zloynick/joole-components-routing

8.1.3.2 2022-05-03 22:30 UTC

This package is not auto-updated.

Last update: 2025-06-25 14:10:52 UTC


README

This component allows you to configure routes for your project.

Getting started

  • Install this dependency via composer: composer install zloynick/joole-components-routing

Configuration

Add to components this in your joole.php configuration file:


'components' => [
        ...,
        [
            'name' => 'router',
            'class' => \joole\components\routing\RoutingComponent::class,
            // Component options
            'options' => [
                // Routes path
                'routes' => __DIR__.'/routes/',
            ],
        ],
        ...,
    ],

Using

Create your routes in the folder that you specified in the component configuration:

----------- routes.php -----------

...
// Closure using.
BaseRouter::register('route.test', '/my/action/:name/:and_id', function(string $name, int $and_id):\joole\framework\http\Response{
          return response();
      }
);
// Controller using.
BaseRouter::register('route.test', '/my/action/:name/:and_id', ['\app\controllers\DefaultController::class', 'index']);
// OR
BaseRouter::register('route.test', '/my/action/:name/:and_id', '\app\controllers\DefaultController::class@index');
...

Validation of requests

Use Validator to create a request parameter validation class.

Example:


...
BaseRouter::register('route.test', '/my/action/:name/:and_id', function(string $name, int $and_id):\joole\framework\http\Response{
          return response();
      }
)->withValidators(YourValidator1::class, ..., new Validator2());
...