Download the PHP package pagemill/router without Composer

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

PageMill Router

This library determines a route for a web request. It is built to be easy to use and fast.

Basic Routing

For the most basic of routing needs, an array can simply be passed to the Router class constructor. Each route array should consist of a type, pattern, and either an action or array of sub-routes called routes. While action has no meaning to the router itself, its purpose is for use after matching.

Adding with Methods

You can also add routes using the add method.

If performance is important, it is suggested to pass the routes into the constructor.

Match Types

There are three matching types supported plus a default route.

exact - The request path must match pattern exactly.

starts_with - Matches when the request path begins with the exact value of pattern.

regex - Uses a regular expression to match against the reqeust path.

default - A default route to use if no other route is matched. A default route does not require a pattern. There must only be one default route defined.

Matching Tokens

Optionally, a route can include an array of tokens that allow for using values from the request path to fill a named array in the return value of the match method. This is only valid for starts_with and exact match types.

For starts_with matches, the tokens will be filled in based on values that appear in the request path between slashes (/) that are not part of the pattern.

The value of $route would be:

For regex matches, the tokens will be filled based on back references used in the regular expression.

The value of $route would be:

Matching Hostname, Request Method, Accept header, and Other HTTP Headers

It is also possible to match on hostname, request method, Accept header, and other HTTP headers by adding these settings to the route array.

host - Matches the HTTP Host header. method - Matches the HTTP request method (GET, POST, etc.) accept - Validates the Accept header contains one of a list of mime types. headers - An array of headers and the patterns to match them.

To match on hostname, add host to the route config. To only match GET requests, add method.

The value of $route would be:

By default, this is treated as an exact match. You can do more complex matching by providing an array with type and pattern set. This is true of host, method and the patterns in the headers array.

The matched values of these settings will be returned in the matched route array. The value of $route would be:

To validate the Accept header against a list of mime types, this route config could be used. For this example, assume the Accept header from the client contains text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8.

NOTE: Unlike other options, the accept option only accepts a single string mime type or an array of mime types.

The value of $route would be:

Router will honor the clients quality scores from the Accept header. For an explination of the quality score used in HTTP client Accept headers, see https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html. If the quality scores for the matching mime types is equal, the order they are defined in the configuration will be honored.

Because the quality score for text/html is not defined in the Accept header, it is assumed to be 1. The value of $route would be:

To match an arbitrary HTTP header, add headers to the route config.

This example will ensure that the Authorization header contains 12345678.

The value of $route would be:

Default Route

The value of $route would be:

Note: No tokens will be returned and no pattern matching is performed on the path for the default route.

Only one default route is allowed. An InvalidRoute exception will be thrown if more than one default route is defined.

Adding Sub Routes (aka Route Maps)

If you have several routes that all have the same prefix or match the same pattern, it can be beneficial to group those routes as sub-routes under a more general route. For example, if we have multiple routes that fall under the /foo path, we could configure our routes like this:

The value of $route would be:

Saving the Route List

If you would like to save the route list for reuse, you can call the getRoutes() method.


All versions of router with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8.0
pagemill/pattern Version ^2.0.1
pagemill/accept Version ~2.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 pagemill/router contains the following files

Loading the files please wait ....