PRADO Component Framework for PHP 5
  • Home
  • About
  • Testimonials
  • Demos
  • Download
  • Documentation
  • Forum
  • Development
  • Tutorials
  • Class Docs
  • API Manual
  • Wiki

Packages

  • None
  • System
    • Caching
    • Collections
    • Data
      • ActiveRecord
        • Relations
        • Scaffold
          • InputBuilder
      • Commom
        • Sqlite
      • Common
        • Mssql
        • Mysql
        • Oracle
        • Pgsql
        • Sqlite
      • DataGateway
      • SqlMap
        • Configuration
        • Statements
    • Exceptions
    • I18N
    • IO
    • Security
    • Util
    • Web
      • Javascripts
      • Services
      • UI
        • ActiveControls
        • WebControls
    • Xml
  • Wsat
    • pages
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo

Class TUrlMappingPattern

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 setPattern Pattern property. setPattern 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 getParameters Parameters attribute collection. For example

<url ... pattern="articles/{year}/{month}/{day}"
         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 Parameters attribute name and values are used as substrings in replacing the placeholders in the Pattern string to form a complete regular expression string.

For more complicated patterns, one may specify the pattern using a regular expression by setRegularExpression RegularExpression. For example, the above pattern is equivalent to the following regular expression-based pattern:

#^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. If you intended to use the RegularExpression property or regular expressions in CDATA sections, notice that you need to escape the slash, if you are using the slash as regular expressions delimiter.

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

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

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

Since 3.1.4 you can also use simplyfied wildcard patterns to match multiple ServiceParameters with a single rule. The pattern must contain the placeholder {*} for the ServiceParameter. For example

<url ServiceParameter="adminpages.*" pattern="admin/{*}" />

This rule will match an URL like http://example.com/index.php/admin/edituser and resolve it to the page Application.pages.admin.edituser. The wildcard matching is non-recursive. That means you have to add a rule for every subdirectory you want to access pages in:

<url ServiceParameter="adminpages.users.*" pattern="useradmin/{*}" />

It is still possible to define an explicit rule for a page in the wildcard path. This rule has to preceed the wildcard rule.

You can also use parameters with wildcard patterns. The parameters are then available with every matching page:

<url ServiceParameter="adminpages.*" pattern="admin/{*}/{id}" parameters.id="\d+" />

To enable automatic parameter encoding in a path format from wildcard patterns you can set {@setUrlFormat UrlFormat} to 'Path':

<url ServiceParameter="adminpages.*" pattern="admin/{*}" UrlFormat="Path" />

This will create and parse URLs of the form .../index.php/admin/listuser/param1/value1/param2/value2.

Use {@setUrlParamSeparator} to define another separator character between parameter name and value. Parameter/value pairs are always separated by a '/'.

<url ServiceParameter="adminpages.*" pattern="admin/{*}" UrlFormat="Path" UrlParamSeparator="-" />

.../index.php/admin/listuser/param1-value1/param2-value2.

Since 3.2.2 you can also add a list of "constants" parameters that can be used just like the original "parameters" parameters, except that the supplied value will be treated as a simple string constant instead of a regular expression. For example

<url ServiceParameter="MyPage" pattern="/mypage/mypath/list/detail/{pageidx}" parameters.pageidx="\d+" constants.listtype="detailed"/> <url ServiceParameter="MyPage" pattern="/mypage/mypath/list/summary/{pageidx}" parameters.pageidx="\d+" constants.listtype="summarized"/>

These rules, when matched by the actual request, will make the application see a "lisstype" parameter present (even through not supplied in the request) and equal to "detailed" or "summarized", depending on the friendly url matched. The constants is practically a table-based validation and translation of specified, fixed-set parameter values.

TComponent
Extended by TUrlMappingPattern
Package: System\Web
Copyright: Copyright © 2005-2014 PradoSoft
License: http://www.pradosoft.com/license/
Author: Wei Zhuo <weizhuo[at]gmail[dot]com>
Since: 3.0.5
Located at Web/TUrlMapping.php
Methods summary
public
# __construct( TUrlManager $manager )

Constructor.

Constructor.

Parameters

$manager
TUrlManager
the URL manager instance

Overrides

TComponent::__construct()
public TUrlManager
# getManager( )

Returns

TUrlManager
the URL manager instance
public
# init( TXmlElement $config )

Initializes the pattern.

Initializes the pattern.

Parameters

$config
TXmlElement
configuration for this module.

Throws

TConfigurationException
if service parameter is not specified
protected string
# getParameterizedPattern( )

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

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

Returns

string
regular expression pattern with parameter subsitution
public string
# getRegularExpression( )

Returns

string
full regular expression mapping pattern
public
# setRegularExpression( string $value )

Parameters

$value
string
full regular expression mapping pattern.
public boolean
# getCaseSensitive( )

Returns

boolean
whether the getPattern Pattern should be treated as case sensititve. Defaults to true.
public
# setCaseSensitive( boolean $value )

Parameters

$value
boolean
whether the getPattern Pattern should be treated as case sensititve.
public
# setServiceParameter( string $value )

Parameters

$value
string
service parameter, such as page class name.
public string
# getServiceParameter( )

Returns

string
service parameter, such as page class name.
public
# setServiceID( string $value )

Parameters

$value
string
service id to handle.
public string
# getServiceID( )

Returns

string
service id.
public string
# getPattern( )

Returns

string
url pattern to match. Defaults to ''.
public
# setPattern( string $value )

Parameters

$value
string
url pattern to match.
public TAttributeCollection
# getParameters( )

Returns

TAttributeCollection
parameter key value pairs.
public
# setParameters( TAttributeCollection $value )

Parameters

$value
TAttributeCollection
new parameter key value pairs.
public TAttributeCollection
# getConstants( )

Returns

TAttributeCollection
constanst parameter key value pairs.

Since

3.2.2
public array
# getPatternMatches( THttpRequest $request )

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

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

Parameters

$request
THttpRequest
the request module

Returns

array
matched parameters, empty if no matches.
public boolean
# getEnableCustomUrl( )

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

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

Returns

boolean
whether to enable custom constructUrl. Defaults to true.

Since

3.1.1
public
# setEnableCustomUrl( boolean $value )

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

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

Parameters

$value
boolean
whether to enable custom constructUrl.
public boolean
# getIsWildCardPattern( )

Returns

boolean
whether this pattern is a wildcard pattern

Since

3.1.4
public THttpRequestUrlFormat
# getUrlFormat( )

Returns

THttpRequestUrlFormat
the format of URLs. Defaults to THttpRequestUrlFormat::Get.
public
# setUrlFormat( THttpRequestUrlFormat $value )

Sets the format of URLs constructed and interpreted by this pattern. A Get URL format is like index.php?name1=value1&name2=value2 while a Path URL format is like index.php/name1/value1/name2/value. The separating character between name and value can be configured with TUrlMappingPattern::setUrlParamSeparator() and defaults to '/'. Changing the UrlFormat will affect TUrlMappingPattern::constructUrl() and how GET variables are parsed.

Sets the format of URLs constructed and interpreted by this pattern. A Get URL format is like index.php?name1=value1&name2=value2 while a Path URL format is like index.php/name1/value1/name2/value. The separating character between name and value can be configured with TUrlMappingPattern::setUrlParamSeparator() and defaults to '/'. Changing the UrlFormat will affect TUrlMappingPattern::constructUrl() and how GET variables are parsed.

Parameters

$value
THttpRequestUrlFormat
the format of URLs.

Since

3.1.4
public string
# getUrlParamSeparator( )

Returns

string
separator used to separate GET variable name and value when URL format is Path. Defaults to slash '/'.
public
# setUrlParamSeparator( string $value )

Parameters

$value
string
separator used to separate GET variable name and value when URL format is Path.

Throws

TInvalidDataValueException
if the separator is not a single character
public TUrlMappingPatternSecureConnection
# getSecureConnection( )

Returns

TUrlMappingPatternSecureConnection
the SecureConnection behavior. Defaults to TUrlMappingPatternSecureConnection::Automatic Automatic

Since

3.2
public
# setSecureConnection( TUrlMappingPatternSecureConnection $value )

Parameters

$value
TUrlMappingPatternSecureConnection
the SecureConnection behavior.

Since

3.2
public boolean
# supportCustomUrl( array $getItems )

Parameters

$getItems
array
list of GET items to be put in the constructed URL

Returns

boolean
whether this pattern IS the one for constructing the URL with the specified GET items.

Since

3.1.1
public string
# constructUrl( array $getItems, boolean $encodeAmpersand, boolean $encodeGetItems )

Constructs a URL using this pattern.

Constructs a URL using this pattern.

Parameters

$getItems
array
list of GET variables
$encodeAmpersand
boolean
whether the ampersand should be encoded in the constructed URL
$encodeGetItems
boolean
whether the GET variables should be encoded in the constructed URL

Returns

string
the constructed URL

Since

3.1.1
protected string
# applySecureConnectionPrefix( string $url )

Apply behavior of SecureConnection property by conditionaly prefixing URL with THttpRequest::getBaseUrl()

Apply behavior of SecureConnection property by conditionaly prefixing URL with THttpRequest::getBaseUrl()

Parameters

$url
string
$url

Returns

string

Since

3.2
Methods inherited from TComponent
__call(), __destruct(), __get(), __isset(), __set(), __sleep(), __unset(), __wakeup(), addParsedObject(), asa(), attachBehavior(), attachBehaviors(), attachClassBehavior(), attachEventHandler(), canGetProperty(), canSetProperty(), clearBehaviors(), createdOnTemplate(), detachBehavior(), detachBehaviors(), detachClassBehavior(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), evaluateStatements(), fxAttachClassBehavior(), fxDetachClassBehavior(), getAutoGlobalListen(), getBehaviorsEnabled(), getClassHierarchy(), getEventHandlers(), getListeningToGlobalEvents(), getSubProperty(), hasEvent(), hasEventHandler(), hasProperty(), isa(), listen(), raiseEvent(), setSubProperty(), unlisten()
Constants inherited from TComponent
GLOBAL_RAISE_EVENT_LISTENER
Properties summary
protected TAttributeCollection $_constants
#

of constant parameters.

of constant parameters.

Terms of Service | Contact Us
PRADO v3.2.4 API Manual API documentation generated by ApiGen 2.8.0
Copyright © 2006-2014 by the PRADO Group.
Powered by PRADO