Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions system/Router/Attributes/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class Filter implements RouteAttributeInterface
{
/**
* @param array<array-key, scalar> $having
*/
public function __construct(
public string $by,
public array $having = [],
Expand All @@ -56,6 +59,9 @@ public function after(RequestInterface $request, ResponseInterface $response): ?
return null;
}

/**
* @return list<string>
*/
public function getFilters(): array
{
if ($this->having === []) {
Expand Down
5 changes: 5 additions & 0 deletions system/Router/Attributes/Restrict.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class Restrict implements RouteAttributeInterface
{
/**
* @param list<string>|string|null $environment
* @param list<string>|string|null $hostname
* @param list<string>|string|null $subdomain
*/
public function __construct(
public array|string|null $environment = null,
public array|string|null $hostname = null,
Expand Down
17 changes: 5 additions & 12 deletions system/Router/AutoRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ public function __construct(
) {
}

/**
* Attempts to match a URI path against Controllers and directories
* found in APPPATH/Controllers, to find a matching route.
*
* @param string $httpVerb HTTP verb like `GET`,`POST`
*
* @return array [directory_name, controller_name, controller_method, params]
*/
public function getRoute(string $uri, string $httpVerb): array
{
$segments = explode('/', $uri);
Expand Down Expand Up @@ -95,7 +87,7 @@ public function getRoute(string $uri, string $httpVerb): array
throw PageNotFoundException::forPageNotFound();
}

/** @var array $params An array of params to the controller method. */
/** @var list<string> $params An array of params to the controller method. */
$params = [];

if ($segments !== []) {
Expand Down Expand Up @@ -177,11 +169,12 @@ public function setTranslateURIDashes(bool $val = false): self
}

/**
* Scans the controller directory, attempting to locate a controller matching the supplied uri $segments
* Scans the controller directory, attempting to locate a controller matching the supplied uri `$segments`.
* Returns an array of remaining uri segments that don't map onto a directory.
*
* @param array $segments URI segments
* @param list<string> $segments URI segments
*
* @return array returns an array of remaining uri segments that don't map onto a directory
* @return list<string>
*/
private function scanControllers(array $segments): array
{
Expand Down
19 changes: 7 additions & 12 deletions system/Router/AutoRouterImproved.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ final class AutoRouterImproved implements AutoRouterInterface
* Map of URI segments and namespaces.
*
* The key is the first URI segment. The value is the controller namespace.
* E.g.,
* [
* 'blog' => 'Acme\Blog\Controllers',
* ]
* ```
* ['blog' => 'Acme\Blog\Controllers']
* ```
*
* @var array [ uri_segment => namespace ]
* @var array<string, string>
*/
private array $moduleRoutes;

Expand Down Expand Up @@ -133,6 +132,9 @@ public function __construct(
$this->controller = $this->defaultController;
}

/**
* @return list<string>
*/
private function createSegments(string $uri): array
{
$segments = explode('/', $uri);
Expand Down Expand Up @@ -250,13 +252,6 @@ private function searchLastDefaultController(): bool
return false;
}

/**
* Finds controller, method and params from the URI.
*
* @param string $httpVerb HTTP verb like `GET`,`POST`
*
* @return array [directory_name, controller_name, controller_method, params]
*/
public function getRoute(string $uri, string $httpVerb): array
{
$this->uri = $uri;
Expand Down
6 changes: 4 additions & 2 deletions system/Router/AutoRouterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
interface AutoRouterInterface
{
/**
* Returns controller, method and params from the URI.
* Returns the directory name, controller name, controller method, and any parameters for the given URI and HTTP verb.
*
* @return array [directory_name, controller_name, controller_method, params]
* @param string $httpVerb HTTP verb like `GET`,`POST`
*
* @return array{string|null, string, string, list<string>}
*/
public function getRoute(string $uri, string $httpVerb): array;
}
Loading
Loading