Class TUrlMappingPattern

Description

TUrlMappingPattern class.

TUrlMappingPattern represents a pattern used to parse and construct URLs. If the currently requested URL matches the pattern, it will alter the THttpRequest parameters. If a constructUrl() call matches the pattern parameters, the pattern will generate a valid URL. In both case, only the PATH_INFO part of a URL is parsed/constructed using the pattern.

To specify the pattern, set the Pattern property. Pattern takes a string expression with parameter names enclosed between a left brace '{' and a right brace '}'. The patterns 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.

For more complicated patterns, one may specify the pattern using a regular expression by RegularExpression. For example, the above pattern is equivalent to the following regular expression-based 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.

Thus, only an url that matches the pattern will be valid. For example, a URL <tt>http://example.com/index.php/articles/2006/07/21</tt> will match the above pattern, while <tt>http://example.com/index.php/articles/2006/07/hello</tt> will not since the "day" parameter pattern is not satisfied.

The parameter values are available through the <tt>THttpRequest</tt> instance (e.g. <tt>$this->Request['year']</tt>).

The ServiceParameter and ServiceID (the default ID is 'page') set the service parameter and service id respectively.

  • since: 3.0.5
  • version: $Id: TUrlMapping.php 2121 2007-08-11 23:37:28Z xue $
  • author: Wei Zhuo <weizhuo[at]gmail[dot]com>

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

TComponent
   |
   --TUrlMappingPattern
Method Summary
TUrlMappingPattern __construct (TUrlManager $manager)
string constructUrl (array $getItems, boolean $encodeAmpersand, boolean $encodeGetItems)
boolean getCaseSensitive ()
boolean getEnableCustomUrl ()
string getPattern ()
array getPatternMatches (THttpRequest $request)
string getServiceID ()
void init (TXmlElement $config)
void setCaseSensitive (boolean $value)
void setEnableCustomUrl (boolean $value)
void setPattern (string $value)
void setRegularExpression (string $value)
void setServiceID (string $value)
void setServiceParameter (string $value)
boolean supportCustomUrl (array $getItems)
Methods
Constructor __construct (line 407)

Constructor.

  • access: public
TUrlMappingPattern __construct (TUrlManager $manager)
constructUrl (line 612)

Constructs a URL using this pattern.

  • return: the constructed URL
  • access: public
  • since: 3.1.1
string constructUrl (array $getItems, boolean $encodeAmpersand, boolean $encodeGetItems)
  • array $getItems: list of GET variables
  • boolean $encodeAmpersand: whether the ampersand should be encoded in the constructed URL
  • boolean $encodeGetItems: whether the GET variables should be encoded in the constructed URL
getCaseSensitive (line 475)
  • return: whether the Pattern should be treated as case sensititve. Defaults to true.
  • access: public
boolean getCaseSensitive ()
getEnableCustomUrl (line 573)

Returns a value indicating whether to use this pattern to construct URL.

  • return: whether to enable custom constructUrl. Defaults to true.
  • access: public
  • since: 3.1.1
boolean getEnableCustomUrl ()
getManager (line 417)
  • return: the URL manager instance
  • access: public
TUrlManager getManager ()
getParameterizedPattern (line 438)

Substitute 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 539)
  • return: parameter key value pairs.
  • access: public
TAttributeCollection getParameters ()
getPattern (line 523)
  • return: url pattern to match. Defaults to ''.
  • access: public
string getPattern ()
getPatternMatches (line 558)

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 (THttpRequest $request)
getRegularExpression (line 459)
  • return: full regular expression mapping pattern
  • access: public
string getRegularExpression ()
getServiceID (line 515)
  • return: service id.
  • access: public
string getServiceID ()
getServiceParameter (line 499)
  • return: service parameter, such as page class name.
  • access: public
string getServiceParameter ()
init (line 427)

Initializes the pattern.

  • access: public
  • throws: TConfigurationException if service parameter is not specified
void init (TXmlElement $config)
setCaseSensitive (line 483)
  • access: public
void setCaseSensitive (boolean $value)
  • boolean $value: whether the Pattern should be treated as case sensititve.
setEnableCustomUrl (line 582)

Sets a value indicating whether to enable custom constructUrl using this pattern

  • access: public
void setEnableCustomUrl (boolean $value)
  • boolean $value: whether to enable custom constructUrl.
setParameters (line 547)
  • access: public
void setParameters (TAttributeCollection $value)
setPattern (line 531)
  • access: public
void setPattern (string $value)
  • string $value: url pattern to match.
setRegularExpression (line 467)
  • access: public
void setRegularExpression (string $value)
  • string $value: full regular expression mapping pattern.
setServiceID (line 507)
  • access: public
void setServiceID (string $value)
  • string $value: service id to handle.
setServiceParameter (line 491)
  • access: public
void setServiceParameter (string $value)
  • string $value: service parameter, such as page class name.
supportCustomUrl (line 592)
  • return: whether this pattern IS the one for constructing the URL with the specified GET items.
  • access: public
  • since: 3.1.1
boolean supportCustomUrl (array $getItems)
  • array $getItems: list of GET items to be put in the constructed URL

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 Mon, 21 Apr 2008 11:36:40 -0400 by phpDocumentor 1.3.0RC4