Rule object for routes

Public Properties

public string $staticUrl

staticUrl with static segments only, dynamic segments are stripped

public array $segments

segments for the pattern

public int $segmentCount

segmentCount is the number of segments in the pattern

public int $staticSegmentCount

staticSegmentCount the number of static segments found in the pattern

public int $dynamicSegmentCount

dynamicSegmentCount the number of dynamic segments found in the pattern

public int $wildSegmentCount

wildSegmentCount the number of wildcard segments found in the pattern

Protected Properties

protected array $config

config values for this instance

protected string $ruleName

ruleName is a named reference for this rule.

protected string $rulePattern

rulePattern used to match this rule.

protected function $conditionCallback

conditionCallback used when matching this rule.

protected function $afterMatchCallback

afterMatchCallback called when this rule is matched.

Public Methods

public __construct()

public __construct(string $name = []): void

__construct the new router rule instance.

public afterMatch()

public afterMatch(callback $callback = null): callback 

afterMatch callback

public condition()

public condition(callback $callback = null): callback 

condition callback

public static fromPattern()

public static fromPattern($name, $pattern): static 

fromPattern returns a named rule from a pattern

public name()

public name(string $name = null): object 

name is a unique route name

public pattern()

public pattern(string $pattern = null): self 

pattern for the route match

public resolveUrl()

public resolveUrl(string $url, array &$parameters): bool 

resolveUrl checks whether a given URL matches a given pattern, with a reference to a PHP array variable to return the parameter list fetched from URL. Returns true if the URL matches the pattern. Otherwise returns false.

public resolveUrlSegments()

public resolveUrlSegments(
    array $urlSegments,
    array &$parameters
): bool 

resolveUrlSegments is an internal method used for multiple checks.

public toArray()

public toArray(): void

Protected Methods

protected captureWildcardSegments()

protected captureWildcardSegments(array &$urlSegments): array 

captureWildcardSegments captures and removes every segment of a URL after a wildcard pattern segment is detected, until both collections of segments are the same size.