summaryrefslogtreecommitdiff
path: root/framework/Web
diff options
context:
space:
mode:
authorhaertl.mike <>2008-11-24 17:16:44 +0000
committerhaertl.mike <>2008-11-24 17:16:44 +0000
commit3a65efc7a28e5a1513301fcf2948f873db41039b (patch)
treee5206d4235883dec63ea028fbd4cee27b1aebf3a /framework/Web
parenta39b73ea8a9d858d35f2a7a0ea16c3bf26c0f12c (diff)
Base url wildcard implementation (Issue #72)
Diffstat (limited to 'framework/Web')
-rw-r--r--framework/Web/TUrlMapping.php35
1 files changed, 33 insertions, 2 deletions
diff --git a/framework/Web/TUrlMapping.php b/framework/Web/TUrlMapping.php
index 6eba80f4..338c00f8 100644
--- a/framework/Web/TUrlMapping.php
+++ b/framework/Web/TUrlMapping.php
@@ -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
@@ -618,7 +649,7 @@ class TUrlMappingPattern extends TComponent
{
if($encodeGetItems)
$value=rawurlencode($value);
- if($this->_parameters->contains($key))
+ if($this->_parameters->contains($key) || $key==='*' && $this->getIsWildCardPattern())
$replace['{'.$key.'}']=$value;
else
$extra[$key]=$value;