PHP Class RtNode, recess

pages/ -> matches /pages/ pages/$id -> matches /pages/1 ... (id => 1) pages/slug/$slug -> matches /pages/slug/some-slug-here (slug => some-slug-here) For the purposes of this class a URI path is broken into parts delimited with a '/'. There are two kinds of path parts: static and parametric. Static matches have precedence over parametric matches. For example, if you have the following routes: (1) /pages/$page_title/ (2) /pages/a-page/ (3) /pages/$page_title/$id A request of "/pages/a-page/" will match (2) and the result will not contain an argument. A request of "/pages/b-page/" will match (1) and the result will contain argument ("page_title" => "b_page") A request of "/pages/a-page/1" will match (3) with result arguments ("page_title" => "a_page", "id" => "1") Note: Because routing trees are serialized and unserialized frequently I am breaking the naming conventions and using short, one-letter member names.
Mostrar archivo Open project: KrisJordan/recess Class Usage Examples

Protected Properties

Property Type Description
$c
$m (c)ondition
$p (s)tatic children
$s (m)ethods

Public Methods

Method Description
__set_state ( $array )
addRoute ( $app, Route $route, $prefix ) Used to add a route to the routing tree.
filterPath ( $input )
findRouteFor ( Request $request ) : RoutingResult Traverses children recursively to find a matching route. First looks to see if a static (non-parametric, i.e. /this_is_static/ vs. /$this_is_dynamic/) match exists. If not, we match against dynamic children. We reverse and step backwards through the array because $index > 0 is less costly than $index < count($parts) in PHP.
getMethods ( )
getParametricPaths ( )
getStaticPaths ( )
matches ( $path )

Private Methods

Method Description
addRouteRecursively ( &$pathParts, $index, $route ) : FindRouteResult The recursive method powering addRouteFor(Request).
findRouteRecursively ( &$pathParts, $index, &$method ) : RoutingResult The recursive method powering findRouteFor(Request).
getRevesedPathParts ( $path ) Explodes a string by forward slashes, removes empty first/last node and finally reverses the array.

Method Details

__set_state() public static method

public static __set_state ( $array )

addRoute() public method

Used to add a route to the routing tree.
public addRoute ( $app, Route $route, $prefix )
$route Route

filterPath() public static method

public static filterPath ( $input )

findRouteFor() public method

Traverses children recursively to find a matching route. First looks to see if a static (non-parametric, i.e. /this_is_static/ vs. /$this_is_dynamic/) match exists. If not, we match against dynamic children. We reverse and step backwards through the array because $index > 0 is less costly than $index < count($parts) in PHP.
public findRouteFor ( Request $request ) : RoutingResult
$request Request
return RoutingResult

getMethods() public method

public getMethods ( )

getParametricPaths() public method

public getParametricPaths ( )

getStaticPaths() public method

public getStaticPaths ( )

matches() public method

public matches ( $path )

Property Details

$c protected_oe property

protected $c

$m protected_oe property

(c)ondition
protected $m

$p protected_oe property

(s)tatic children
protected $p

$s protected_oe property

(m)ethods
protected $s