PHP code example of poa / httprouter
1. Go to this page and download the library: Download poa/httprouter 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/ */
poa / httprouter example snippets
use Poa\Http\Router\CallableResult;
use Poa\Http\Router\Router;
use Poa\Http\Router\RouteResultInterface;
use Poa\Http\Router\RouteRulerInterface;
use Poa\Http\Server\HttpApplication;
use Poa\Http\Server\HttpContext;
class SimpleRuler implements RouteRulerInterface
{
public function process(HttpContext $context): ?RouteResultInterface
{
if ($context->request->getMethod() === 'get') {
return new CallableResult(function () {
echo 'do something';
});
}
return null;
}
}
$router = new Router();
$router->addRuler(new SimpleRuler());
$app = new HttpApplication();
$app->use($router);
$app->handle(new HttpContext($request, $responst));