Download the PHP package proteins/route without Composer

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

Protein | Route

A simple and fast URL router

Install


Require the global class via :

URL mapping


You can define a route via the on method.

This is the simplest form to define an HTTP GET route responding on URL /hello.
You can map the same route to multiple request methods using the fluent api interface.

The via method accepts an array of string for handled HTTP request methods.

The with method binds a callable function to the route.

If you need to map various HTTP methods to different callbacks for a single URL (like exposing a resource via a REST API) the map method allows you to pass a method => callback dictionary.

The any shorthand will trigger the route responding on URL /hello for any HTTP verb.

This is the same as doing :

URL pattern matching and parameters extraction


The route pattern is essentially a Regular Expression with some slight differencies.

The pattern is ALWAYS matched against the end of the REQUEST_URI parameter (stripped of the query string).

Rules:

Examples:

In this example the optional (is in a (...) group) :id is extracted when present, and the route can be optionally terminated by a /.

This route handles all of these request:

But, as you can see, this example handles also /element/fooo. If we want to give format rules to an extracted parameters we can use the rules method.

The rules method accepts a named_parameter => regex dictionary.

rules([ 'parameter_name' => 'parameter_regex_pattern' ])

We can strenghten the former example adding rules to the id parameter for accepting only integer values (defined by the \d+ regex pattern).

Example:

Route groups


You can encapsulate routes based on a prefix pattern. If the current request doesn't match the group URL pattern, relative routes definition are not registered.

Note: This behaviour is controlled by the core.route.pruning flag.

This feature can be used for response-time optimization and for mounting route trees to a dynamic URL prefix.

You can define multiple nested route groups.

Examples:

Admin section

Route groups with dynamic parameters

RouteGroups can have dynamic parameters that will be extracted like normal Routes.

Route middlewares


You can append a list of middlewares before and after a Route, or a RouteGroup.

If a middleware returns false the entire route execution halts.

Middlewares can be chained, the befores will be executed in reverse declaration order (FIFO), the afters in direct declaration order (LIFO).

Gives this output :

You can apply a middleware to multiple routes a single time using a RouteGroup :

Dispatching routes


Remember to invoke the dispatch method before script end for route execution.

You can override the request URI and method passing them as parameters to the dispatch method :

Example :

The matched (if any) route can be returned without being automatically executed passing true to the return_route parameter :

Route can't find a match. (HTTP 404)


When no routes matches the current request, the 404 event is triggered.

You can append a view to the Response to show a courtesy page.

Render shortcuts


Instead of the rendering callback, you can also pass a string or a view, for direct rendering.

Closure

A View

A string (not a callable one)

An object

HTTP/2 Resource Push


You can push resources directly from the Route and RouteGroup definitions.
The syntax is the same as for the Response::push method.

URL tagging and Reverse Routing


You can add a name tag to a route via the tag method :

A named route is retrieved via the Route::tagged($name) method :

To get the URL for a route use the getURL($params = []) method :

As a shorthand, you can obtain the URL for the named route via the Route::URL($name, $params = []) helper :

You can also pass an array to map and assign the dynamic values of the route.

Note: The returned value of the Route::URL method is an [[URL]] object.

Events and Filters


Route has the Events trait behaviour, the only difference is that the Events::on method is renamed to onEvent to avoid collisions with the Route::on handler.

Available Events

Name Parameters Description
start route,args,method A route run method has been called.
before route,middleware A route pre middleware is called.
after route,middleware A route post middleware is called.
end route,args,method A route run method has ended.
404 No routes can be dispatched.

Available Filters

Name Parameters Description
core.route.response response_body Filter the route response body output.

All versions of route with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2
proteins/event Version ^1.0.0
proteins/filter Version ^1.0.0
proteins/url Version ^1.0.0
proteins/request Version ^1.0.0
proteins/response Version ^1.0.0
proteins/options Version ^1.0.0
proteins/extensions Version ^1.0.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 proteins/route contains the following files

Loading the files please wait ....