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.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

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

PHP Build Version
Package Version
Requires php Version >=7.4.0
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
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sevens/router contains the following files

Loading the files please wait ....