Apache Zeta Components Manual :: File Source for regexp.php
Source for file regexp.php
Documentation is available at regexp.php
* File containing the ezcMvcRegexpRoute class
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @version //autogentag//
* Router class that uses regular expressions for matching routes.
* The routes are matched against the uri property of the request object.
* @version //autogentag//
* This property contains the regular expression.
* This is the name of the controller class that will be instantiated with the
* request variables obtained from the route, as well as the default values
* Contains the action that the controller should execute.
* The default values for the variables that are send to the controller. The route
* matchers can override those default values
* Constructs a new ezcMvcRegexpRoute with $pattern.
* When the route is matched (with the match() method), the route instantiates
* an object of the class $controllerClassName.
* @param string $controllerClassName
* @param array(string) $defaultValues
public function __construct( $pattern, $controllerClassName, $action =
null, array $defaultValues =
array() )
* Returns the request information that the matches() method will match the
* @param ezcMvcRequest $request
* Evaluates the URI against this route.
* The method first runs the match. If the regular expression matches, it
* cleans up the variables to only include named parameters. it then
* creates an object containing routing information and returns it. If the
* route's pattern did not match it returns null.
* @param ezcMvcRequest $request
* @return null|ezcMvcRoutingInformation
public function matches( ezcMvcRequest $request )
if ( $this->pregMatch( $request, $matches ) )
foreach ( $matches as $key =>
$match )
* This method performs the actual regular expresion match against the
* @param ezcMvcRequest $request
* @param array(string) $matches
protected function pregMatch( $request, &$matches )
* Parses the pattern and adds the prefix.
* It's up to the developer to provide a meaningfull prefix. In this case,
* it needs to be a regular expression just like the pattern.
* @throws ezcMvcRegexpRouteException if the prefix can not be prepended to
public function prefix( $prefix )
// Find pattern delimiter
$patternDelim =
$pattern[0];
// Obtain pattern modifiers
$patternModifier =
substr( strrchr( $pattern, $patternDelim ), 1 );
$prefixDelim =
$prefix[0];
// Obtain prefix modifiers
// If modifiers are not the same, throw exception
if ( $patternModifier !==
$prefixModifier )
// Reassemble the new pattern
$newPattern =
$patternDelim;
$newPattern .=
substr( $prefix, 1, -
1 -
strlen( $prefixModifier ) );
$newPattern .=
substr( $pattern, 1 +
( $pattern[1] ==
'^' ) );
* Generates an URL back out of a route, including possible arguments
* @param array $arguments
$url =
substr( $url, 1 );
$url =
substr( $url, 0, -
1 );
if ( substr( $url, 0, 1 ) ==
'^' )
$url =
substr( $url, 1 );
if ( substr( $url, -
1 ) ==
'$' )
$openPart =
$openPartName =
false;
$partName =
$partOffset =
$partLength =
false;
for( $i =
0; isset
( $url[$i] ); $i ++
)
elseif ( $url[$i] ==
')' )
if ( substr( $url, $i, 4 ) ==
'(?P<' )
$openPart =
$openPartName =
true;
if ( $url[$i] ==
')' &&
$openParenthesis ==
0 )
substr( $url, $partOffset, $partLength ),
$i =
$partOffset +
strlen( $arguments[$partName] );