Download the PHP package lumax/routing-component without Composer
On this page you can find all versions of the php package lumax/routing-component. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lumax/routing-component
More information about lumax/routing-component
Files in lumax/routing-component
Package routing-component
Short Description A dynamic PHP Routing Component.
License GPL-3.0-or-later
Informations about the package routing-component
Luma | Routing Component
The Routing Component is a lightweight and flexible PHP package for handling routing in your web application. It provides a simple way to define routes and execute controller actions based on incoming HTTP requests. This component is designed to be easily integrated into your PHP projects and works seamlessly with PSR-11 compliant dependency injection containers.
Installation
You can install this package using Composer:
Usage
Basic Usage
Create a Router Instance
Create an instance of the Router
class, passing a dependency injection container that implements the
Psr\Container\ContainerInterface
:
Load Routes:
Load your application's routes from a YAML configuration file:
Example YAML configuration (routes.yaml
):
Alternatively, you can load your routes from an array if you'd prefer:
Handle Requests:
In your application's entry point (e.g., index.php
), call the handleRequest
method to handle incoming HTTP requests:
The handleRequest
method expects an instance of Psr\Http\Message\RequestInterface
. This Routing Component requires my
HTTP Component, therefore Request
and Response
classes are already provided.
The router will match the request URI to the defined routes and execute the corresponding controller action.
Controller Actions
Controller actions are defined as arrays containing the controller class name and the method name:
Dependencies
The Router
class is designed to work seamlessly with dependency injection containers. You can inject dependencies
into your controller actions through constructor injection. When a controller is instantiated, the router will automatically
resolve and inject its dependencies from the container. Requires a PSR-11 compliant ContainerInterface
instance.
Error Handling
The router handles 404 Not Found errors for unhandled routes. If no matching route is found, it will respond with a 404 status code.
License
This package is open-source software licensed under the GNU General Public License, version 3.0 (GPL-3.0).
All versions of routing-component with dependencies
symfony/yaml Version ^6.3
psr/http-message Version ^2.0
lumax/security-component Version ^1.3
lumax/http-component Version ^2.2
lumax/framework-component Version ^1.0