zloynick / joole-components-routing
Installs: 15
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:joole-component
Requires
- php: ^8.1
- zloynick/joole-framework: ^8.1
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());
...