Download the PHP package haszi/router without Composer

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

A router and dispatcher written to learn about routers/dispatchers and the difficulties in writing these.

Requirements

PHP 8.0+

Installation

Features

Supported

Getting started

Basic usage

HTTP Methods

The router supports the following HTTP methods:

Using * for HTTP method will add a route for each of the above HTTP methods.

For each of the above methods there is also a corresponding shorthand method in the router. The shorthand for * is the method 'any'.

Multiple HTTP methods for one path can also be defined using an array of HTTP method strings.

Handlers

The router accepts a closure or a string in the form of 'controller@method' as a handler. The latter will be stored as a closure that will try to call the method on the class statically (if the method is available on the class, is static, non abstract and public) or will try to instantiate the class and call the method on it. On multiple route matches, the dispatcher will only call the handler of the first registered route.

Routes

Static Routes

Static routes are routes that do not have a dynamic, variable component. These routes will be matched exactly against the URI.

Dynamic Routes

Dynamic routes are routes of which certain parts can be variable. The router supports dynamic routes by using placeholder ({} notation) or PCRE regular expressions.

Please note that placeholders will accept any input, i.e. are the equivalent of a (.*?) regular expression. On dispatching a route, All placeholder values will be passed to the matching route's handler.

When using regular expressions, all variables returned by capturing groups will be passed to the matching route's handler.

Optional parameters

Parts of a route can be made optional by making a portion of the regular expression optional by using the ? token. (/\d+)?

Route groups

Routes can be defined as a group which will apply the same prefix to each route defined in that group.

Handler for unknown routes

A custom handler can be defined in the router for when no routes were found. If there is such a handler registered, the dispatcher will call this handler when no matching routes are found. There can only one handler be defined at a time. When a new handler is set, the previous one is replaced.

Before route middleware

Before route middleware are handlers that are executed before the actual route handler is called. Please note that all registered middleware will be executed for a route, and they will be executed in the order they have been registered.

Dispatcher

The dispatcher accompanying the router is a basic implementation that exercises all the functionalities of the router. I.e. it executes the registered middleware, 'route not found' handler if one registered (or throws an exception otherwise) and calls the registered route handler with the optional route parameters, and returns its result to the caller.

Acknowledgments / Credits

The concepts behind and implementation of this router/dispatcher was inspired and influenced by bramus/router and FastRoute. Additional inspiration was drawn from Symfony and Laravel.


All versions of router with dependencies

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

Loading the files please wait ....