Skip to content

Latest commit

 

History

History
53 lines (37 loc) · 2.58 KB

readme.md

File metadata and controls

53 lines (37 loc) · 2.58 KB

Eddy/Route

Eddy/Route is an implementation of nikic/FastRoute and Middlewares/FastRoute package.

Similarly to League/Route, this library aims to provide a friendlier API for FastRoute, as well as adding a few tweaks.

It is not as feature rich as League/Route, but intends to be simple and flexible.

Tweaks to FastRoute

Eddy/Route adds a few tweaks to FastRoute's default behaviour:

  • The default DataGenerator stores routes in an ArrayObject instance instead of a plain array.

    • The idea here is to allow creating a Dispatcher instance before routes have been added, since an ArrayObject is passed by reference, while a plain array is copied.
    • Note: Work In Progress: FastRoute passes an empty array to the Dispatcher if no variable routes are set, which breaks this feature for variable routes added after the Dispatcher is created.
    • This feature may be dropped in favour of old behaviour.
  • Various convenience methods.

    • The Router object provides a number of convenience methods that wrap FastRoute's own methods. These helpers are a little less verbose than FastRoute's method names, and may be preferred.
  • PSR-15 Compliant Router

Example

Below is a basic example of a Router implementation using Zend Diactoros, Zend Request Handler Runner, and the Middleman psr-15 dispatcher.

$r = new Eddy\Route\Router();

$r->get('/', function () {
    return new Zend\Diactoros\Response\JsonResponse('hello world');
});

$r->get('/test', function () {
    return new Zend\Diactoros\Response\JsonResponse('hello test');
});

$d = new mindplay\middleman\Dispatcher([$r, new Middlewares\RequestHandler()]);

(new Zend\HttpHandlerRunner\Emitter\SapiEmitter())->emit($d->dispatch(
    Zend\Diactoros\ServerRequestFactory::fromGlobals()
));