yiisoft/router-fastroute

Yii router FastRoute adapter

dev-master / 3.0.x-dev 2021-09-07 20:55 UTC

This package is auto-updated.

Last update: 2021-09-19 14:40:40 UTC


README

993323

Yii Router FastRoute adapter


The package provides FastRoute adapter for Yii Router.

Latest Stable Version Total Downloads Build status Scrutinizer Code Quality Code Coverage Mutation testing badge static analysis type-coverage

General usage

Router instance could be obtained like the following:

use Yiisoft\Router\FastRoute\FastRouteFactory;

$factory = new FastRouteFactory();
$router = $factory();

Custom route factory

If you need to make custom route factory you can do something like the following:

namespace App\Factory;

use Psr\Container\ContainerInterface;
use Yiisoft\Router\FastRoute\FastRouteFactory;
use Yiisoft\Router\Route;
use Yiisoft\Router\RouterFactory;
use Yiisoft\Router\RouterInterface;
use Yiisoft\Yii\Web\Middleware\ActionCaller;
use App\Controller\SiteController;

class RouteFactory
{
    public function __invoke(ContainerInterface $container): RouterInterface
    {
        $routes = [
            Route::get('/')
                ->action([SiteController::class, 'index'])
                ->name('site/index'),
            Route::get('/about')
                ->action([SiteController::class, 'about'])
                ->name('site/about'),
        ];

        return (new RouterFactory(new FastRouteFactory(), $routes))($container);
    }
}

setting up your container

use App\Factory\RouteFactory;
use Yiisoft\Router\RouterInterface;

return [
    /** 
     * ...
     * There other container configuration. 
     * ...
     */

    RouterInterface::class => new RouteFactory(),
];

Unit testing

The package is tested with PHPUnit. To run tests:

./vendor/bin/phpunit

Mutation testing

The package tests are checked with Infection mutation framework. To run it:

./vendor/bin/infection

Static analysis

The code is statically analyzed with Psalm. To run static analysis:

./vendor/bin/psalm

Support the project

Open Collective

Follow updates

Official website Twitter Telegram Facebook Slack

License

The Yii Router FastRoute adapter is free software. It is released under the terms of the BSD License. Please see LICENSE for more information.

Maintained by Yii Software.