ICanBoogie/Routing v2.4.0
  • Namespace
  • Class

Namespaces

  • ICanBoogie
    • Routing
      • Controller
      • Dispatcher
      • Route

Classes

  • ActionController
  • Controller
  • Dispatcher
  • FormattedRoute
  • Helpers
  • Pattern
  • Route
  • Routes

Interfaces

  • Exception
  • ToSlug

Exceptions

  • ActionNotDefined
  • ControllerNotDefined
  • PatternNotDefined
  • PatternRequiresValues
  • RouteNotDefined

Functions

  • absolutize_url
  • contextualize
  • decontextualize

Class Pattern

Representation of a route pattern.

<?php

use ICanBoogie\Routing\Pattern;

$pattern = Pattern::from("/blog/<year:\d{4}>-<month:\d{2}>-:slug.html");
echo $pattern;       // "/blog/<year:\d{4}>-<month:\d{2}>-:slug.html"

$pathname = $pattern->format([ 'year' => "2013", 'month' => "07", 'slug' => "test-is-a-test" ]);
echo $pathname;      // "/blog/2013-07-this-is-a-test.html"

$matching = $pattern->match($pathname, $captured);

var_dump($matching); // true
var_dump($captured); // [ 'year' => "2013", 'month' => "07", 'slug' => "test-is-a-test" ]
ICanBoogie\Routing\Pattern uses ICanBoogie\Accessor\AccessorTrait (not available)
Namespace: ICanBoogie\Routing
Located at Pattern.php

Methods summary

protected static
# read_value_from_array( $container, $key )
protected static
# read_value_from_object( $container, $key )
public static boolean
# is_pattern( string $pattern )

Checks if the given string is a route pattern.

Checks if the given string is a route pattern.

Parameters

$pattern

Returns

boolean
true if the given pattern is a route pattern, false otherwise.
public static ICanBoogie\Routing\Pattern
# from( mixed $pattern )

Creates a ICanBoogie\Routing\Pattern instance from the specified pattern.

Creates a ICanBoogie\Routing\Pattern instance from the specified pattern.

Parameters

$pattern

Returns

ICanBoogie\Routing\Pattern
protected
# get_pattern( )
protected
# get_interleaved( )
protected
# get_params( )
protected
# get_regex( )
protected
# __construct( string $pattern )

Initializes the $pattern, $interleaved, $params and $regex properties.

Initializes the $pattern, $interleaved, $params and $regex properties.

Parameters

$pattern
A route pattern.
public string
# __toString( )

Returns the route pattern specified during construct.

Returns the route pattern specified during construct.

Returns

string
public string
# format( array|object $values = null )

Formats a pattern with the specified values.

Formats a pattern with the specified values.

Parameters

$values

The values to format the pattern, either as an array or an object. If value is an instance of ICanBoogie\Routing\ToSlug the to_slug() method is used to transform the instance into a URL component.

Returns

string

Throws

ICanBoogie\Routing\PatternRequiresValues

in attempt to format a pattern requiring values without providing any.

public boolean
# match( string $pathname, array & $captured = null )

Checks if a pathname matches the pattern.

Checks if a pathname matches the pattern.

Parameters

$pathname
The pathname.
$captured
The parameters captured from the pathname.

Returns

boolean
true if the pathname matches the pattern, false otherwise.

Properties summary

Magic properties

public read-only string $pattern

The pattern.

public read-only array $interleaved

The interleaved parts of the pattern.

public read-only array $params

The names of the pattern params.

public read-only string $regex

The regex of the pattern.

ICanBoogie/Routing v2.4.0 API documentation generated by ApiGen