Download the PHP package hotaruma/http-router without Composer

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

HTTP Router

Build and Test Latest Version License PHP from Packagist Packagist Downloads codecov

Simple HTTP router.

Navigation

Installation

You can install the library using Composer. Run the following command:

RouteMap

Creating Routes

To create routes, you need to use the RouteMap class. Here's an example of creating a route:

Route Parameters

You can also define route parameters using curly braces {} in the route path:

Route Config

Routes can be configured by defining its defaults, rules, and more.

It is preferable to use named attributes for configuration. By using named attributes, you can explicitly specify the purpose of each configuration option, improving the readability of your code.

Pattern Registry

The patterns can be defined in both the rules array and directly within the route path declaration. When patterns are defined in the rules array, they take precedence. Patterns are enclosed in curly braces {} follow the format {placeholder:rule}. Here's an example:

In this example, rules array defines the pattern id:\d+ and {category:slug} placeholder specifies that the category parameter in the URL should be a [A-Za-z0-9-_]+.

By default, we have the following rules:

You can also define your own patterns and register them in the pattern registry. The patterns in the registry can be either regular expression strings or Closures that perform custom validation. Here's an example:

In this example, we register a custom pattern named 'custom' using a Closure that performs the validation.

If a route specifies both a rule in the route path and a rule in the route configuration, the rule in configuration takes precedence.

Grouping Routes

You can group routes with a common prefix and apply shared middleware or other configurations:

When grouping routes and nesting one group within another, you have the ability to merge configurations. This means that each route inside a group merges its configuration with the group's configuration, and each nested group merges its configuration with its parent group.

By organizing routes into groups, you can apply specific configurations to multiple routes at once. The configurations cascade down the nested groups, allowing you to inherit and override settings as needed. This provides a powerful and flexible way to manage and organize your routes.

Route Scanner

By using PHP 8's attribute syntax, you can easily annotate your classes and methods with route attributes, simplifying the process of defining routes in your application.

The Route Scanner scans the provided classes for attributes that extend the RouteInterface and RouteGroupInterface. It extracts the route configuration from these attributes and registers the routes in the RouteMap, a data structure that holds all the defined routes.

By calling the scanRoutes method of the RouteScanner class and passing the ApiController class as an argument, the routes defined in the class will be scanned and registered in the RouteMap.

The Route Scanner can be used within the RouteMap and its groups.

When scanning routes using $routeMap->scanRoutes() and encountering the RouteGroup attribute, the configuration defined within the attribute will take precedence over the current group configuration set by $routeMap->group(). This means that the configuration specified in RouteGroup will be used for the routes within that specific class.

The routeActionBuilder method allows you to customize how the action for a created route will look like, based on the class name and method name. This can be useful if you want to modify the default behavior of action generation for the routes.

The scanRoutesFromDirectory function allows you to scan all PHP files in a specified directory and its subdirectories to automatically discover classes and their attributes marked with the Route and RouteGroup attributes.

Route Dispatcher

Once the routes are defined, you can use the RouteDispatcher class to match the incoming request to the appropriate route and extract the associated attributes. You can configure the RouteDispatcher and match the routes:

You can customize the route dispatching process by providing your own implementation of the RouteMatcherInterface interface.

URL Generator

To use the RouteUrlGenerator, you need to create a RouteMap instance with defined routes.

You can customize the route url generation by providing your own implementation of the RouteUrlBuilderInterface interface.

Contributing

Contributions are welcome! If you find a bug or have an idea for a new feature, please open an issue or submit a pull request.


All versions of http-router with dependencies

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

Loading the files please wait ....