From 0f332e6564ed67ef7eb4d715ce3bcb5ff54c50cf Mon Sep 17 00:00:00 2001 From: Ciro Mattia Gonano Date: Wed, 24 Jul 2013 12:22:49 +0200 Subject: Upgrade to newly released 3.2.2 --- framework/Web/TUrlMapping.php | 111 +++++++++++++++++++++++++++++++++++------- 1 file changed, 93 insertions(+), 18 deletions(-) (limited to 'framework/Web/TUrlMapping.php') 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 © 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 - * @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 * * * - * 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': * * @@ -465,8 +476,19 @@ class TUrlMapping extends TUrlManager * * .../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 + * + * + * + * + * 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 - * @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,9 +507,13 @@ 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. */ @@ -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; } @@ -671,6 +704,20 @@ class TUrlMappingPattern extends TComponent $this->_parameters=$value; } + /** + * @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. @@ -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 - * @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 */ -- cgit v1.2.3