summaryrefslogtreecommitdiff
path: root/framework/Web/TUrlMapping.php
diff options
context:
space:
mode:
authorCiro Mattia Gonano <ciromattia@gmail.com>2013-07-24 12:22:49 +0200
committerCiro Mattia Gonano <ciromattia@gmail.com>2013-07-24 12:22:49 +0200
commit0f332e6564ed67ef7eb4d715ce3bcb5ff54c50cf (patch)
tree00cecb80224872c25e712a59b417c5f1dff240cb /framework/Web/TUrlMapping.php
parent3c208455c7775838e795909923536a7de13d9c5c (diff)
Upgrade to newly released 3.2.23.2.2
Diffstat (limited to 'framework/Web/TUrlMapping.php')
-rw-r--r--framework/Web/TUrlMapping.php111
1 files changed, 93 insertions, 18 deletions
diff --git a/framework/Web/TUrlMapping.php b/framework/Web/TUrlMapping.php
index ecbe5935..abfa02fd 100644
--- a/framework/Web/TUrlMapping.php
+++ b/framework/Web/TUrlMapping.php
@@ -6,7 +6,7 @@
* @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2013 PradoSoft
* @license http://www.pradosoft.com/license/
- * @version $Id: TUrlMapping.php 3245 2013-01-07 20:23:32Z ctrlaltca $
+ * @version $Id: TUrlMapping.php 3290 2013-05-06 08:32:15Z ctrlaltca $
* @package System.Web
*/
@@ -63,7 +63,7 @@ Prado::using('System.Collections.TAttributeCollection');
* in the GET variables.
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id: TUrlMapping.php 3245 2013-01-07 20:23:32Z ctrlaltca $
+ * @version $Id: TUrlMapping.php 3290 2013-05-06 08:32:15Z ctrlaltca $
* @package System.Web
* @since 3.0.5
*/
@@ -109,7 +109,15 @@ class TUrlMapping extends TUrlManager
$this->loadConfigFile();
$this->loadUrlMappings($config);
if($this->_urlPrefix==='')
- $this->_urlPrefix=$this->getRequest()->getApplicationUrl();
+ {
+ $request=$this->getRequest();
+ if($request->getUrlFormat()===THttpRequestUrlFormat::HiddenPath)
+ {
+ $this->_urlPrefix=dirname($request->getApplicationUrl());
+ } else {
+ $this->_urlPrefix=$request->getApplicationUrl();
+ }
+ }
$this->_urlPrefix=rtrim($this->_urlPrefix,'/');
}
@@ -331,6 +339,9 @@ class TUrlMapping extends TUrlManager
* If {@link THttpRequest::setUrlFormat THttpRequest.UrlFormat} is 'Path',
* the following format is used instead:
* /entryscript.php/serviceID/serviceParameter/get1,value1/get2,value2...
+ * If {@link THttpRequest::setUrlFormat THttpRequest.UrlFormat} is 'HiddenPath',
+ * the following format is used instead:
+ * /serviceID/serviceParameter/get1,value1/get2,value2...
* @param string service ID
* @param string service parameter
* @param array GET parameters, null if not provided
@@ -450,7 +461,7 @@ class TUrlMapping extends TUrlManager
*
* <url ServiceParameter="adminpages.*" pattern="admin/{*}/{id}" parameters.id="\d+" />
*
- * To enable automatic parameter encoding in a path format fro wildcard patterns you can set
+ * 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" />
@@ -465,8 +476,19 @@ class TUrlMapping extends TUrlManager
*
* <tt>.../index.php/admin/listuser/param1-value1/param2-value2</tt>.
*
+ * 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.
+ *
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id: TUrlMapping.php 3245 2013-01-07 20:23:32Z ctrlaltca $
+ * @version $Id: TUrlMapping.php 3290 2013-05-06 08:32:15Z ctrlaltca $
* @package System.Web
* @since 3.0.5
*/
@@ -485,10 +507,14 @@ class TUrlMappingPattern extends TComponent
*/
private $_pattern;
/**
- * @var TMap parameter regular expressions.
+ * @var TAttributeCollection parameter regular expressions.
*/
private $_parameters;
/**
+ * @var TAttributeCollection of constant parameters.
+ */
+ protected $_constants;
+ /**
* @var string regular expression pattern.
*/
private $_regexp='';
@@ -518,8 +544,6 @@ class TUrlMappingPattern extends TComponent
public function __construct(TUrlManager $manager)
{
$this->_manager=$manager;
- $this->_parameters=new TAttributeCollection;
- $this->_parameters->setCaseSensitive(true);
}
/**
@@ -552,12 +576,16 @@ class TUrlMappingPattern extends TComponent
{
$params=array();
$values=array();
- foreach($this->_parameters as $key=>$value)
+ if ($this->_parameters)
{
- $params[]='{'.$key.'}';
- $values[]='(?P<'.$key.'>'.$value.')';
+ foreach($this->_parameters as $key=>$value)
+ {
+ $params[]='{'.$key.'}';
+ $values[]='(?P<'.$key.'>'.$value.')';
+ }
}
- if ($this->getIsWildCardPattern()) {
+ if ($this->getIsWildCardPattern())
+ {
$params[]='{*}';
// service parameter must not contain '=' and '/'
$values[]='(?P<'.$this->getServiceID().'>[^=/]+)';
@@ -660,6 +688,11 @@ class TUrlMappingPattern extends TComponent
*/
public function getParameters()
{
+ if (!$this->_parameters)
+ {
+ $this->_parameters=new TAttributeCollection;
+ $this->_parameters->setCaseSensitive(true);
+ }
return $this->_parameters;
}
@@ -672,6 +705,20 @@ class TUrlMappingPattern extends TComponent
}
/**
+ * @return TAttributeCollection constanst parameter key value pairs.
+ * @since 3.2.2
+ */
+ public function getConstants()
+ {
+ if (!$this->_constants)
+ {
+ $this->_constants = new TAttributeCollection;
+ $this->_constants->setCaseSensitive(true);
+ }
+ return $this->_constants;
+ }
+
+ /**
* Uses URL pattern (or full regular expression if available) to
* match the given url path.
* @param THttpRequest the request module
@@ -708,6 +755,12 @@ class TUrlMappingPattern extends TComponent
unset($matches['urlparams']);
}
+ if(count($matches) > 0 && $this->_constants)
+ {
+ foreach($this->_constants->toArray() as $key=>$value)
+ $matches[$key] = $value;
+ }
+
return $matches;
}
@@ -755,7 +808,7 @@ class TUrlMappingPattern extends TComponent
* Changing the UrlFormat will affect {@link constructUrl} and how GET variables
* are parsed.
* @param THttpRequestUrlFormat the format of URLs.
- * @param since 3.1.4
+ * @since 3.1.4
*/
public function setUrlFormat($value)
{
@@ -809,10 +862,24 @@ class TUrlMappingPattern extends TComponent
{
if(!$this->_customUrl || $this->getPattern()===null)
return false;
- foreach($this->_parameters as $key=>$value)
+ if ($this->_parameters)
+ {
+ foreach($this->_parameters as $key=>$value)
+ {
+ if(!isset($getItems[$key]))
+ return false;
+ }
+ }
+
+ if ($this->_constants)
{
- if(!isset($getItems[$key]))
- return false;
+ foreach($this->_constants->toArray() as $key=>$value)
+ {
+ if (!isset($getItems[$key]))
+ return false;
+ if ($getItems[$key]!=$value)
+ return false;
+ }
}
return true;
}
@@ -827,12 +894,20 @@ class TUrlMappingPattern extends TComponent
*/
public function constructUrl($getItems,$encodeAmpersand,$encodeGetItems)
{
+ if ($this->_constants)
+ {
+ foreach($this->_constants->toArray() as $key=>$value)
+ {
+ unset($getItems[$key]);
+ }
+ }
+
$extra=array();
$replace=array();
// for the GET variables matching the pattern, put them in the URL path
foreach($getItems as $key=>$value)
{
- if($this->_parameters->contains($key) || $key==='*' && $this->getIsWildCardPattern())
+ if(($this->_parameters && $this->_parameters->contains($key)) || ($key==='*' && $this->getIsWildCardPattern()))
$replace['{'.$key.'}']=$encodeGetItems ? rawurlencode($value) : $value;
else
$extra[$key]=$value;
@@ -930,7 +1005,7 @@ class TUrlMappingPattern extends TComponent
* URL prefix behavior that can be used by {@link TUrlMappingPattern::constructUrl()}.
*
* @author Yves Berkholz <godzilla80[at]gmx[dot]net>
- * @version $Id: TUrlMapping.php 3245 2013-01-07 20:23:32Z ctrlaltca $
+ * @version $Id: TUrlMapping.php 3290 2013-05-06 08:32:15Z ctrlaltca $
* @package System.Web
* @since 3.2
*/