44 $matcher->treesByLength = $data;
68 $partLength = strlen( $part );
69 return $partLength > 2 && $part[0] ===
'{' && $part[$partLength - 1] ===
'}';
80 if ( $this->
isParam( $part ) ) {
81 return substr( $part, 1, -1 );
107 if ( $index >= count( $parts ) ) {
111 $part = $parts[$index];
113 if ( $this->
isParam( $part ) ) {
114 foreach ( $node as $key => $childNode ) {
115 $result = $this->
findConflict( $childNode, $parts, $index + 1 );
116 if ( $result !==
false ) {
121 if ( isset( $node[
"=$part"] ) ) {
122 $result = $this->
findConflict( $node[
"=$part"], $parts, $index + 1 );
124 if ( $result ===
false && isset( $node[
'*'] ) ) {
125 $result = $this->
findConflict( $node[
'*'], $parts, $index + 1 );
149 public function add( $template, $userData ) {
150 $parts = explode(
'/', $template );
151 $length = count( $parts );
152 if ( !isset( $this->treesByLength[$length] ) ) {
153 $this->treesByLength[$length] = [];
155 $tree =& $this->treesByLength[$length];
157 if ( $conflict !==
false ) {
158 throw new PathConflict( $template, $userData, $conflict );
162 foreach ( $parts as $index => $part ) {
164 if ( $paramName !==
false ) {
165 $params[] = $paramName;
170 if ( $index === $length - 1 ) {
172 'template' => $template,
173 'paramNames' => $params,
174 'userData' => $userData
176 } elseif ( !isset( $tree[$key] ) ) {
179 $tree =& $tree[$key];
197 $parts = explode(
'/',
$path );
198 $length = count( $parts );
199 if ( !isset( $this->treesByLength[$length] ) ) {
202 $node = $this->treesByLength[$length];
205 foreach ( $parts as $part ) {
206 if ( isset( $node[
"=$part"] ) ) {
207 $node = $node[
"=$part"];
208 } elseif ( isset( $node[
'*'] ) ) {
210 $paramValues[] = $part;
217 'params' => array_combine( $node[
'paramNames'], $paramValues ),
218 'userData' => $node[
'userData']