summaryrefslogtreecommitdiff
path: root/framework/Web/THttpRequest.php
diff options
context:
space:
mode:
authorxue <>2006-08-02 02:24:29 +0000
committerxue <>2006-08-02 02:24:29 +0000
commit550ba06593b467b643862d41a00ca2dd12ee704b (patch)
tree16ad8180c2f0b96454453effff89dc236469ee4f /framework/Web/THttpRequest.php
parentccfa7850dc435ae9941cde18be827b3aac550f85 (diff)
merge from 3.0 branch till 1320.
Diffstat (limited to 'framework/Web/THttpRequest.php')
-rw-r--r--framework/Web/THttpRequest.php53
1 files changed, 35 insertions, 18 deletions
diff --git a/framework/Web/THttpRequest.php b/framework/Web/THttpRequest.php
index 01827f33..130dc3cf 100644
--- a/framework/Web/THttpRequest.php
+++ b/framework/Web/THttpRequest.php
@@ -57,13 +57,12 @@
* @package System.Web
* @since 3.0
*/
-class THttpRequest extends TApplicationComponent implements IteratorAggregate,ArrayAccess,IModule
+class THttpRequest extends TApplicationComponent implements IteratorAggregate,ArrayAccess,Countable,IModule
{
/**
* Separator used to separate GET variable name and value when URL format is Path.
*/
- const URL_PARAM_SEPARATOR=',';
-
+ private $_separator=',';
/**
* @var boolean whether the module is initialized
*/
@@ -227,6 +226,26 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar
}
/**
+ * @return string separator used to separate GET variable name and value when URL format is Path. Defaults to comma ','.
+ */
+ public function getUrlParamSeparator()
+ {
+ return $this->_separator;
+ }
+
+ /**
+ * @param string separator used to separate GET variable name and value when URL format is Path.
+ * @throws TInvalidDataValueException if the separator is not a single character
+ */
+ public function setUrlParamSeparator($value)
+ {
+ if(strlen($value)===1)
+ $this->_separator=$value;
+ else
+ throw new TInvalidDataValueException('httprequest_separator_invalid');
+ }
+
+ /**
* @return string request type, can be GET, POST, HEAD, or PUT
*/
public function getRequestType()
@@ -460,10 +479,7 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar
*/
public function constructUrl($serviceID,$serviceParam,$getItems=null,$encodeAmpersand=false,$encodeGetItems=true)
{
- if($this->getUrlFormat()==='Path')
- $url=$serviceID.'/'.$serviceParam;
- else
- $url=$serviceID.'='.$serviceParam;
+ $url=$serviceID.'='.$serviceParam;
$amp=$encodeAmpersand?'&amp;':'&';
if(is_array($getItems) || $getItems instanceof Traversable)
{
@@ -497,7 +513,7 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar
}
if($this->getUrlFormat()==='Path')
{
- $url=strtr($url,array($amp=>'/','?'=>'/','='=>self::URL_PARAM_SEPARATOR));
+ $url=strtr($url,array($amp=>'/','?'=>'/','='=>$this->_separator));
if(defined('SID') && SID != '' && !((int)ini_get('session.use_cookies')===1 && ((int)ini_get('session.use_only_cookies')===1)))
$url.='?'.SID;
return $this->getApplicationUrl().'/'.$url;
@@ -523,13 +539,12 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar
{
$paths=explode('/',$this->_pathInfo);
$getVariables=$_GET;
- $index=0;
$serviceID=null;
foreach($paths as $path)
{
if(($path=trim($path))!=='')
{
- if(($pos=strpos($path,','))!==false)
+ if(($pos=strpos($path,$this->_separator))!==false)
{
$name=substr($path,0,$pos);
$value=substr($path,$pos+1);
@@ -538,16 +553,8 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar
else
$getVariables[$name]=$value;
}
- else if($index===0)
- {
- $serviceID=$path;
- $getVariables[$serviceID]='';
- }
- else if($index===1 && $serviceID!==null)
- $getVariables[$serviceID]=$path;
else
$getVariables[$path]='';
- $index++;
}
}
return $getVariables;
@@ -654,6 +661,16 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar
}
/**
+ * Returns the number of items in the request.
+ * This method is required by Countable interface.
+ * @return integer number of items in the request.
+ */
+ public function count()
+ {
+ return $this->getCount();
+ }
+
+ /**
* @return array the key list
*/
public function getKeys()