Download the PHP package componenta/router without Composer

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

Componenta Router

Runtime HTTP router for Componenta applications. The package provides immutable route records, fluent route building, route groups, route collections, path pattern compilation, optimized compiled routes, URL generation, PSR-15 route matching and dispatch middleware, handler resolution, and router exception handlers.

Attribute discovery, production route-cache generation, and HTTP-interceptor route handler resolution live in componenta/router-app.

Installation

Package Boundaries

componenta/router owns runtime routing behavior. It can work with explicitly registered routes and does not require class scanning.

Related Packages

Package Why it matters here
componenta/http-responder Provides HTTP response helpers; router only selects handlers and does not format controller output.
componenta/middleware-factory Turns strings, classes, groups, and middleware instances into MiddlewareInterface.
componenta/di Creates route handlers and middleware from the container when needed.
componenta/router-app Discovers #[Route] attributes, builds route cache files, and provides application HTTP-interceptor route handler resolution.

Use componenta/router for:

Use componenta/router-app for:

Route Records

RouteRecord is an immutable route definition.

Public fields:

Field Type Meaning
name string Unique route name used for matching result and URL generation.
path string Normalized route path.
handler RouteHandler Handler definition wrapped as route middleware.
methods list<string> Uppercase HTTP methods.
middlewares ?MiddlewareGroup Route-level middleware group.
tokens array<string, string> Regex constraints for path parameters.
defaults array<string, mixed> Scalar defaults for optional parameters.
group ?string Group name to apply through Routes.

Static constructors exist for get, post, put, patch, delete, head, options, and any.

RouteRecord validates early:

Fluent Builder

RouteBuilder is useful when a route is assembled conditionally.

build() throws LogicException when no handler was set.

Path Syntax

The default compiler uses CompositeSyntax, so several parameter syntaxes are accepted:

Syntax Meaning
/posts/{id} Required parameter.
/posts/[id] Required parameter.
/posts/:id Required parameter in colon syntax.
/posts/[?page] Optional parameter.
/posts/[id:\d+] Inline regex constraint.
/posts/[?page:\d+=1] Optional parameter with regex and default.

Explicit tokens override inline tokens. Explicit defaults override inline defaults.

Groups

RouteGroup applies name prefix, path prefix, middleware, tokens, and defaults to child routes.

The route above is registered as:

Nested groups are registered in the parent collection, so later routes can reference the full group name explicitly.

Route Collection

Routes implements:

Routes compiles static and dynamic lookup tables lazily after registration. Static routes use hash lookup. Dynamic routes use compiled regex patterns.

Routes accepts an optional SyntaxParserInterface as the named syntax argument for URL generation. When omitted, it uses the built-in Compiler syntax, or CompositeSyntax for another CompilerInterface implementation. A custom compiler does not need to expose a syntax property.

Router Facade

Router combines a route collector, matcher, and generator.

match() throws:

generate() throws:

Match Result

MatchResult contains data needed for dispatch:

Field Type
name string
handler RouteHandler
middlewares ?MiddlewareGroup
parameters array<string, mixed>
route RouteRecord lazy property

Matched parameters are cast from numeric strings to integers or floats when possible.

PSR-15 Middleware

MatchRouteMiddleware matches the incoming request and stores the result in request attributes:

DispatchRouteMiddleware reads the match result and resolves route middleware through MiddlewareFactory.

DispatchRouteMiddleware resolves route middleware on every request through the configured factory. The container and middleware resolver determine object lifetimes; compiled route collections preserve the same resolution and execution behavior.

Router Exception Handlers

Handler Behavior
ThrowingRouterExceptionHandler Re-throws router exceptions for a global error handler.
RouterExceptionHandler Returns 404 or 405 PSR-7 responses.
JsonRouterExceptionHandler Returns JSON 404/405 responses and Allow for 405.
CallableRouterExceptionHandler Delegates handling to a closure.

Compiled Routes

CompiledRoutes loads an explicitly compiled route collection from a generated cache file.

Performance model:

The cache file is generated by RouteCacheGenerator, normally through componenta/router-app and app:build. Production service factories load the map when optimization is enabled. Rebuild it whenever route definitions, configuration or external inputs used by the route source change. Combined expressions are checked against PCRE limits and oversized groups are split further. If a combined expression exhausts a matching limit, matching continues through the original individual route patterns. CachedRouteLocator falls back to its supplied source when generated data is invalid, including when the application converts warnings into exceptions.

Replacing a compiled collection's public compiler before its first match uses the source matching path. URL generation uses the current compiler while retaining any explicitly configured generation syntax. Cache format 8 records whether that syntax was explicit; tryFromCache() rejects older formats so its caller can use the source.

Attribute Route Metadata

#[Route] is the runtime metadata class consumed by application discovery.

Constructor:

methods accepts a string ('GET'), a |-separated string ('GET|POST'), or an array (['GET', 'POST']). priority is used by componenta/router-app: when multiple attribute routes can match the same URI, the route with the higher priority is added first.

The base router package does not scan this attribute. Discovery belongs to componenta/router-app.

Configuration

ConfigProvider registers:

Config keys:

Key Meaning
ConfigKey::ROUTES_FILE Path to route definition file.
ConfigKey::ROUTES_CACHE_FILE Optional explicit route cache file path.
ConfigKey::COMPILED_PIPELINE Enables the compiled route map in production; defaults to true.

Failure Model

Exception When
RouteAlreadyExistsException Duplicate route name registration.
RouteNotRegisteredException URL generation references unknown route name.
RouteNotFoundException URI/method cannot be matched.
MethodNotAllowedException URI matches a route, but method is not allowed.
GroupNotFoundException Requested group is absent.

All versions of router with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
componenta/arrayable Version ^1.0
componenta/config Version ^3.0.0
componenta/di Version ^5.0.3
componenta/http-responder Version ^1.0.3
componenta/middleware-factory Version ^2.1.0
componenta/path-resolver Version ^1.0
componenta/var-export Version ^2.0.0
psr/container Version ^2.0
psr/http-message Version ^2.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 componenta/router contains the following files

Loading the files please wait ...