Download the PHP package polymorphine/routing without Composer

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

Polymorphine/Routing

Latest stable release Build status Coverage status PHP version

Composite routing library for HTTP applications

Concept feature: Tree structure routing matching requests and building endpoint urls

Router may consist of individual routes (see Route interface) of three main categories:

These routes composed in different ways will create unique routing logic, but since composition tree may be deep its instantiation using new operator may become hard to read by looking at large nested structure or its dependencies assembled together, but instantiated in order that is reversed to execution flow (nested structure instantiated first).

Builder is a part of this package to help with the problem. It uses fluent interface with expressive method names - more concise than class names & their constructors that would be used in direct composition. It is also more readable due to the fact that builder method calls resemble execution path in instantiated tree.

Installation with Composer

Routing build example

Diagram below shows control flow of the request passed to matching endpoint in simplified blog page example.

Routing diagram

Let's start with it's routing logic description:

  1. Request is passed to the router (root)
  2. Forwarded request goes through CSRF and (if CSRF guard will allow) Authentication gates (let's assume that there are no other registered user roles than admin)
  3. In ResponseScan request is forwarded sequentially through each route until response other than "nullResponse" is returned.
  4. First (default) route will pass request forward only if Authentication marked request as coming from page admin.
  5. If request was forwarded all meaningful endpoints are available, and if user has no authenticated account routes dedicated for unregistered ("guest") user are tested.
  6. Of course "guest" user may access almost all pages in read-only mode, so we can forward his request to the main tree after guest specific or forbidden options are excluded. Next routes will check if user wants to log in, access logout page (which makes no sense so he is redirected) or gain unauthorized access to /admin path. Beside these, all other read-only (GET) endpoints should be accessible for guests.
  7. If none of previous routes returned meaningful response GET requests are allowed to main endpoints tree.
  8. While some endpoint access makes sense from guest perspective it is pointless from admin's - for example admin trying to log in will be redirected to home page. Guests won't be forwarded here, because this case was already resolved for them.

Here's an example showing how to create this structure using routing builder:

Tests for this example structure can be found in ReadmeExampleTests.php - compare one created as above using builder (BuilderTests.php) and equivalent structure composed directly from components (CompositionTests.php) which will be result of calling builder methods.

Routing components & builder commands

Endpoints

Endpoints are responsible for handling incoming server requests with procedures given by programmer. Beside that, endpoints can can handle types of requests that can be resolved in generic way (OPTIONS, HEAD). There are several ways to define endpoint behaviour:

  1. RouteBuilder::callback($callable)) will handle forwarded request using given callback function with following signature:

  2. RouteBuilder::handler(RequestHandlerInterface $handler)) will handle forwarded request with given class implementing RequestHandlerInterface.
  3. RouteBuilder::redirect(string $routingPath, $code = 301)) will return response redirecting to another endpoint route.
  4. Mapped endpoint (RouteBuilder::endpoint(string $id)) will use user defined callback to create endpoint route based on given id string. To define mapping procedure initialise MappedRoutes with defined $endpoint parameter (see predefined mapping using PSR's ContainerInterface in MappedRoutes::withContainerMapping()).

All versions of routing with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8.0
psr/http-message Version ^1.0
psr/http-factory Version ^1.0
psr/http-server-middleware Version ^1.0
psr/container 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 polymorphine/routing contains the following files

Loading the files please wait ....