gephart/routing

Gephart Routing Component

0.5.1 2017-10-13 17:11 UTC

This package is not auto-updated.

Last update: 2024-04-13 18:18:11 UTC


README

Build Status

Dependencies

  • 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

Instalation

composer require gephart/routing

Basic using

/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
]);

Annotation

/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";
    }
}