PHP code example of marekskopal / router
1. Go to this page and download the library: Download marekskopal/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/ */
marekskopal / router example snippets
use MarekSkopal\Router\Builder\RouterBuilder;
$router = (new RouterBuilder())
->setClassDirectories([__DIR__ . '/../Controllers'])
->setCache(new Cache()) // optional
->build();
use MarekSkopal\Router\Attribute\Route;
use MarekSkopal\Router\Attribute\RoutePost;
class MyController
{
#[Route('GET', '/api/my/name')]
public function getName(): void
{
}
#[RoutePost('/api/my/address')]
public function postAddress(): void
{
}
}
use MarekSkopal\Router\Attribute\RouteGet;
#[RouteGet('/api/my/action')]
class MyAction
{
public function __invoke(): void
{
}
}