Skip to content

Internals Router Matching SegmentPathMatcher

Stefan Crkvenjakov edited this page Oct 7, 2026 · 1 revision

router\matching\SegmentPathMatcher

Framework Internals · Subsystem overview · Developer guide

Source: awt_src/classes/router/matching/SegmentPathMatcher.php · Snapshot 8411f4287706.

Routing separates definition, HTTP request snapshot, matching, method policy, execution and error responses. Collaborators can be replaced through constructor injection.

Imports and dependencies

use router\interface\IPathMatcher;

SegmentPathMatcher

Declaration and architectural role

final class SegmentPathMatcher implements IPathMatcher

Constants, enum cases, traits and properties

No own constants, enum cases, traits or property declarations. Inherited members are documented on the parent reference page.

Method index

Method Signature
match public function match(string $pattern, string $path): ?array

match

Source line 9

public function match(string $pattern, string $path): ?array

Parameters

Parameter Type, modifiers and default Purpose
$pattern string $pattern Operation input; the exact use, validation and propagation are shown in the implementation trace.
$path string $path Filesystem or route path as defined by the owning component; no universal path normalization is implied.

Return expressions (including local callbacks): null; $params.

Implementation, validation guards and interaction order
public function match(string $pattern, string $path): ?array
    {
        $segments = explode('/', $pattern);
        $requested = explode('/', $path);
        if (count($segments) !== count($requested)) {
            return null;
        }

        $params = [];
        foreach ($segments as $index => $segment) {
            if (str_starts_with($segment, '{') && str_ends_with($segment, '}')) {
                $params[trim($segment, '{}')] = $requested[$index];
            } elseif ($segment !== $requested[$index]) {
                return null;
            }
        }
        return $params;
    }

Related types

Clone this wiki locally