Download the PHP package genai/routing without Composer

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

GenAI Routing

A minimal, dependency-free pure route matching engine for PHP, built and tested against PHP 5.3.29.

You give it an HTTP method and a request path; it matches them against your configured routes and returns the handler (e.g. UserController@show) together with any captured parameters. It does not read the request for you and it does not dispatch — it only answers the question "which controller/action handles this request?".


Features


Requirements


Installation

Option A — standalone (no Composer)

Require the bundled autoloader (see demo/autoload.php for a ready-made one):

Option B — Composer

A PSR-4 mapping is already declared in composer.json:

Run composer dump-autoload, then use Composer's autoloader as usual.


Quick start


Loading a whole route table at once

When you collect all controller/action pairs at boot, hand the entire table to the router with load(). Both entry shapes are accepted, so it fits whatever your compile step produces:

Caching the route table

The table is a plain array, so you can build it once and cache it to disk with var_export(), skipping the collection work on every request:


Route patterns

Pattern Matches Captured params
/users /users (none)
/user/{id} /user/5, /user/abc array('id' => '5')
/user/{id:\d+} /user/5 (not /user/abc) array('id' => '5')
/posts/{slug}/comments/{commentId} /posts/hello/comments/9 array('slug' => 'hello', 'commentId' => '9')

Notes:


Matching rules


API reference

GenAI\Routing\Router

Method Description
add($method, $pattern, $handler) Register one route. Returns $this.
get($pattern, $handler) Shortcut for add('GET', ...).
post($pattern, $handler) Shortcut for add('POST', ...).
put($pattern, $handler) Shortcut for add('PUT', ...).
patch($pattern, $handler) Shortcut for add('PATCH', ...).
delete($pattern, $handler) Shortcut for add('DELETE', ...).
any($pattern, $handler) Register a route matching any method.
load(array $routes) Register many routes from a single config array. Returns $this.
match($method, $path) Returns a RouteMatch, or false if nothing matched.

GenAI\Routing\RouteMatch

Method Description
getHandler() The raw handler as registered (e.g. 'UserController@show').
getParams() All captured params, e.g. array('id' => '5').
getParam($name, $default = null) A single param, or $default if absent.
getController() Controller part of a Controller@action handler.
getAction() Action part of a Controller@action handler.

Project layout


Running the example

With a local PHP:

Against a real PHP 5.3.29 via Docker (no local PHP needed):

Expected output:


PHP 5.3 compatibility notes

The codebase deliberately stays within PHP 5.3:


All versions of routing with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.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 genai/routing contains the following files

Loading the files please wait ...