Class TUrlMappingPattern

Description

URL Mapping Pattern Class

Describes an URL mapping pattern, if a given URL matches the pattern, the TUrlMapping class will alter the THttpRequest parameters. The url matching is done using patterns and regular expressions.

The Pattern property takes an string expression with parameter names enclosed between a left brace '{' and a right brace '}'. The pattens for each parameter can be set using Parameters attribute collection. For example

  1. <url ... pattern="articles/{year}/{month}/{day}"
  2. parameters.year="\d{4}" parameters.month="\d{2}" parameters.day="\d+" />

In the above example, the pattern contains 3 parameters named "year", "month" and "day". The pattern for these parameters are, respectively, "\d{4}" (4 digits), "\d{2}" (2 digits) and "\d+" (1 or more digits). Essentially, the <tt>Parameters</tt> attribute name and values are used as substrings in replacing the placeholders in the <tt>Pattern</tt> string to form a complete regular expression string. A full regular expression may be expressed using the <tt>RegularExpression</tt> attribute or as the body content of the &lt;module&gt; tag. The above pattern is equivalent to the following regular expression pattern.

  1. /articles/(?P<year>d{4})/(?P<month>d{2})/(?P<day>d+)/u
The above regular expression used the "named group" feature available in PHP. Notice that you need to escape the slash in regular expressions.

In the TUrlMappingPattern class, the pattern is matched against the path property of the url only.

Thus, only an url that matches the pattern will be valid. For example, an url "<tt>http://example.com/articles/2006/07/21</tt>" will matches and is valid. However, "<tt>http://example.com/articles/2006/07/hello</tt>" is not valid since the "day" parameter pattern is not satisfied.

The parameter values are available through the standard <tt>Request</tt> object. For example, <tt>$this->Request['year']</tt>.

The ServiceParameter and ServiceID (the default ID is 'page') set the service parameter and service id respectively. The service parameter for the TPageService is the Page class name, other service may use the service parameter differently.

For more complicated mappings, the body of the <tt>&lt;url&gt;</tt> can be used to specify the mapping pattern.

  • since: 3.0.5
  • version: $Id: TUrlMapping.php 1551 2006-12-03 23:16:40Z xue $
  • author: Wei Zhuo <weizhuo[at]gmail[dot]com>

Located in /Web/TUrlMapping.php (line 254)

TComponent
   |
   --TUrlMappingPattern
Method Summary
TUrlMappingPattern __construct ()
boolean getCaseSensitive ()
string getModifiers ()
string getPattern ()
array getPatternMatches (TUri $url)
string getServiceID ()
void init (TXmlElement $config)
void setCaseSensitive (boolean $value)
void setPattern (string $value)
void setRegularExpression (string $value)
void setServiceID (string $value)
void setServiceParameter (string $value)
Methods
Constructor __construct (line 281)
  • access: public
TUrlMappingPattern __construct ()
getCaseSensitive (line 399)
  • return: case sensitive pattern matching, default is true.
  • access: public
boolean getCaseSensitive ()
getModifiers (line 440)
  • return: regular expression matching modifiers.
  • access: protected
string getModifiers ()
getParameterizedPattern (line 308)

Subsitutue the parameter key value pairs as named groupings in the regular expression matching pattern.

  • return: regular expression pattern with parameter subsitution
  • access: protected
string getParameterizedPattern ()
getParameters (line 407)
  • return: parameter key value pairs.
  • access: public
TAttributeCollection getParameters ()
getPattern (line 375)
  • return: url pattern to match.
  • access: public
string getPattern ()
getPatternMatches (line 426)

Uses URL pattern (or full regular expression if available) to match the given url path.

  • return: matched parameters, empty if no matches.
  • access: public
array getPatternMatches (TUri $url)
  • TUri $url: url to match against
getRegularExpression (line 327)
  • return: full regular expression mapping pattern
  • access: public
string getRegularExpression ()
getServiceID (line 367)
  • return: service id.
  • access: public
string getServiceID ()
getServiceParameter (line 351)
  • return: service parameter, such as page class name.
  • access: public
string getServiceParameter ()
init (line 291)

Initialize the pattern, uses the body content as pattern is available.

  • access: public
  • throws: TConfigurationException if page class is not specified.
void init (TXmlElement $config)
setCaseSensitive (line 391)
  • access: public
void setCaseSensitive (boolean $value)
  • boolean $value: case sensitive pattern matching, default is true.
setParameters (line 415)
  • access: public
void setParameters (TAttributeCollection $value)
setPattern (line 383)
  • access: public
void setPattern (string $value)
  • string $value: url pattern to match.
setRegularExpression (line 335)
  • access: public
void setRegularExpression (string $value)
  • string $value: full regular expression mapping patern.
setServiceID (line 359)
  • access: public
void setServiceID (string $value)
  • string $value: service id to handle.
setServiceParameter (line 343)
  • access: public
void setServiceParameter (string $value)
  • string $value: service parameter, such as page class name.

Inherited Methods

Inherited From TComponent

TComponent::addParsedObject()
TComponent::attachEventHandler()
TComponent::canGetProperty()
TComponent::canSetProperty()
TComponent::createdOnTemplate()
TComponent::detachEventHandler()
TComponent::evaluateExpression()
TComponent::evaluateStatements()
TComponent::getEventHandlers()
TComponent::getSubProperty()
TComponent::hasEvent()
TComponent::hasEventHandler()
TComponent::hasProperty()
TComponent::raiseEvent()
TComponent::setSubProperty()
TComponent::__get()
TComponent::__set()

Documentation generated on Sun, 14 Jan 2007 21:44:56 -0500 by phpDocumentor 1.3.0RC4