Skip to content

Latest commit

 

History

History
102 lines (75 loc) · 9.33 KB

File metadata and controls

102 lines (75 loc) · 9.33 KB

Table of contents


Class: Rudra\Router\Attributes\Middleware

Visibility Function
public __construct(string $name, ?string $params)

Class: Rudra\Router\Attributes\Routing

Visibility Function
public __construct(string $url, array|string $method)

Class: Rudra\Router\Router

Visibility Function
public set(array $route): void
Sets the route, parsing HTTP methods (if multiple are specified via |).
Registers a route handler for each method.
private handleRequestUri(array $route): void
Processes the incoming URI request and checks if it matches the current route.
private handleRequestMethod(): void
Processes the HTTP request method, including spoofing via _method (for PUT/PATCH/DELETE)
private handlePattern(array $route, array $request): array
Matches the URI from the route with the actual request, processing parameters of the form :param and :regexp.
This method is used to extract dynamic segments from a URI pattern
private setCallable(array $route, ?array $params): void
Calls the controller associated with the route — either a Closure or a controller method.
public directCall(array $route, ?array $params): void
Calls the controller and its method directly, performing the full lifecycle:
This method is used to fully dispatch a route after matching it with the current request.
private callActionThroughReflection(?array $params, string $action, object $controller): void
Calls the controller method using Reflection, performing automatic parameter injection based on type hints.
This method is typically used when the zend.exception_ignore_args setting is enabled,
allowing for more flexible and type-safe dependency resolution.
private callActionThroughException(?array $params, string $action, object $controller): void
Calls the specified controller method directly.
If the argument type or number does not match — tries to automatically inject required dependencies.
This is a fallback mechanism for cases where Reflection-based injection is disabled or unavailable.
Handles two types of errors during invocation:
- \ArgumentCountError — thrown when the number of arguments doesn't match the method signature.
- \TypeError — thrown when an argument is not compatible with the expected type.
In both cases, Rudra's autowire system attempts to resolve and inject the correct dependencies.
public handleMiddleware(array $chain): void
Executes a chain of middleware, recursively calling each element.
Middleware can be specified in one of the supported formats:
- 'MiddlewareClass' (string) — a simple class name to call without parameters.
- ['MiddlewareClass'] (array with class name) — same as above, allows for future extensions.
- ['MiddlewareClass', $parameter] (array with class and parameter) — passes the parameter to the middleware.
Each middleware must implement the __invoke() method to be callable.
public annotationCollector(array $controllers, bool $getter, bool $attributes): ?array
Collects and processes annotations from the specified controllers.
This method scans each controller class for Routing and Middleware annotations,
builds route definitions based on those annotations, and either:
- Registers them directly via set() (if $getter = false), or
- Returns them as an array (if $getter = true).
protected handleAnnotationMiddleware(array $annotation): array
Processes middleware annotations into a valid middleware format.
#[Middleware(name: "Auth", params: "admin")]
to:
['Auth', 'admin']
public __construct(Rudra\Container\Interfaces\RudraInterface $rudra)
public rudra(): Rudra\Container\Interfaces\RudraInterface
public get(string $pattern, callable|array $target, array $middleware): void
Registers a route with the GET HTTP method.
public post(string $pattern, callable|array $target, array $middleware): void
Registers a route with the POST HTTP method.
public put(string $pattern, callable|array $target, array $middleware): void
Registers a route with the PUT HTTP method.
public patch(string $pattern, callable|array $target, array $middleware): void
Registers a route with the PATCH HTTP method.
public delete(string $pattern, callable|array $target, array $middleware): void
Registers a route with the DELETE HTTP method.
public any(string $pattern, callable|array $target, array $middleware): void
Registers a route that supports all HTTP methods.
Sets the method to a pipe-separated string ('GET|POST|PUT|PATCH|DELETE'),
allowing the same route to handle multiple request types.
public resource(string $pattern, string $controller, array $actions): void
Registers a resource route, mapping standard actions to controller methods.
Supports common CRUD operations by default:
- GET=> read
- POST => create
- PUT=> update
- DELETE => delete
Can be customized with an optional $actions array.
protected setRoute(string $pattern, $target, string $httpMethod, array $middleware): void
The method constructs a route definition and passes it to the set() method for registration.

Class: Rudra\Router\RouterFacade

Visibility Function
public static __callStatic(string $method, array $parameters): mixed
Handles static method calls for the Facade class
It dynamically resolves the underlying class name by removing "Facade" from the class name
If the resolved class does not exist, it attempts to clean up the class name by removing spaces
If the resolved class is not already registered in the container, it registers it
Finally, it delegates the static method call to the resolved class instance

Class: Rudra\Router\RouterInterface

Visibility Function
abstract public set(array $route): void
abstract public directCall(array $route, ?array $params): void

Class: Rudra\Router\Traits\RouterAnnotationTrait

Visibility Function
public annotationCollector(array $controllers, bool $getter, bool $attributes): ?array
Collects and processes annotations from the specified controllers.
This method scans each controller class for Routing and Middleware annotations,
builds route definitions based on those annotations, and either:
- Registers them directly via set() (if $getter = false), or
- Returns them as an array (if $getter = true).
protected handleAnnotationMiddleware(array $annotation): array
Processes middleware annotations into a valid middleware format.
#[Middleware(name: "Auth", params: "admin")]
to:
['Auth', 'admin']

Class: Rudra\Router\Traits\RouterRequestMethodTrait

Visibility Function
public get(string $pattern, callable|array $target, array $middleware): void
Registers a route with the GET HTTP method.
public post(string $pattern, callable|array $target, array $middleware): void
Registers a route with the POST HTTP method.
public put(string $pattern, callable|array $target, array $middleware): void
Registers a route with the PUT HTTP method.
public patch(string $pattern, callable|array $target, array $middleware): void
Registers a route with the PATCH HTTP method.
public delete(string $pattern, callable|array $target, array $middleware): void
Registers a route with the DELETE HTTP method.
public any(string $pattern, callable|array $target, array $middleware): void
Registers a route that supports all HTTP methods.
Sets the method to a pipe-separated string ('GET|POST|PUT|PATCH|DELETE'),
allowing the same route to handle multiple request types.
public resource(string $pattern, string $controller, array $actions): void
Registers a resource route, mapping standard actions to controller methods.
Supports common CRUD operations by default:
- GET=> read
- POST => create
- PUT=> update
- DELETE => delete
Can be customized with an optional $actions array.
protected setRoute(string $pattern, $target, string $httpMethod, array $middleware): void
The method constructs a route definition and passes it to the set() method for registration.