Download the PHP package asko/router without Composer

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

codecov

A PHP router with built-in configuration-free dependency injection.

Install

Usage

The most basic usage example looks like this:

All HTTP methods are supported: get, head, post, put, delete, patch, options, trace. To catch any HTTP method, use any.

To set a 404 handler, use the not_found method, which just takes a callable as its only argument.

Callables

You can pass 3 different types of callables to the router.

Controllers

Controllers are classes which are mostly used for grouping routes that are similar together, so let's say you have Admin page routes, well, it would make sense to create a AdminController class for that, where each method in it represents a single route. To use controller classes with Router you need to pass an array as the callable, where the first item is the class constant and the second the name of the method, like so:

Functions

Functions are regular PHP functions where you pass the name of the function as the callable. This is useful if you want to do more functional style programming, like so:

Closures

You can also entirely forgo having named functions and instead use anonymous functions in the form of Closures, like so:

Parameters

Parameters in Router are named, and then used in the function (or method) declaration as arguments with those same names. So let's say you have this Route:

Then the argument name you need to refer to is also $who, like so:

You can have as many parameters as you wish, and the order of which you have them in the function declaration does not matter. The only thing that matters is that the name matches the Route parameter.

Note: your parameters must be type hinted as either string, int or float. Leaving parameters untyped will assume the parameter is string.

Dependency injection

Router has configuration-free dependency injection in the form of type hinting classes in the function (or method) declaration. Dependency injections must occur before Route parameters. An example injection looks like this:

The above examples instantiates the SomeDependency class and injects it into the callable. All callable types are supported: Controller methods (and constructor methods!), functions and Closures.

All injections are also recursive in nature, which means that the injected classes can also benefit from configuration-free dependency injection by type hinting injections in their respective constructor methods.

Middlewares

Middlewares are a way to run code before the actual route is dispatched. You can use middlewares to check if a user is authenticated, or if a user has the right permissions to access a route, etc. Middlewares are added to the router by using the middleware method, like so:

When the above route is dispatched, the SomeMiddleware class will be instantiated and the handle method will be called. If the handle method returns anything other than null, the route will not be dispatched and the return value of the handle method will be returned instead.

The handle method of a middleware also fully supports dependency injection, and can make use of the same parameters as in the route itself.


All versions of router with dependencies

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

Loading the files please wait ....