Download the PHP package fastero/php-router without Composer

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

PHP Router

Simple, fast and fully covered with a tests Router.

Router is a very important part of (almost)any web application and as a part of core it must have as less overhead as possible. That's what this router is built for -- to be extremely fast

requires php 7.0 +

Install with composer

Usage

array contain's route names as keys and configuration parameters array as value. It's recommended to generate configuration using Configurators

And to use reverse routing (path generation):

See Generate path

Configurators

Configurators are created to make configuration of your route easier and prevent you from making mistakes.

While configurators are using chaining syntax they are not return an object as a result but simple array and they don't create a bunch of objects while being used. This method has some limitations but it has much less overhead and almost as fast as using simple arrays and speed is a main goal of this library.

To start configuring route you must call static method on appropriate Configurator. This method usually has two parameters and . Example:

now is a Object and other it's methods can be called to continue configuration and all of theme will return object and at the very end you must call method which will return array with all the configurations. So at the end it looks like:

All the configurators has following methods:

Add a default value for parameter and/or validation rule. Validation rule is a regular expression.

This controller will be returned as a part of route options so you can call it or do whatever you want. It has no special meaning for Router class

Some route handlers may not be able to generate reverse path from path by itself (for example Regex route) so you need to specify this pattern and reverse path generator as well (see next)

Class name that will be used as a generator with specified reversePattern. If specified it will be used instead of built in route handler generator.

Set rules for query parameter

Currently there are 3 configurators (src/Configuration) one per each route type:

All they have the same methods but slightly different signature for ::config() method. That's because Literal route type does not need any path pattern but static path only

Route types

Literal

Regex

It's recommended to make regex as simple as possible and use validators if you need to validate parameters rather than include all the validation in the regex.

Section

and here is a static prefix or just - more unique prefix is better but sometimes it's more important to be looking good and readable.

so this type of route uses "/" to delimit parameters and ":" to define parameter "[", "]" - to define optional parameter.

More examples (with static prefixes as they should be used. You may think about if like it's a single concat string):

Generate path

Currently there are two path generators:

Format:

Examples:

Why is it fast?

There are two factors - first it uses native array as a configuration and does not create an object for every route. Even though creating a few objects per route is not a big deal it will still some part of your performance and this part will be bigger more routes you have.

Second factor - is that it forces you to use static prefixes to your paths. And searching by static prefixes first is much faster than executing each regex. Some other libraries are doing the same but they trying to figure out prefixes by itself and in order for this to be efficient you would need use cache. While using cache is not a bad thing to do usually you want your app to be fast enough without cache and then make it even faster with cache.

MIT Licensed, http://www.opensource.org/licenses/MIT


All versions of php-router with dependencies

PHP Build Version
Package Version
Requires php Version ^7.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 fastero/php-router contains the following files

Loading the files please wait ....