alpha-zeta/route

Fast and flexible routing library

1.0.5 2024-09-26 11:50 UTC

This package is auto-updated.

Last update: 2024-10-31 14:09:16 UTC


README

Fast and flexible routing library

Install

composer require alpha-zeta/route

Usage

use Az\Route\RouteCollectionInterface;
use App\Http\Conroller\Home;
use App\Http\Conroller\Image;
...

class App
{
    private RouteCollectionInterface $route;

    public function __construct(RouteCollectionInterface $route, ...)
    {
        $this->route = $route;
        ...
    }

    public function run()
    {
        $this->route->get('/hello', function () {
            return 'Hello, World!';
        });

        $this->route->conroller('/image/{id}/{action?}/{slug?}', Image::class, 'image')
            ->tokens([
                'id' => '\d+',
                'action' => 'thumbnail|origin|',
            ]);

        $this->route->get('/', [Home::class, 'index'], 'home')
            ->pipe(AuthMiddleware::class);

        $response = $this->pipeline->process($this->request, $this->defaultHandler);
        $this->emitter->emit($response);
    }
}