/router-fastroute

Yii Router FastRoute adapter

Primary LanguagePHPBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

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('/', [SiteController::class, 'index'], $container)->name('site/index'),
            Route::get('/about', [SiteController::class, 'about'], $container)->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.