[ Index ]
 

Code source de PRADO 3.0.6

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/framework/Web/ -> TUrlMapping.php (sommaire)

TUrlMapping and TUrlMappingPattern class file.

Author: Wei Zhuo
Copyright: Copyright © 2006 PradoSoft
License: http://www.pradosoft.com/license/
Version: $Id: TUrlMapping.php 1543 2006-12-03 13:00:54Z xue $
Poids: 449 lignes (13 kb)
Inclus ou requis:0 fois
Référencé: 0 fois
Nécessite: 0 fichiers

Définit 2 classes

TUrlMapping:: (8 méthodes):
  init()
  loadConfigFile()
  getConfigFile()
  setConfigFile()
  loadUrlMappings()
  parseUrl()
  getMatchingPattern()
  changeServiceParameters()

TUrlMappingPattern:: (17 méthodes):
  __construct()
  init()
  getParameterizedPattern()
  getRegularExpression()
  setRegularExpression()
  setServiceParameter()
  getServiceParameter()
  setServiceID()
  getServiceID()
  getPattern()
  setPattern()
  setCaseSensitive()
  getCaseSensitive()
  getParameters()
  setParameters()
  getPatternMatches()
  getModifiers()


Classe: TUrlMapping  - X-Ref

TUrlMapping Class

The TUrlMapping module allows aributary URL path to be mapped to a
particular service and page class. This module must be configured
before a service is initialized, thus this module should be configured
globally in the <tt>application.xml</tt> file and before any services.
<code>
<module id="friendly-url" class="System.Web.TUrlMapping">
<url ServiceParameter="Posts.ViewPost" pattern="post/{id}/?" parameters.id="\d+" />
<url ServiceParameter="Posts.ListPost" pattern="archive/{time}/?" parameters.time="\d{6}" />
<url ServiceParameter="Posts.ListPost" pattern="category/{cat}/?" parameters.cat="\d+" />
</module>
<module id="request" class="THttpRequest" UrlManager="friendly-url" />
</code>

See {@link TUrlMappingPattern} for details regarding the mapping patterns.
Similar to other modules, the <tt>&lt;url /&gt;</tt> configuration class
can be customised using the <tt>class</tt> property.

The URL mapping are evaluated in order, only the first mapping that matches
the URL will be used. Cascaded mapping can be achieved by placing the URL mappings
in particular order. For example, placing the most specific mappings first.

The mapping can be load from an external file by specifying a configuration
file using the {@link setConfigFile ConfigFile} property.

Since TUrlMapping is a URL manager extending from {@link TUrlManager},
you may override {@link TUrlManager::constructUrl} to support your pattern-based
URL scheme.

init($xml)   X-Ref
Initializes this module.
This method is required by the IModule interface.

param: TXmlElement configuration for this module, can be null

loadConfigFile()   X-Ref
Initialize the module from configuration file.


getConfigFile()   X-Ref

return: string external configuration file. Defaults to null.

setConfigFile($value)   X-Ref

param: string external configuration file in namespace format. The file

loadUrlMappings($xml)   X-Ref
Load and configure each url mapping pattern.

param: TXmlElement configuration node

parseUrl()   X-Ref
Parses the request URL and returns an array of input parameters.
This method overrides the parent implementation.
The input parameters do not include GET and POST variables.
This method uses the request URL path to find the first matching pattern. If found
the matched pattern parameters are used to return as the input parameters.

return: array list of input parameters

getMatchingPattern()   X-Ref

return: TUrlMappingPattern the matched pattern, null if not found.

changeServiceParameters($pattern)   X-Ref

param: TUrlMappingPattern change the Request service ID and page class.

Classe: TUrlMappingPattern  - X-Ref

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 {@link setPattern 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 {@link getParameters Parameters}
attribute collection. For example
<code>
<url ... pattern="articles/{year}/{month}/{day}"
parameters.year="\d{4}" parameters.month="\d{2}" parameters.day="\d+" />
</code>

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.
<code>
/articles\/(?P<year>\d{4})\/(?P<month>\d{2})\/(?P<day>\d+)/u
</code>
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
<b>path</b> 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 {@link setServiceParameter ServiceParameter} and {@link setServiceID 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.

__construct()   X-Ref


init($config)   X-Ref
Initialize the pattern, uses the body content as pattern is available.

param: TXmlElement configuration for this module.

getParameterizedPattern()   X-Ref
Subsitutue the parameter key value pairs as named groupings
in the regular expression matching pattern.

return: string regular expression pattern with parameter subsitution

getRegularExpression()   X-Ref

return: string full regular expression mapping pattern

setRegularExpression($value)   X-Ref

param: string full regular expression mapping patern.

setServiceParameter($value)   X-Ref

param: string service parameter, such as page class name.

getServiceParameter()   X-Ref

return: string service parameter, such as page class name.

setServiceID($value)   X-Ref

param: string service id to handle.

getServiceID()   X-Ref

return: string service id.

getPattern()   X-Ref

return: string url pattern to match.

setPattern($value)   X-Ref

param: string url pattern to match.

setCaseSensitive($value)   X-Ref

param: boolean case sensitive pattern matching, default is true.

getCaseSensitive()   X-Ref

return: boolean case sensitive pattern matching, default is true.

getParameters()   X-Ref

return: TAttributeCollection parameter key value pairs.

setParameters($value)   X-Ref

param: TAttributeCollection new parameter key value pairs.

getPatternMatches($url)   X-Ref
Uses URL pattern (or full regular expression if available) to
match the given url path.

param: TUri url to match against
return: array matched parameters, empty if no matches.

getModifiers()   X-Ref

return: string regular expression matching modifiers.



Généré le : Sun Feb 25 21:07:04 2007 par Balluche grâce à PHPXref 0.7