File src/class/Http/Route.php

class Lia\Http\Route

A value-object for holding route information, with some convenience methods.

Some behavior is documented in this class, but it's really all up to the calling code.

Constants

Properties

  • public Router $router = null; The router that returned this route.

  • public array $paramaters; Paramaters extracted from the url, based upon the route.

  • public string $url; Requested URL Path

  • public string $method; Request method, like "GET" or "POST"

  • public string $originalPattern; Original route pattern, like /blog/{slug}/

  • public string $regexPattern; Full Regex used to check if the request url is valid, AFTER the testPattern has reduced the number of possibilities.

  • public string $testPattern; A simplified pattern for the route-selection algorithm. After this filter-step, $regexPattern filters to the final set of pattern matches.

  • public array $allowedMethods; Array of methods that are valid for this route. Such as GET, PUT, POST, DELETE, etc

  • public mixed $target; Callable or absolute file path.
    The calling code is responsible for passing args.

  • public array $args; Array of arguments to pass to $target
    The calling code is responsible for passing args.

Methods

  • public function __construct() All desired properties must be set explicitly one-by-one.

  • public function part(int $index): string Get a portion of the url.

  • public function param(string $name): string Get a named url paramater.

  • public function var(int $index): string Get a named url paramater by zero-based index (instead of by name)

  • public function type(): string Check if target is callable, a file, or null

  • public function isCallable(): bool Check if target is callable

  • public function isFile(): bool Check if target is a file

  • public function isExecutableFile(): bool Check if target is an executable file.

  • public function fileExt(): string Get file extension, if target is a file. null otherwise.

  • public function isStatic(): bool Check if the route's originalPattern is static.

  • public function isDynamic(): bool Check if the route's originalPattern contains named parmaters.