Download the PHP package timetoogo/rapid-route without Composer

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

RapidRoute - Another fast router for PHP

Build status Code quality Coverage Status Stable Release License

RapidRoute aims to be another fast router for PHP. This library takes a different approach to uri routing by compiling the router to optimized PHP code, minimizing the need for traditional regular expressions.

As this project focuses on performance, the scope of this library is limited. All in all, this library provides the ability to match a supplied HTTP request (method and uri) against a set of route definitions. See below for usage examples.

Benchmarks

Test Name RapidRoute (req/sec) FastRoute (req/sec) Change
First static route 3385.28 2906.64 16.47% faster
Last static route 3419.56 2901.09 17.87% faster
First dynamic route 3428.94 2829.18 21.20% faster
Last dynamic route 3379.56 2890.18 16.93% faster
Non-existent route 3412.31 2823.27 20.86% faster
Longest route 3371.36 2853.40 18.15% faster
Invalid method, static route 3125.81 2864.19 9.13% faster
Invalid method, dynamic route 3402.57 2847.55 19.49% faster

These results are generated using this benchmark suite running on PHP 5.5 with opcache enabled. These results indicate a consistent 10-20% performance gain over FastRoute depending on the input uri and http method.

Installation

This project is compatible with PHP 5.4+. It can be loaded via composer:

Router Usage

This library is designed to be used by another library/framework or as a standalone package. It provides specific APIs for each use case.

Usage in a framework

A framework often provides its own wrapper API so this library offers a lower-level API in this case. A basic example is shown:

The result from the router is an array that contains the result status as the first element. The following elements of the array are dependent on the status and will be one of three formats:

Usage as a standalone package

If this library is intended to be used as a standalone package, a cleaner and more extensive wrapper API is provided. A similar example showing off this the API is shown:

The result from the call to $router->match(...) will be an instance of RapidRoute\MatchResult.

Route definitions

Route patterns

To define the routes, a familiar url structure is used:

Adding Routes

To define the routes, the router API takes a callable parameter which will be called with an instance of RapidRoute\RouteCollection when the router is being compiled. This can be used like so:

Using the RouteCollection you can also define a route parameter regex globally to avoid repetitions:

Basic usage example

The associated route data will be available when the route is matched. This is a very basic example of how this library may be implemented as a standalone router package. The route data contains the associated handler so it can be easily dispatched when the route is matched.

Here are some examples of how this set up should handle the incoming request:

Request Dispatched Handler
GET / HomeController::index([])
GET /user UserController::index([])
POST /user UserController::store([])
POST / ErrorController::methodNotAllowed(['GET'])
GET /abc ErrorController::notFound()
GET /user/123 UserController::show(['user_id' => '123'])
PUT /user/123 UserController::update(['user_id' => '123'])
PUT /user/abc ErrorController::notFound()

Notes

Compilation

Given that this library compiles route definitions to plain PHP, there is much room for optimization. The current approach is using a tree structure matching each segment in a uri ('/shop/product' is composed of the 'shop' and 'product' segments). Currently the structure is compiled to nested switch and if blocks using optimized comparisons where applicable.

One consideration of the compiled router is that it must be able to be called directly and as such must handle the any expected error cases within the compiled router.

Example compiled router

Route definitions:

Currently the compiled router for the above will be similar to the following:

The complexity of the router will grow in proportion to the number and complexity of the route definitions.


All versions of rapid-route with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.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 timetoogo/rapid-route contains the following files

Loading the files please wait ....