Download the PHP package math280h/php-router without Composer

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

php-router

Simple PHP Router, it supports features such as middlewares and views using aura/view

Installation

Usage

For simple usage you can inline callback functions directly in the routes as shown below.

Note: The router always passes the Request object to callback functions

Accepting different HTTP Methods

The router exposes a function for each accepted HTTP method. The list of available methods are:

And they can be called like so:

Route groups

You can group routes together, this allows you to e.g. define a prefix for a colleciton of routes or apply middleware to the collection of routes.

You can define a route group like so:

This example results in two routes with the paths /test/1 and /test/2

Adding middleware

The router supports middleware than runs after the connection is accepted but before the request is forwarded to the callback function.

For now, only direct callback functions are supported and can be added to the router like so:

The router will always pass the request object to the callback function.

Once the middleware is added to the router you can attach it to your route like so:

Passing callbacks from classes to the router

The router allows you to pass references to functions inside classes instead of inlining the callback functions You can do this like so:

Returning views

The router is built with support for aura/view. This allows callback functions to pass back a view and the router will automatically render it.

This can achieved like so:

It's recommended to implement a helper function for spinning up new views so you don't have to duplicate the factory creation in your code

View helper function

A view helper function can look something like this:


All versions of php-router with dependencies

PHP Build Version
Package Version
Requires aura/view Version ^2.4
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 math280h/php-router contains the following files

Loading the files please wait ....