webservco / route
A PHP component/library. Loads a module's routes from a PHP file that maps route names to controller classes.
Requires
- php: ^8.4
- webservco/configuration: ^2
Requires (Dev)
- pds/skeleton: ^1
- phan/phan: ^6
- php-parallel-lint/php-console-highlighter: ^1
- php-parallel-lint/php-parallel-lint: ^1
- phpmd/phpmd: ^3
- phpstan/phpstan: ^2
- phpstan/phpstan-deprecation-rules: ^2
- phpstan/phpstan-phpunit: ^2
- phpstan/phpstan-strict-rules: ^2
- phpunit/phpunit: ^13
- slevomat/coding-standard: ^8
- squizlabs/php_codesniffer: ^4
- vimeo/psalm: ^6
- webservco/coding-standards: ^2
- webservco/component-common: ^2
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A PHP component/library. Please see webservco/sandbox for an example project using these types of components.
Loads a module's routes from a PHP file that maps route names to controller classes.
- Related:
webservco/http-request-handler(looks up the route),webservco/controller(creates the controller),webservco/configuration(file loader)
Installation
composer require webservco/route
Usage
config/Example/Routes.php:
<?php declare(strict_types=1); use Project\Controller\Example\TestController; return [ // /example/test 'test' => TestController::class, ];
use WebServCo\Configuration\Service\PHPConfigurationLoader; use WebServCo\Route\Service\ControllerView\RoutesConfigurationLoader; $routesConfigurationLoader = new RoutesConfigurationLoader(new PHPConfigurationLoader()); // array<string, \WebServCo\Route\Service\ControllerView\RouteConfiguration> $routesConfiguration = $routesConfigurationLoader->loadFromFile( sprintf('%sconfig/Example/Routes.php', $projectPath), );
Pass the result to the module's request handler (see webservco/http-request-handler).
Contracts
| Interface | Implementation | Purpose |
|---|---|---|
Contract\RouteConfigurationInterface |
Service\ControllerView\RouteConfiguration |
Holds the controller class for a route (controllerClass). |
| none | Service\ControllerView\RoutesConfigurationLoader |
Reads a route file into RouteConfiguration objects. |
Namespaces are relative to WebServCo\Route\.
Notes
Keys and values in the route file must be strings, or the loader throws an UnexpectedValueException. API routes include the version in the key, for example 'v1/about' => APIController::class.
Route files live in config/, not src/, because they aren't classes.
Development
# Start project. ddev start # Install dependencies. ddev c u # Run all validations. ddev c c # Run unit tests. ddev c test:dox