Search by

webservco / route

ariademur

A PHP component/library. Loads a module's routes from a PHP file that maps route names to controller classes.

Package info

github.com/webservco/route

Homepage

pkg:composer/webservco/route

Statistics

Installs: 121

Dependents: 3

Suggesters: 0

Stars: 0

Open Issues: 0

v2.3.0 2026-10-11 16:34 UTC

This package is auto-updated.

Last update: 2026-10-11 16:45:40 UTC


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

License

MIT