Download the PHP package sevens/router without Composer
On this page you can find all versions of the php package sevens/router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sevens/router
More information about sevens/router
Files in sevens/router
Package router
Short Description Simple Php High Speed Web Application Router library with PSR-7 Compliance
License MIT
Informations about the package router
About SevenRouter
=> Seven Router is developed by Elisha Temiloluwa [ TemmyScope ]
=> The Library uses the PHP-DI dependency container to inject dependencies.
=> The Library has been completely unit tested and is ready for use.
Installation
PHP >=7.4 Performance Hack
=> Use preloader to preload the cached route file after compilation on a production server.
Seven\Router\Router: Usage
Initialize the class
Performance Optimization and Cache
=> To Improve performance on a production server, you should enable cache.
Downside: Whenever a new route is added, You have to delete the cache file from the cache directory in order for the new route to be reloaded.
Registering PSR-7 Compliant/Implementing Request & Response Objects
=> This is an optional feature; You don't have to register PSR-7 request & response objects
Register middlewares you want to use later in your route calls:: All Callables are acceptable
***Note: registered middlewares only run/load after the associated route is matched/found.
Running middlewares before matching the routes can only be done if you implement it in our application or by extending the router
The "next" is an object of the PSR-15 RequestHandlerInterface
=> This means the handle method is available as well as it can be invoked like a function.
Note: You can only use the "handle" method of the "next" object if you registered $request & $respnse objects that implement PSR-7 Interface; Else, just call next as a function|closure i.e. next(request, response)
It is best when routes are defined in a different file
=> route definition are included/required/loaded into the current file
=> Note: routes can also be defined in the front controller (i.e. in your index.php);
The routing process starts here
=> The "run" method processes routes and calls the appropriate action if the request succeeds.
The route difinition in the route file that was required in the front controller e.g. index.php
=> All Standard Http Methods are supported: GET, POST, PUT, OPTIONS, PATCH, HEAD, DELETE;
=>All methods accept a callable as the second parameter
=>All callables are injected with the request & response objects that were previously registered
Multiple Methods to same Route
To make all requests to a certain endpoint return the same callable, use the "all" method
All params in uri are accessible through the request param object
The "use" method is used to call registered middlewares before returning the endpoint's callable
=> The middlewares are called in the order in which they were written/passed
=> The second parameter passed to the "use" method must be a closure that accepts no parameter
Shorthand for Use Keyword
=> There is a shorthand way to use the "use" method (Of-course it is negligibly slower, if you're performance-anxious)
Apache - .HTACCESS
=> An example .htaccess directive file fit for this router would look sth like this:
NGINX Site Configuration Directive
=> An example nginx configuration directive fits for this router would look sth like this:
Example use Case In a real Life Applicatiion
Example use Case of PSR-7 Request-Response Handlers In an Applicatiion making use of Symfony/http-foundation
Note: Not all use of PSR-7 compliants Request & Response handlers are this stressful.
This example is given as it might be the most complicated scenario use case.
Note: Routes without parameters are resolved faster that those that accept parameters
All versions of router with dependencies
psr/http-message Version ^1.0
psr/http-server-handler Version ^1.0
php-di/php-di Version ^6.0.11
opis/closure Version ^3.6.1