Skip to content

thenotsoft/router-fastroute

 
 

Yii Router FastRoute adapter


The package provides FastRoute adapter for Yii Router.

Latest Stable Version Total Downloads Build Status Scrutinizer Code Quality Code 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('/')->to(new ActionCaller(SiteController::class, 'index', $container))->name('site/index'),
            Route::get('/about')->to(new ActionCaller(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(),
];

About

Yii Router FastRoute adapter

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%