Download the PHP package bermudaphp/router without Composer

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

Bermuda Router

๐Ÿ‡ท๐Ÿ‡บ ะ ัƒััะบะฐั ะฒะตั€ัะธั

Flexible and performant routing library for PHP 8.4+ with route caching support.

Table of Contents

Installation

Requirements: PHP 8.4+

Quick Start

Creating Routes

HTTP Verb Helper Methods

Method HTTP Methods Description Usage Example
get() GET Retrieve data RouteRecord::get('users.index', '/users', 'UsersController')
post() POST Create new resources RouteRecord::post('users.store', '/users', 'UsersController::store')
put() PUT Full resource update RouteRecord::put('users.update', '/users/[id]', 'UsersController::update')
patch() PATCH Partial resource update RouteRecord::patch('users.patch', '/users/[id]', 'UsersController::patch')
delete() DELETE Delete resource RouteRecord::delete('users.destroy', '/users/[id]', 'UsersController::destroy')
head() HEAD Retrieve headers RouteRecord::head('users.check', '/users/[id]', 'UsersController::head')
options() OPTIONS Get available methods RouteRecord::options('users.options', '/users', 'UsersController::options')
any() Custom Multiple HTTP methods RouteRecord::any('users.resource', '/users/[id]', 'UsersController', ['GET', 'PUT', 'DELETE'])

Using RouteBuilder

Route Parameters

Basic Parameters

Predefined Patterns

Name Pattern Description Examples
id \d+ Numeric ID 1, 123, 999
slug [a-z0-9-]+ URL-compatible string hello-world, my-post
uuid [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} UUID v4 format 550e8400-e29b-41d4-a716-446655440000
any .+ Any characters including slashes any/path/here
alpha [a-zA-Z]+ Letters only Hello, ABC
alnum [a-zA-Z0-9]+ Letters and digits Hello123, ABC789
year [12]\d{3} 4-digit year (1900-2999) 2024, 1995
month 0[1-9]\|1[0-2] Month (01-12) 01, 12
day 0[1-9]\|[12]\d\|3[01] Day of month (01-31) 01, 15, 31
locale [a-z]{2}(_[A-Z]{2})? Locale code en, en_US, fr_FR
version v?\d+(\.\d+)* Version string 1.0, v2.1.3
date \d{4}-\d{2}-\d{2} ISO date (YYYY-MM-DD) 2024-12-25

Custom Patterns

Inline Patterns

Inline patterns allow defining regex patterns directly in route definition. Syntax: [parameter_name:regular_expression]

Setting Patterns via Methods

Pattern Priority

Patterns are applied in the following priority order (highest to lowest):

  1. Inline patterns in route: [id:\d+]
  2. Method patterns: ->withToken('id', '\d+')
  3. Group patterns: $group->setTokens(['id' => '\d+'])
  4. Predefined patterns: from table above
  5. Default pattern: [^\/]+ (any characters except slash)

Default Values

Route Groups

Groups allow organizing related routes with common settings:

Group Configuration

URL Generation

PSR-15 Middleware Integration

Basic Setup

Using RouteNotFoundHandler

RouteNotFoundHandler handles requests for non-existent routes and can work in two modes:

Integration in Middleware Pipeline

Accessing Route Data in Controllers

Route Locators

For loading routes from configuration files:

Locator Setup

Routes File

PHP Attribute-based Route Location

The library supports automatic route discovery through PHP attributes on controller methods. This allows defining routes declaratively, right next to handlers.

Installation

Attribute support requires an additional package:

Route Attribute

The #[Route] attribute allows defining routes directly on controller methods:

Route Attribute Parameters

Parameter Type Description Example
name string Unique route name 'users.show'
path string URL pattern with parameters '/users/[id]'
methods string\|array HTTP methods (string or array) 'GET', 'PUT\|PATCH', ['GET', 'POST']
middleware array Middleware array for route ['auth', 'validation']
group string Route group name 'api'
priority int Route priority (higher = earlier) 10
defaults array Default parameter values ['format' => 'json']

AttributeRouteLocator Setup

AttributeRouteLocator works as a decorator for existing route locators:

ClassFinder Integration

For automatic controller discovery with attributes, ClassFinder is used (already included in dependencies):

๐Ÿ“‹ Detailed documentation: bermudaphp/finder | Russian Guide

Full Application Integration

Groups via Attributes

โš ๏ธ Important: Route groups must be predefined in code (e.g., in base locator's routes file), otherwise RouterException will be thrown.

Route Priorities

Priorities determine the order of route checking when matching requests. Routes with higher priority are checked first.

Priority Rules:

When to use priorities:

Priority example for API versioning:

Regular routes vs attribute routes:

Accessing Route Handler

RouteRecord provides convenient access to various route components:

Route Caching

For improved performance in production:

Creating Cache

Using Cache

Cache with Context for Closures

When routes use closures with external variables (via use), these variables must be available when loading cached routes. Context allows passing necessary objects and data to the cached file scope.

Caching Limitations

The caching system has the following limitations:

โŒ What cannot be cached

โœ… What can be cached

๐Ÿ’ก Recommendations

  1. Use string handlers in production for maximum cache compatibility
  2. Pass contextual data if using use in closure handlers

Most preferred handler type - class name or class and method combination

Error Handling

Exception Types


All versions of router with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
bermudaphp/psr15factory Version ^3.0
bermudaphp/var-export Version ^2.0.1
bermudaphp/number Version ^2.0
bermudaphp/config Version ^2.0
fig/http-message-util Version ^1.1
psr/http-message Version ^2.0
psr/http-server-handler Version ^1.0
psr/http-server-middleware Version ^1.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 bermudaphp/router contains the following files

Loading the files please wait ....