1. Go to this page and download the library: Download tandrezone/zroute 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/ */
use zRoute\Contracts\MiddlewareInterface;
use zRoute\Request;
class AuthenticateUser implements MiddlewareInterface
{
public function handle(Request $request, callable $next): mixed
{
if (!$request->getHeader('Authorization')) {
throw new \RuntimeException('Unauthorized', 401);
}
return $next($request);
}
}
public function show(Request $request): mixed
{
$id = $request->getParam('id'); // path > query > body
$page = $request->getParam('page', 1); // with default
$all = $request->all(); // merged array
$accept = $request->getHeader('Accept');
$method = $request->getMethod();
// …
}