summaryrefslogtreecommitdiff
path: root/framework/Web/TUrlMapping.php
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web/TUrlMapping.php')
-rw-r--r--framework/Web/TUrlMapping.php50
1 files changed, 39 insertions, 11 deletions
diff --git a/framework/Web/TUrlMapping.php b/framework/Web/TUrlMapping.php
index e1deea0f..83dd99b6 100644
--- a/framework/Web/TUrlMapping.php
+++ b/framework/Web/TUrlMapping.php
@@ -76,7 +76,7 @@ class TUrlMapping extends TUrlManager
/**
* @var TUrlMappingPattern[] list of patterns.
*/
- private $_patterns=array();
+ protected $_patterns=array();
/**
* @var TUrlMappingPattern matched pattern.
*/
@@ -92,7 +92,7 @@ class TUrlMapping extends TUrlManager
/**
* @var array rules for constructing URLs
*/
- private $_constructRules=array();
+ protected $_constructRules=array();
private $_urlPrefix='';
@@ -264,7 +264,8 @@ class TUrlMapping extends TUrlManager
if(is_string($key))
$params[$key]=$value;
}
- $params[$pattern->getServiceID()]=$pattern->getServiceParameter();
+ if (!$pattern->getIsWildCardPattern())
+ $params[$pattern->getServiceID()]=$pattern->getServiceParameter();
return $params;
}
}
@@ -299,6 +300,8 @@ class TUrlMapping extends TUrlManager
if(!(is_array($getItems) || ($getItems instanceof Traversable)))
$getItems=array();
$key=$serviceID.':'.$serviceParam;
+ $wildCardKey = ($pos=strrpos($serviceParam,'.'))!==false ?
+ $serviceID.':'.substr($serviceParam,0,$pos).'.*' : $serviceID.':*';
if(isset($this->_constructRules[$key]))
{
foreach($this->_constructRules[$key] as $rule)
@@ -306,6 +309,17 @@ 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)
+ {
+ if($rule->supportCustomUrl($getItems))
+ {
+ $getItems['*']= $pos ? substr($serviceParam,$pos+1) : $serviceParam;
+ return $rule->constructUrl($getItems,$encodeAmpersand,$encodeGetItems);
+ }
+ }
}
}
return parent::constructUrl($serviceID,$serviceParam,$getItems,$encodeAmpersand,$encodeGetItems);
@@ -399,6 +413,8 @@ class TUrlMappingPattern extends TComponent
private $_manager;
private $_caseSensitive=true;
+
+ private $_isWildCardPattern=false;
/**
* Constructor.
@@ -428,6 +444,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;
}
/**
@@ -444,6 +462,11 @@ class TUrlMappingPattern extends TComponent
$params[]='{'.$key.'}';
$values[]='(?P<'.$key.'>'.$value.')';
}
+ if ($this->getIsWildCardPattern()) {
+ $params[]='{*}';
+ // service parameter must not contain '=' and '/'
+ $values[]='(?P<'.$this->getServiceID().'>[^=/]+)';
+ }
$params[]='/';
$values[]='\\/';
$regexp=str_replace($params,$values,trim($this->getPattern(),'/').'/');
@@ -585,6 +608,14 @@ class TUrlMappingPattern extends TComponent
}
/**
+ * @return boolean whether this pattern is a wildcard pattern
+ * @since 3.1.4
+ */
+ public function getIsWildCardPattern() {
+ return $this->_isWildCardPattern;
+ }
+
+ /**
* @param array list of GET items to be put in the constructed URL
* @return boolean whether this pattern IS the one for constructing the URL with the specified GET items.
* @since 3.1.1
@@ -616,10 +647,8 @@ class TUrlMappingPattern extends TComponent
// for the GET variables matching the pattern, put them in the URL path
foreach($getItems as $key=>$value)
{
- if($encodeGetItems)
- $value=urlencode($value);
- if($this->_parameters->contains($key))
- $replace['{'.$key.'}']=$value;
+ if($this->_parameters->contains($key) || $key==='*' && $this->getIsWildCardPattern())
+ $replace['{'.$key.'}']=$encodeGetItems ? rawurlencode($value) : $value;
else
$extra[$key]=$value;
}
@@ -637,12 +666,12 @@ class TUrlMappingPattern extends TComponent
{
if(is_array($value))
{
- $name=urlencode($name.'[]');
+ $name=rawurlencode($name.'[]');
foreach($value as $v)
- $url2.=$amp.$name.'='.urlencode($v);
+ $url2.=$amp.$name.'='.rawurlencode($v);
}
else
- $url2.=$amp.urlencode($name).'='.urlencode($value);
+ $url2.=$amp.rawurlencode($name).'='.rawurlencode($value);
}
}
else
@@ -664,4 +693,3 @@ class TUrlMappingPattern extends TComponent
}
}
-?>