Download the PHP package marceauka/router without Composer

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

Build Status

Router is a lightweight HTTP resquest router written in PHP.

It will be your perfect companion if you need a simple and effective library or if you want an easy to understand routing library.
Otherwise, take a look at these awesome libraries symfony/routing ou league/route.

Installation

Router can be installed with composer: composer require marceauka/router. For now, it requires PHP 7.4 or 8.0.

Also, copy / paste src/Router.php where you want and require it.

Configure Apache

The router works perfectly with any kind of URL, but if you want some url rewriting, you can use this example .htaccess.

Usage

Instanciation

Router as no params.

Adding routes

Once you have the instance, adding routes is childish.

Your routes can follow these HTTP verbs: POST, PUT, PATCH and DELETE.

A route can use many HTTP verbs:

Finally, routes can be chained or added with a callback:

If no callback is given to the routes() method, all routes will be returned.

Listening requests

For everything to work, Router needs to incoming requests:

Dispatching actions

Obviously, for each route, a need. You need to define an action for each of them.

Here, the route, once matched, will instanciate the class named "MyClass" and will call the "myMethod" method.
Note: Router will accepts namespaces if you application can autoload them (PSR-4, ...).

Besides, you can define a global namespace for all of your actions.

You can define a not found action when no routes was matched.

URL parameters

Your routes can contains dynamic parameters. Usage is simple.

Parameters can be:

Once matched, parameters are sent to the corresponding action in the URL defined order.

Named routes

You can give a name to your routes to access them later or easily creating links (in a view for example).

If your route contains parameters, you can build an URI with filled parameters.
You need to give all parameters expected by the route, otherwise and exception will be rised.

Caching

Sometimes, when our router contains many routes, it's convenient to have a ready-to-use Router instance for each script execution. Router supports serialization and unserialization. Two helpers exists to assists you.

Note: Routes using a callback can't be serialized. Only the "MyClass@myMethod" is serializable.
The router does not provide functionnality to store or read a cache file. It's not its goal.

Tests

Tests are with PHPUnit 9. You can use the phpunit command given at vendor/bin.

Tests are certainly incomplete. Feel free to contribute.

Licence

MIT


All versions of router with dependencies

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

Loading the files please wait ....