alpha-zeta/route

Fast and flexible routing library

1.0.4 2024-09-14 10:05 UTC

This package is auto-updated.

Last update: 2024-09-26 11:51:08 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);
    }
}