2026-02-13 21:07:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
2026-02-13 23:26:31 +00:00
|
|
|
namespace Atlas\Router;
|
2026-02-13 21:07:59 +00:00
|
|
|
|
|
|
|
|
use Psr\Http\Message\UriInterface;
|
|
|
|
|
|
2026-02-14 04:04:38 +00:00
|
|
|
/**
|
|
|
|
|
* Represents a complete route definition with matching patterns, handlers, and metadata.
|
|
|
|
|
*
|
|
|
|
|
* @final
|
|
|
|
|
*/
|
2026-02-13 21:07:59 +00:00
|
|
|
final class RouteDefinition
|
|
|
|
|
{
|
2026-02-14 04:04:38 +00:00
|
|
|
/**
|
|
|
|
|
* Constructs a new RouteDefinition instance.
|
|
|
|
|
*
|
|
|
|
|
* @param string $method HTTP method (GET, POST, etc.)
|
|
|
|
|
* @param string $pattern Matching pattern (currently not used for matching)
|
|
|
|
|
* @param string $path Normalized path for comparison
|
|
|
|
|
* @param mixed $handler Route handler
|
|
|
|
|
* @param string|null $name Optional route name
|
|
|
|
|
* @param array $middleware Middleware for route processing
|
|
|
|
|
* @param array $validation Validation rules for route parameters
|
|
|
|
|
* @param array $defaults Default parameter values
|
|
|
|
|
* @param string|null $module Module identifier
|
|
|
|
|
* @param array $attributes Route attributes for parameter extraction
|
|
|
|
|
*/
|
2026-02-13 21:07:59 +00:00
|
|
|
public function __construct(
|
|
|
|
|
private readonly string $method,
|
|
|
|
|
private readonly string $pattern,
|
|
|
|
|
private readonly string $path,
|
|
|
|
|
private readonly mixed $handler,
|
|
|
|
|
private readonly string|null $name = null,
|
|
|
|
|
private readonly array $middleware = [],
|
|
|
|
|
private readonly array $validation = [],
|
|
|
|
|
private readonly array $defaults = [],
|
|
|
|
|
private readonly string|null $module = null,
|
|
|
|
|
private readonly array $attributes = []
|
|
|
|
|
) {}
|
|
|
|
|
|
2026-02-14 04:04:38 +00:00
|
|
|
/**
|
|
|
|
|
* Gets the HTTP method of this route definition.
|
|
|
|
|
*
|
|
|
|
|
* @return string HTTP method
|
|
|
|
|
*/
|
2026-02-13 21:07:59 +00:00
|
|
|
public function getMethod(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->method;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-14 04:04:38 +00:00
|
|
|
/**
|
|
|
|
|
* Gets the path for this route definition.
|
|
|
|
|
*
|
|
|
|
|
* @return string Normalized path
|
|
|
|
|
*/
|
2026-02-13 21:07:59 +00:00
|
|
|
public function getPath(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->path;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-14 04:04:38 +00:00
|
|
|
/**
|
|
|
|
|
* Gets the handler for this route definition.
|
|
|
|
|
*
|
|
|
|
|
* @return string|callable Route handler
|
|
|
|
|
*/
|
2026-02-13 21:07:59 +00:00
|
|
|
public function getHandler(): string|callable
|
|
|
|
|
{
|
|
|
|
|
return $this->handler;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-14 04:04:38 +00:00
|
|
|
/**
|
|
|
|
|
* Gets the optional name of this route.
|
|
|
|
|
*
|
|
|
|
|
* @return string|null Route name or null
|
|
|
|
|
*/
|
2026-02-13 21:07:59 +00:00
|
|
|
public function getName(): ?string
|
|
|
|
|
{
|
|
|
|
|
return $this->name;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-14 04:04:38 +00:00
|
|
|
/**
|
|
|
|
|
* Gets the middleware configuration for this route.
|
|
|
|
|
*
|
|
|
|
|
* @return array Middleware configuration
|
|
|
|
|
*/
|
2026-02-13 21:07:59 +00:00
|
|
|
public function getMiddleware(): array
|
|
|
|
|
{
|
|
|
|
|
return $this->middleware;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-14 04:04:38 +00:00
|
|
|
/**
|
|
|
|
|
* Gets the validation rules for this route.
|
|
|
|
|
*
|
|
|
|
|
* @return array Validation rules
|
|
|
|
|
*/
|
2026-02-13 21:07:59 +00:00
|
|
|
public function getValidation(): array
|
|
|
|
|
{
|
|
|
|
|
return $this->validation;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-14 04:04:38 +00:00
|
|
|
/**
|
|
|
|
|
* Gets the default values for parameters.
|
|
|
|
|
*
|
|
|
|
|
* @return array Default parameter values
|
|
|
|
|
*/
|
2026-02-13 21:07:59 +00:00
|
|
|
public function getDefaults(): array
|
|
|
|
|
{
|
|
|
|
|
return $this->defaults;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-14 04:04:38 +00:00
|
|
|
/**
|
|
|
|
|
* Gets the module identifier for this route.
|
|
|
|
|
*
|
|
|
|
|
* @return string|null Module identifier or null
|
|
|
|
|
*/
|
2026-02-13 21:07:59 +00:00
|
|
|
public function getModule(): ?string
|
|
|
|
|
{
|
|
|
|
|
return $this->module;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-14 04:04:38 +00:00
|
|
|
/**
|
|
|
|
|
* Gets route attributes for parameter extraction.
|
|
|
|
|
*
|
|
|
|
|
* @return array Route attributes
|
|
|
|
|
*/
|
2026-02-13 21:07:59 +00:00
|
|
|
public function getAttributes(): array
|
|
|
|
|
{
|
|
|
|
|
return $this->attributes;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-14 04:04:38 +00:00
|
|
|
/**
|
|
|
|
|
* Converts the route definition to an array.
|
|
|
|
|
*
|
|
|
|
|
* @return array Plain array representation
|
|
|
|
|
*/
|
2026-02-13 21:07:59 +00:00
|
|
|
public function toArray(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'method' => $this->method,
|
|
|
|
|
'pattern' => $this->pattern,
|
|
|
|
|
'path' => $this->path,
|
|
|
|
|
'handler' => $this->handler,
|
|
|
|
|
'name' => $this->name,
|
|
|
|
|
'middleware' => $this->middleware,
|
|
|
|
|
'validation' => $this->validation,
|
|
|
|
|
'defaults' => $this->defaults,
|
|
|
|
|
'module' => $this->module,
|
|
|
|
|
'attributes' => $this->attributes
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|