Download the PHP package minhngoc/phroute without Composer

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

PHRoute - Fast request router for PHP

Build Status Coverage Status Latest Stable Version License Total Downloads

This library provides a fast implementation of a regular expression based router.

Credit to nikic/FastRoute.

While the bulk of the library and extensive unit tests are my own, credit for the regex matching core implementation and benchmarking goes to nikic. Please go and read nikic's blog post explaining how the implementation works and why it's fast.

Many modifications to the core have been made to suit the new library wrapper, and additional features added such as optional route parameters and reverse routing etc, but please head over and checkout nikic's library to see the origins of the core and how it works.

Installation

Install via composer

Usage

Example

Defining routes

These helper methods are wrappers around addRoute($method, $route, $handler)

This method accepts the HTTP method the route must match, the route pattern and a callable handler, which can be a closure, function name or ['ClassName', 'method'] pair.

The methods also accept an additional parameter which is an array of middlewares: currently filters before and after, and route prefixing with prefix are supported. See the sections on Filters and Prefixes for more info and examples.

By default a route pattern syntax is used where {foo} specifies a placeholder with name foo and matching the string [^/]+. To adjust the pattern the placeholder matches, you can specify a custom pattern by writing {bar:[0-9]+}. However, it is also possible to adjust the pattern syntax by passing a custom route parser to the router at construction.

Regex Shortcuts

Named Routes for Reverse Routing

Pass in an array as the first argument, where the first item is your route and the second item is a name with which to reference it later.

Filters

Filter Groups

Wrap multiple routes in a route group to apply that filter to every route defined within. You can nest route groups if required.

Prefix Groups

Controllers

Dispatching a URI

A URI is dispatched by calling the dispatch() method of the created dispatcher. This method accepts the HTTP method and a URI. Getting those two bits of information (and normalizing them appropriately) is your job - this library is not bound to the PHP web SAPIs.

$response = (new Phroute\Phroute\Dispatcher($router)) ->dispatch($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);

The dispatch() method will call the matched route, or if no matches, throw one of the exceptions below:

# Route not found
Phroute\Phroute\Exception\HttpRouteNotFoundException;

# Route found, but method not allowed
Phroute\Phroute\Exception\HttpMethodNotAllowedException;

NOTE: The HTTP specification requires that a 405 Method Not Allowed response include the Allow: header to detail available methods for the requested resource. This information can be obtained from the thrown exception's message content: which will look like: "Allow: HEAD, GET, POST" etc... depending on the methods you have set You should catch the exception and use this to send a header to the client: header($e->getMessage());

Dependency Injection

Defining your own dependency resolver is simple and easy. The router will attempt to resolve filters, and route handlers via the dependency resolver.

The example below shows how you can define your own resolver to integrate with orno/di, but pimple/pimple or others will work just as well.

When you create your dispatcher:

A Note on HEAD Requests

The HTTP spec requires servers to [support both GET and HEAD methods][2616-511]:

The methods GET and HEAD MUST be supported by all general-purpose servers

To avoid forcing users to manually register HEAD routes for each resource we fallback to matching an available GET route for a given resource. The PHP web SAPI transparently removes the entity body from HEAD responses so this behavior has no effect on the vast majority of users.

However, implementors using Phroute outside the web SAPI environment (e.g. a custom server) MUST NOT send entity bodies generated in response to HEAD requests. If you are a non-SAPI user this is your responsibility; Phroute has no purview to prevent you from breaking HTTP in such cases.

Finally, note that applications MAY always specify their own HEAD method route for a given resource to bypass this behavior entirely.

Performance

Performed on a machine with :

Phroute

This test is to illustrate, in part, the efficiency of the lightweight routing-core, but mostly the lack of degradation of matching speed as the number of routes grows, as compared to conventional libraries.

With 10 routes, matching 1st route (best case)
With 10 routes, matching last route (worst case)

Note that the match is just as quick as against the first route

With 100 routes, matching last route (worst case)
With 1000 routes, matching the last route (worst case)

For comparison, Laravel 4.0 routing core

Please note, this is no slight against laravel - it is based on a routing loop, which is why the performance worsens as the number of routes grows

With 10 routes, matching first route (best case)
With 10 routes, matching last route (worst case)
With 100 routes, matching last route (worst case)
With 1000 routes, matching last route (worst case)

All versions of phroute 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 minhngoc/phroute contains the following files

Loading the files please wait ....