PHP Класс 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.
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$c
$m (c)ondition
$p (s)tatic children
$s (m)ethods

Открытые методы

Метод Описание
__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 )

Приватные методы

Метод Описание
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.

Описание методов

__set_state() публичный статический Метод

public static __set_state ( $array )

addRoute() публичный Метод

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

filterPath() публичный статический Метод

public static filterPath ( $input )

findRouteFor() публичный Метод

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
Результат RoutingResult

getMethods() публичный Метод

public getMethods ( )

getParametricPaths() публичный Метод

public getParametricPaths ( )

getStaticPaths() публичный Метод

public getStaticPaths ( )

matches() публичный Метод

public matches ( $path )

Описание свойств

$c защищенное свойство

protected $c

$m защищенное свойство

(c)ondition
protected $m

$p защищенное свойство

(s)tatic children
protected $p

$s защищенное свойство

(m)ethods
protected $s