Download the PHP package alexya-framework/router without Composer

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

Router

Alexya's routing components

Contents

Instantiating Router objects

The router translates the HTTP requests and routes them through different specified callbacks until one can handle it.

First you'll need to instance a Router object that will route the requests.

The constructor accepts as parameter a string being the base path.

Example:

Adding routes

Once the router has been instantiated you will have to add the routes, you can do this using the method add. The first parameter is the regular expression to match, the second parameter is the callback to execute if the regular expression is matched, the third parameter is an array containing the methods where the regular expression should be tested (if it's empty it will be tested globaly).

There are 2 ways for calling this method:

Adding a single route

To add a single route you need to provide at least the first 2 arguments:

Optionally you can send a 3rd parameter that can be either an array or a string, this parameter will contain the method(s) on which the expression should me matched.

Example:

Adding multiple routes

To add multiple routes you need to provide a single parameter that is an array which contains all the routes to match, each index of the array is an array that contains at least 2 index:

Optionally you can add a 3rd index that can be either an array or a string, this index will contain the method(s) on which the expression should be matched.

Example:

Matching routes

Once all routes have been added you will need to call the route method which will parse the request through all routes, if the request matches a route, its callback will be executed, if not, it will throw an exception of type \Alexya\Router\Exceptions\NoRouteMatch.

The default route

To avoid a exception to be thrown, you can use the method setDefault which accepts as parameter the \Alexya\Router\Route object to be executed if the request doesn't match any route. Alternatively, you can use the method add and send {DEFAULT} as the regular expression.

Example:

Chainable routes

Sometimes it's a good idea to have multiple routes work in a single request. For example, you could check that the page exists in a route, then check if the user is logged in another, then load the page in another route...

The function \Alexya\Router\Router::route can accept as parameter a boolean that tells if the router will support chainable routes or not.

When the router supports chainable routes it will loop through ALL routes and execute all the routes that are matched, to stop the router you can let the route callback return false or finish the script execution with die or exit.

Example:


All versions of router with dependencies

PHP Build Version
Package Version
Requires php Version >=7.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 alexya-framework/router contains the following files

Loading the files please wait ....