class RouteCompiler extends RouteCompiler implements RouteCompilerInterface (View source)

Compiler to generate derived information from a Route necessary for matching.

Methods

static CompiledRoute
compile(Route $route)

Compiles the current route instance.

static string
getPatternOutline(string $path)

Returns the pattern outline.

static int
getFit(string $path)

Determines the fitness of the provided path.

static string
getPathWithoutDefaults(Route $route)

Returns the path of the route, without placeholders with a default value.

Details

static CompiledRoute compile(Route $route)

Compiles the current route instance.

Because so much of the parent class is private, we need to call the parent class's compile() method and then dissect its return value to build our new compiled object. If upstream gets refactored so we can subclass more easily then this may not be necessary.

Parameters

Route $route

A Route instance.

Return Value

CompiledRoute

A CompiledRoute instance.

static string getPatternOutline(string $path)

Returns the pattern outline.

The pattern outline is the path pattern but normalized so that all placeholders are the string '%'.

Parameters

string $path

The path for which we want the normalized outline.

Return Value

string

The path pattern outline.

static int getFit(string $path)

Determines the fitness of the provided path.

Parameters

string $path

The path whose fitness we want.

Return Value

int

The fitness of the path, as an integer.

static string getPathWithoutDefaults(Route $route)

Returns the path of the route, without placeholders with a default value.

When computing the path outline and fit, we want to skip default-value placeholders. If we didn't, the path would never match. Note that this only works for placeholders at the end of the path. Infix placeholders with default values don't make sense anyway, so that should not be a problem.

Parameters

Route $route

The route to have the placeholders removed from.

Return Value

string

The path string, stripped of placeholders that have default values.