Download the PHP package ingenioz-it/router without Composer

On this page you can find all versions of the php package ingenioz-it/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

Router

A PHP Router.

Disclaimer

In order to ensure that this package is easy to integrate into your app, it is built around the PHP Standard Recommendations : it takes in a PSR-7 Server Request and returns a PSR-7 Response. It also uses a PSR-11 Container (such as EDICT) to resolve the route handlers.

It is inspired by routers from well-known frameworks (did anyone say Laravel ?) aswell as some home-made routers used internally by some major companies.

It is build with quality in mind : readability, immutability, no global states, 100% code coverage, 100% mutation testing score, and validation from various static analysis tools at the highest level.

About

Info Value
Latest release Packagist Version
Requires PHP from Packagist
License Packagist
Unit tests tests
Code coverage Code Coverage
Code quality code-quality
Quality tested with phpunit, phan, psalm, phpcs, phpstan, phpmd, infection, rector

Installation

Documentation

Overview

Here is the whole process of using this router :

Basic routing

The simplest route consists of a path and a handler.

The path is a string, and the handler is a callable that will be executed when the route is matched. The handler must return a PSR-7 ResponseInterface.

Organizing routes

Route groups are used to contain routes definitions.
They also allows you to visually organize your routes according to your application's logic.

This is useful when you want to apply the same conditions, middlewares, or attributes to several routes at once (as we will see later).

Route groups can be nested to create a hierarchy of routes that will inherit everything from their parent groups.

HTTP methods

You can specify the HTTP method that the route should match:

If you want a route to match multiple HTTP methods, you can use the some method:

You can also use the any method to match all HTTP methods:

Path parameters

Basic usage

You can define route parameters by using the {} syntax in the route path.

The matched parameters will be available in the request attributes.

Custom parameter patterns

By default, the parameters are matched by the [^/]+ regex (any characters that are not a /).

You can specify a custom pattern by using the where parameter:

Custom parameter patterns in a group

Parameters patterns can also be defined globally for all routes inside a group:

Route handlers

Closures

The simplest way to define a route handler is to use a closure.
The closure must return a PSR-7 ResponseInterface.

Closures can take in parameters: the request and a request handler (the router itself).

RequestHandlerInterface

A route handler can be a callable, but it can also be a PSR RequestHandlerInterface.

MiddlewareInterface

Sometimes, you might want a handler to be able to "refuse" to handle the request, and pass it to the next handler in the chain.

This is done by using a PSR MiddlewareInterface as a route handler :

Dependency injection

Instead of using a closure or a class instance, your handler can be a class name. The router will then resolve the class using the PSR container you injected into the router.

The router will resolve this handler by calling get(MyHandler::class) on the container. This means that you can use any value that the container can resolve into a valid route handler.

Additional attributes

You can add additional attributes to a route by using the with method.
Just like path parameters, these attributes will be available in the request attributes.

Attributes can also be defined globally for all the routes inside a group:

Middlewares

Middlewares are classes that can modify the request and/or the response before and after the route handler is called.

They can be applied to a route group.

The middleware class must implement the PSR \Psr\Http\Server\MiddlewareInterface interface.

Conditions

Conditions are callables that will determine if a route group should be parsed.

Additionally, conditions can return an array of attributes that will be added to the request attributes.

If a condition returns an array, it is assumed that the route group should be parsed.

If any condition returns false, the route group will not be parsed:

Naming routes

Routes can be named.

Using the router, you can then generate the path to a named route:

If a route has parameters, you can pass them as the second argument:

Error handling

This router uses custom exceptions to handle errors.

Here is the inheritance tree of those exceptions:


All versions of router with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
psr/http-server-handler Version ^1.0
psr/http-server-middleware Version ^1.0
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 ingenioz-it/router contains the following files

Loading the files please wait ....