Download the PHP package g4/aura-router without Composer

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

Aura Router

Build Status

Aura Router is a PHP package that implements web routing. Given a URI path and a copy of $_SERVER, it will extract controller, action, and parameter values for a specific application route.

Your application foundation or framework is expected to take the information provided by the matching route and dispatch to a controller on its own. As long as your system can provide a URI path string and a representative copy of $_SERVER, you can use Aura Router.

Aura Router is inspired by Solar rewrite rules and http://routes.groovie.org.

This package is compliant with PSR-0, PSR-1, and PSR-2. If you notice compliance oversights, please send a patch via pull request.

Basic Usage

Instantiation

The easiest way to instantiate a router is to include the scripts/instance.php file:

Alternatively, you can add Aura Router to your autoloader and instantiate it manually:

Adding A Route

To create a route, call the add() method.

You will need to place the router object where you can get to it from your application; e.g., in a registry, a service locator, or a dependency injection container. One such system is the Aura DI package.

Matching A Route

To match a URI path against your routes, call match() with a path string and the $_SERVER values.

The match() method does not parse the URI or use $_SERVER internally. This is because different systems may have different ways of representing that information; e.g., through a URI object or a context object. As long as you can pass the string path and a server array, you can use Aura Router in your application foundation or framework.

The returned $route object will contain, among other things, a $values array with values for each of the parameters identified by the route path. For example, matching a route with the path /{:controller}/{:action}/{:id} will populate the $route->values array with controller, action, and id keys.

Dispatching A Route

Now that you have route, you can dispatch it. The following is what a foundation or framework system might do with a route to invoke a page controller.

Again, note that Aura Router will not dispatch for you; the above is provided as a naive example only to show how to use route values.

Generating A Route Path

To generate a URI path from a route so that you can create links, call generate() on the router object and provide the route name.

Aura Router does not do dynamic matching of routes; a route must have a name to be able to generate a path from it.

The example shows that passing an array of data as the second parameter will cause that data to be interpolated into the route path. This data array is optional. If there are path params without matching data keys, those params will not be replaced, leaving the {:param} token in the path. If there are data keys without matching params, those values will not be added to the path.

As a Microframework

Sometimes you may wish to use Aura.Router as a micro-framework. It’s also possible by assigning anonymous function to controller.

When you are using Aura.Router as a micro-framework, the dispatcher will look like

So when you request for the url /blog/read/1.json, you will get json and for /blog/read/1 you will get Reading blog ID 1 as output.

Advanced Usage

Complex Route Specification

When you add a complex route specification, you describe extra information related to the path as an array with one or more of the following recognized keys:

Here is a full route specification named read with all keys in place:

Note that using closures, instead of callbacks, means you will not be able to serialize() or var_export() the router for caching.

Simple Routes

You don't need to specify a complex route specification. If you pass a string for the route instead of an array ...

... then Aura Router will use a default subpattern that matches everything except slashes for the path params, and use the route name as the default value for 'action'. Thus, the above short-form route is equivalent to the following long-form route:

Wildcard Routes

Sometimes it is useful to allow the trailing part of the path be anything at all. There are two types of such "wildcard" routes. (Wildcard routing of this sort works only when specified at the end of the path.)

The first is a "values optional" named wildcard, represented by adding /{:foo*} to the end of the path. This will allow the route to match anything after that point, including nothing at all. On a match, it will collect the remaining slash-separated values into a sequential array named 'foo'. Notably, the matched path with no wildcard values may have a slash at the end or not.

The second is a "values required" wildcard, represented by adding /{:foo+} to the end of the path. This will allow the route to match anything at all after that point, but there must be at least one slash and an additional value. On a match, it will collect the remaining slash-separated values into a sequential array named 'foo'.

N.b.: In previous releases of the router, '/*' was the wildcard indicator, with wildcard values collected in an array named '*'. This behavior remains available but is deprecated.

Attaching Route Groups

You can add a series of routes all at once under a single "mount point" in your application. For example, if you want all your blog-related routes to be mounted at '/blog' in your application, you can do this:

Each of the route paths will be prefixed with /blog, so the effective paths become:

You can set other route specification keys as part of the attachment specification; these will be used as the defaults for each attached route, so you don't need to repeat common information:

Constructor-Time Attachment

You can configure your routes in a single array of attachment groups, and then pass them to the router constructor all at once. This allows you to separate configuration and construction of routes.

Note that you can specify a name_prefix as part of the common route information for each attached route group; the route names in that group will be prefixed with that value. This helps with deconfliction of routes with the same names in different groups.

This technique can be very effective with modular application packages. Each package can return an array for its own route group specification, and a system-specific configuration mechanism can collect each spec into a common array for the router. For example:

Caching

You may wish to cache the router map for production deployments so that the router does not have to build the route objects from definitions on each page load. The methods getRoutes() and setRoutes() may be used for that purpose.

The following is a naive example for file-based caching and restoring of routes:

Note that if there are closures in the route definitions, you will not be able to cache the routes; this is because closures cannot be represented properly for caching. Use traditional callbacks instead of closures if you wish to pursue a cache strategy.


All versions of aura-router with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
aura/installer-default 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 g4/aura-router contains the following files

Loading the files please wait ....