PHP code example of guyliangilsing / php-abstract-router
1. Go to this page and download the library: Download guyliangilsing/php-abstract-router 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/ */
guyliangilsing / php-abstract-router example snippets
use use PHPAbstractRouter\HTTP\Router;;
$routeRegisterer = // Your bridge class...
$router = new Router($routeRegisterer);
$router->get('/', MyController::class,'renderIndex');
$router->get('/about', MyController::class, 'renderAbout');
use PHPAbstractRouter\HTTP\Attributes\GET;
use PHPAbstractRouter\HTTP\Attributes\Group;
use PHPAbstractRouter\HTTP\Attributes\POST;
#[Group('/test')]
final class MyController
{
#[GET('/')]
public function renderIndex(): string
{
return "index.php";
}
#[POST('/')]
public function indexPOST(): string
{
return "POST index.php";
}
#[GET('/about')]
public function renderAbout(): string
{
return "about.php";
}
#[POST('/about')]
public function aboutPOST(): string
{
return "POST about.php";
}
}
use use PHPAbstractRouter\HTTP\Router;;
$routeRegisterer = // Your bridge class...
$router = new Router($routeRegisterer);
$router->fromClass(MyController::class);
use PHPAbstractRouter\HTTP\GroupRouter;
use PHPAbstractRouter\HTTP\Router;
$dispatcher = // Your custom dispatcher here...
$router = new RouterFacade($dispatcher);
$router->group('/test', function(GroupRouter $group) {
$group->get('', MyController::class, 'renderIndex');
$group->get('/about', MyController::class, 'renderAbout');
});
use PHPAbstractRouter\HTTP\BackendRouteRegistererInterface;
final class BackendRouteRegisterer implements BackendRouteRegistererInterface
{
public function route(HTTPRoute $route): void
{
// Todo:: Implement your registration logic here...
}
public function routeGroup(HTTPRouteGroup $group): void
{
// Todo:: Implement your registration logic here...
}
}
bash
$ composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.