- PHP >= 7.1
- gephart/annotation >= 0.4
- gephart/collections = dev-master
- gephart/configuration >= 0.4
- gephart/dependency-injection >= 0.4
- gephart/event-manager >= 0.4
- gephart/request >= 0.4
- gephart/response >= 0.4
composer require gephart/routing
/index.php
<?php
// $_GET["_route"] = "/admin/article/edit";
$container = new \Gephart\DependencyInjection\Container();
$configuration = $container->get(\Gephart\Configuration\Configuration::class);
$configuration->setDirectory(__DIR__ . "/config");
$router = $container->get(\Gephart\Routing\Router::class);
$route = new \Gephart\Routing\Route();
$route->setName("testing_route");
$route->setController("Test");
$route->setAction("index");
$route->setRule("/admin/{entity}/{action}");
$router->addRoute($route);
$router->run(); // Run controller Test and action method index
// /admin/article/post?id=21
$url = $router->generateUrl("testing_route", [
"action" => "post",
"entity" => "article",
"id" => 21
]);
/config/routing.json
{
"autoload": "Controller"
}
/Controller/AdminController.php
<?php
/**
* @RoutePrefix /admin
*/
class AdminController
{
/**
* @Route {
* "rule": "/page/{slug}/{limit}/{offset}",
* "name": "homepage",
* "requirements": {
* "limit": "[0-9]+",
* "offset": "[0-9]+"
* }
* }
*/
public function page($limit, $offset, $slug)
{
echo "OK";
}
}