Download the PHP package stratify/router without Composer

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

Routers implemented as a PSR-7 middleware.

This package provides 3 routers:

Everything is a middleware

Each router is a middleware, which means it can be used as many times as needed in a middleware stack. That also means that if a router doesn't match the request to a route, it's not an error: it will simply call the $next middleware.

Additionally, controllers (aka route handlers) are also middlewares. Routers are simply routing the flow of the request to a sub-branch of middlewares. That allows to remove the specific concept of "route middlewares".

Here is an example of using several routers in one application, as well as using middlewares in routes:

Please keep in mind this example is over-simplified. It's perfectly possible to benefit from dependency injection, lazy instantiation of controllers/middlewares as well as a simpler API for configuring the application; that's what the Stratify framework brings on top of the router.

Installation

Classic router

This "classic" router is very similar to other PHP routers. It is built on top of Aura.Router.

The router takes a map of URLs to callables, for example:

By default only the HTTP GET method will be allowed.

Placeholders can be used in route paths and fetched from request attributes or injected as parameters:

Routes can be configured in more details using the route() helper.

HTTP resources

You can define separate handlers for each HTTP method using the resource() helper:

However if you plan on using all HTTP methods you might want to use the RestRouter instead.

Controllers

Controllers, aka "route handlers", can be any PHP callables (closures, object methods, invokable objects, …).

The callable can decide which parameters it will take. The router will detect what to provide based on the callable's parameters. Parameters can be:

Since a controller/route handler is a middleware, it can also have the middleware signature:

Controller responses

Controllers, like middlewares, are expected to return PSR-7 response objects.

However, in order to ease development, they can also return strings: those will be automatically turned into 200 HTML responses.

REST router

The REST router behaves exactly like the classic router (the same rules applies for controllers) except that it allows to register handlers more easily for HTTP resources.

This is equivalent to this mapping with the classic router:

Here is an example of a REST controller:

Prefix router

The PrefixRouter is a very simple and very fast router that routes based on URL prefixes.

The first prefix to match is used. Each route handler must be a middleware, i.e. a callable whose signature matches:

The prefix router is useful to separate several parts of a large application that do not need the same middlewares, for example:


All versions of router with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
psr/http-message Version ^1.0
stratify/http Version ~0.5.0
aura/router Version ^3.0
psr/container Version ^1.0
php-di/invoker 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 stratify/router contains the following files

Loading the files please wait ....