From 22471c977d4edc4ddfe63abe23928d03e659f045 Mon Sep 17 00:00:00 2001 From: "GODZilla0480@gmail.com" <> Date: Mon, 17 Oct 2011 07:36:47 +0000 Subject: Port changes of r3050 (branches/3.1) to trunk --- framework/Web/TUrlMapping.php | 71 ++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 25 deletions(-) (limited to 'framework') diff --git a/framework/Web/TUrlMapping.php b/framework/Web/TUrlMapping.php index 69abc7a9..5338c119 100644 --- a/framework/Web/TUrlMapping.php +++ b/framework/Web/TUrlMapping.php @@ -120,7 +120,7 @@ class TUrlMapping extends TUrlManager protected function loadConfigFile() { if(is_file($this->_configFile)) - { + { if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) { $config = include $this->_configFile; @@ -227,6 +227,8 @@ class TUrlMapping extends TUrlManager */ protected function loadUrlMappings($config) { + $defaultClass = $this->getDefaultMappingClass(); + if(is_array($config)) { if(isset($config['urls']) && is_array($config['urls'])) @@ -235,7 +237,7 @@ class TUrlMapping extends TUrlManager { $class=null; if(!isset($url['class'])) - $class=$this->getDefaultMappingClass(); + $class=$defaultClass; $pattern=Prado::createComponent($class,$this); $properties = isset($url['properties'])?$url['properties']:array(); $this->buildUrlMapping($class,$pattern,$properties,$url); @@ -248,7 +250,7 @@ class TUrlMapping extends TUrlManager { $properties=$url->getAttributes(); if(($class=$properties->remove('class'))===null) - $class=$this->getDefaultMappingClass(); + $class=$defaultClass; $pattern=Prado::createComponent($class,$this); $this->buildUrlMapping($class,$pattern,$properties,$url); } @@ -262,6 +264,23 @@ class TUrlMapping extends TUrlManager throw new TConfigurationException('urlmapping_urlmappingpattern_required'); foreach($properties as $name=>$value) $pattern->setSubproperty($name,$value); + + if($url instanceof TXmlElement) { + $text = $url -> getValue(); + if($text) { + $text = preg_replace('/(\s+)/S', '', $text); + if(($regExp = $pattern->getRegularExpression()) !== '') + trigger_error(sPrintF('%s.RegularExpression property value "%s" for ServiceID="%s" and ServiceParameter="%s" was replaced by node value "%s"', + get_class($pattern), + $regExp, + $pattern->getServiceID(), + $pattern->getServiceParameter(), + $text), + E_USER_NOTICE); + $pattern->setRegularExpression($text); + } + } + $this->_patterns[]=$pattern; $pattern->init($url); @@ -325,8 +344,8 @@ class TUrlMapping extends TUrlManager { if($this->_customUrl) { - if(!(is_array($getItems) || ($getItems instanceof Traversable))) - $getItems=array(); + if(!(is_array($getItems) || ($getItems instanceof Traversable))) + $getItems=array(); $key=$serviceID.':'.$serviceParam; $wildCardKey = ($pos=strrpos($serviceParam,'.'))!==false ? $serviceID.':'.substr($serviceParam,0,$pos).'.*' : $serviceID.':*'; @@ -337,7 +356,7 @@ class TUrlMapping extends TUrlManager if($rule->supportCustomUrl($getItems)) return $rule->constructUrl($getItems,$encodeAmpersand,$encodeGetItems); } - } + } elseif(isset($this->_constructRules[$wildCardKey])) { foreach($this->_constructRules[$wildCardKey] as $rule) @@ -392,10 +411,12 @@ class TUrlMapping extends TUrlManager * by {@link setRegularExpression RegularExpression}. For example, the above pattern * is equivalent to the following regular expression-based pattern: * - * /^articles\/(?P\d{4})\/(?P\d{2})\/(?P\d+)$/u + * #^articles/(?P\d{4})/(?P\d{2})\/(?P\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. + * 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, @@ -409,7 +430,7 @@ class TUrlMapping extends TUrlManager * (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 + * ServiceParameters with a single rule. The pattern must contain the placeholder * {*} for the ServiceParameter. For example * * @@ -417,24 +438,24 @@ class TUrlMapping extends TUrlManager * 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: + * want to access pages in: * * * * 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 + * You can also use parameters with wildcard patterns. The parameters are then * available with every matching page: * * * - * To enable automatic parameter encoding in a path format fro wildcard patterns you can set - * {@setUrlFormat UrlFormat} to 'Path': + * To enable automatic parameter encoding in a path format fro wildcard patterns you can set + * {@setUrlFormat UrlFormat} to 'Path': * * * - * This will create and parse URLs of the form + * 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 @@ -518,8 +539,8 @@ class TUrlMappingPattern extends TComponent { if($this->_serviceParameter===null) throw new TConfigurationException('urlmappingpattern_serviceparameter_required', $this->getPattern()); - if(strpos($this->_serviceParameter,'*')!==false) - $this->_isWildCardPattern=true; + if(strpos($this->_serviceParameter,'*')!==false) + $this->_isWildCardPattern=true; } /** @@ -537,17 +558,17 @@ class TUrlMappingPattern extends TComponent $values[]='(?P<'.$key.'>'.$value.')'; } if ($this->getIsWildCardPattern()) { - $params[]='{*}'; - // service parameter must not contain '=' and '/' - $values[]='(?P<'.$this->getServiceID().'>[^=/]+)'; + $params[]='{*}'; + // service parameter must not contain '=' and '/' + $values[]='(?P<'.$this->getServiceID().'>[^=/]+)'; } $params[]='/'; $values[]='\\/'; $regexp=str_replace($params,$values,trim($this->getPattern(),'/').'/'); if ($this->_urlFormat===THttpRequestUrlFormat::Get) - $regexp='/^'.$regexp.'$/u'; - else - $regexp='/^'.$regexp.'(?P.*)$/u'; + $regexp='/^'.$regexp.'$/u'; + else + $regexp='/^'.$regexp.'(?P.*)$/u'; if(!$this->getCaseSensitive()) $regexp.='i'; @@ -670,12 +691,12 @@ class TUrlMappingPattern extends TComponent if (isset($matches['urlparams'])) { $params=explode('/',$matches['urlparams']); - if ($this->_separator==='/') + if ($this->_separator==='/') { while($key=array_shift($params)) $matches2[$key]=($value=array_shift($params)) ? $value : ''; - } - else + } + else { array_pop($params); foreach($params as $param) -- cgit v1.2.3