anonym-php / anonym-route
AnonymFramework Route Component
dev-master / 1.2.x-dev
2015-09-23 00:47 UTC
Requires
- php: >=5.5.9
- anonym-php/anonym-httpfoundation: ~1.2@dev
- anonym-php/anonym-security: ~1.2@dev
- anonym-php/anonym-view: ~1.2@dev
Requires (Dev)
- illuminate/container: 5.2.*
This package is not auto-updated.
Last update: 2024-11-09 18:47:04 UTC
README
#Anonym-Route
This is a route component for AnoynmFramework.
Launch the component
include 'vendor/autoload.php'; use Anonym\Components\Route\RouteCollector; use Anonym\Components\Route\Router; use Anonym\Components\HttpClient\Request; $collector = new RouteCollector();
How can i add a new route?
$collector->get('uri', ['_controller' => 'Controller:method', 'access' => [ 'role' => '', 'next' => null, 'name' => 'name', ]]);
Which types are supported?
GET
, POST
, HEAD
, PUT
, OPTIONS
, DELETE
, PATCH
How to run?
use Anonym\Components\Route\Router; $router = new Router( new Request()); $router->run();
How can i add a middleware?
$collector->get('/', ['_middleware' => ['name' => 'middlewarename', 'role' => 'aaa', 'next' => function(){}]]);
How can i add a middleware in a controller?
public function __construct(){ $this->middleware('middlewarename'); }
How can i create a Controller
add it to composer.json
"Anonym\Controllers": "path"
and create controller in the "path"
use Anonym\Components\Route\Controller; class Test extends Controller{ // do nothing }
$collector->get('/{test}', 'Controller:method'); // {test} is required $collector->get('/{test!}', 'Controller:method'); // {test!} is required $collector->get('/{test?}', 'Controller:method'); // {test?} is optional
How can I set the namespace?
$router = new Router()->setNamespace('Your\Namespace'); // or $collector->get('/', ['_controller' => 'Test:method', '_namespace' => 'Your\Namespace']);