devop-core / router
PHP Router library
1.0.2
2019-05-15 12:34 UTC
Requires
- php: >=7.0
- devop-core/http: ^1.1
- psr/http-message: ~1.0
Requires (Dev)
- http-interop/http-factory: ^0.3
- phpunit/phpunit: ^6
This package is auto-updated.
Last update: 2024-10-29 05:10:40 UTC
README
Description
This library is just proof of concept. > We do NOT recommended the use of production environment.
Provide router implementation
Install
Package is available on Packagist, you can install it using Composer.
composer require devop-core/router
Usage
<?php include_once '../vendor/autoload.php'; $router = new DevOp\Core\Router\Router(); $router->get('page1', '/page1/{name:\w+}/{id}', function($request, $response){ $response->getBody()->write('Hello world!'); return $response; }); $uri = (new DevOp\Core\Http\UriFactory())->createUri('/page1/devop/1'); $request = (new \DevOp\Core\Http\ServerRequestFactory())->createServerRequest('GET', $uri); try { /* @var $route \DevOp\Core\Router\Route */ $route = $router->dispatch($request); } catch (\DevOp\Core\Router\Exceptions\RouteNotFoundException $ex) { var_dump($ex); } catch (DevOp\Core\Router\Exceptions\RouteIsNotCallableException $ex) { var_dump($ex); } var_dump($route);
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ vendor/bin/phpunit
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see License File for more information.