1. Go to this page and download the library: Download amsrafid/piper-framework library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
amsrafid / piper-framework example snippets
class ShopController extends Controller
{
public function index() { } // GET /shop/index, nothing declared
#[Get('/shop/{slug}')] // declared, because a slug is not a convention
public function bySlug($slug) { }
}
use Piper\Routing\Attributes\Get;
use Piper\Routing\Attributes\Middleware;
use Piper\Routing\Attributes\Post;
use Piper\Routing\Attributes\Prefix;
use Piper\Routing\Attributes\Route;
#[Prefix('/api/v2')]
#[Middleware('auth:api')]
class OrderController extends Controller
{
#[Get]
public function index() { } // GET /api/v2/order/index
#[Get('/orders/{slug}/lines/{line}')]
public function lines($line, $slug) { } // parameters arrive by name, in any order
#[Get('/orders/{id:\d+}')]
public function show($id) { } // constrained
#[Get('/orders/page/{number?}')]
public function page($number = 1) { } // optional
#[Post('/orders')]
#[Middleware('throttle')]
public function store(Request $request) { } // type hints still come from the container
#[Route('/health', methods: ['GET', 'HEAD'])]
public function health() { }
}
public function __construct()
{
$this->post('store'); // restrict a method to a verb
$this->middleware('auth'); // controller-wide
$this->middleware(['auth:api' => 'store']);
}