diff options
author | xue <> | 2006-02-07 19:05:33 +0000 |
---|---|---|
committer | xue <> | 2006-02-07 19:05:33 +0000 |
commit | 60e486b5697030d18311f67de29b95a892c7d95d (patch) | |
tree | b61991b7a3b419d586980ef9a5ad318c1429b4ea /framework | |
parent | ee2e653ec9da8cc311989acf6b21b78d32cc80c3 (diff) |
Added UrlFormat property to THttpRequest.
Diffstat (limited to 'framework')
-rw-r--r-- | framework/Security/TAuthManager.php | 11 | ||||
-rw-r--r-- | framework/Web/THttpRequest.php | 62 | ||||
-rw-r--r-- | framework/Web/THttpResponse.php | 27 |
3 files changed, 74 insertions, 26 deletions
diff --git a/framework/Security/TAuthManager.php b/framework/Security/TAuthManager.php index c46e32c1..819b7b36 100644 --- a/framework/Security/TAuthManager.php +++ b/framework/Security/TAuthManager.php @@ -169,13 +169,22 @@ class TAuthManager extends TModule if($service instanceof TPageService)
{
$returnUrl=$application->getRequest()->getRequestUri();
- $url=$service->constructUrl($this->getLoginPage(),array(self::RETURN_URL_VAR=>$returnUrl));
+ $application->getSession()->add(self::RETURN_URL_VAR,$returnUrl);
+ $url=$service->constructUrl($this->getLoginPage());
$application->getResponse()->redirect($url);
}
}
}
/**
+ * @return string URL that the browser should be redirected to when login succeeds.
+ */
+ public function getReturnUrl()
+ {
+ return $this->getSession()->itemAt(self::RETURN_URL_VAR);
+ }
+
+ /**
* Performs the real authentication work.
* An OnAuthenticate event will be raised if there is any handler attached to it.
* If the application already has a non-null user, it will return without further authentication.
diff --git a/framework/Web/THttpRequest.php b/framework/Web/THttpRequest.php index ba626d07..b8db56d6 100644 --- a/framework/Web/THttpRequest.php +++ b/framework/Web/THttpRequest.php @@ -80,6 +80,7 @@ class THttpRequest extends TMap implements IModule */
private $_pathInfo;
+ private $_urlFormat='Get';
private $_services;
private $_requestResolved=false;
/**
@@ -140,7 +141,20 @@ class THttpRequest extends TMap implements IModule $_COOKIE=$this->stripSlashes($_COOKIE);
}
- $this->copyFrom(array_merge($_GET,$_POST));
+ if($this->getUrlFormat()==='Path' && ($pathInfo=trim($this->_pathInfo,'/'))!=='')
+ {
+ $paths=explode('/',$pathInfo);
+ $n=count($paths);
+ $getVariables=array();
+ for($i=0;$i<$n;++$i)
+ {
+ if($i+1<$n)
+ $getVariables[$paths[$i]]=$paths[++$i];
+ }
+ $this->copyFrom(array_merge($getVariables,array_merge($_GET,$_POST)));
+ }
+ else
+ $this->copyFrom(array_merge($_GET,$_POST));
$this->_initialized=true;
$this->getApplication()->setRequest($this);
@@ -182,6 +196,27 @@ class THttpRequest extends TMap implements IModule }
/**
+ * @return string the format of URLs. Defaults to 'Get'.
+ */
+ public function getUrlFormat()
+ {
+ return $this->_urlFormat;
+ }
+
+ /**
+ * Sets the format of URLs constructed and interpretted by the request module.
+ * A 'Get' URL format is like index.php?name1=value1&name2=value2
+ * while a 'Path' URL format is like index.php/name1/value1/name2/value.
+ * Changing the UrlFormat will affect {@link constructUrl} and how GET variables
+ * are parsed.
+ * @param string the format of URLs. Valid values include 'Path' and 'Get'.
+ */
+ public function setUrlFormat($value)
+ {
+ $this->_urlFormat=TPropertyValue::ensureEnum($value,'Path','Get');
+ }
+
+ /**
* @return string request type, can be GET, POST, HEAD, or PUT
*/
public function getRequestType()
@@ -366,19 +401,26 @@ class THttpRequest extends TMap implements IModule */
public function constructUrl($serviceID,$serviceParam,$getItems=null,$encodeAmpersand=false)
{
- $url=$this->getApplicationPath();
- $url.='?'.$serviceID.'=';
- if(!empty($serviceParam))
- $url.=$serviceParam;
+ $url=$serviceID.'='.$serviceParam;
$amp=$encodeAmpersand?'&':'&';
if(is_array($getItems) || $getItems instanceof Traversable)
{
foreach($getItems as $name=>$value)
$url.=$amp.urlencode($name).'='.urlencode($value);
}
- if(defined('SID') && SID != '')
- $url.=$amp.SID;
- return $url;
+ if($this->getUrlFormat()==='Path')
+ {
+ $url=strtr($url,array($amp=>'/','?'=>'/','='=>'/'));
+ if(defined('SID') && SID != '')
+ $url.='?'.SID;
+ return $this->getApplicationPath().'/'.$url;
+ }
+ else
+ {
+ if(defined('SID') && SID != '')
+ $url.=$amp.SID;
+ return $this->getApplicationPath().'?'.$url;
+ }
}
/**
@@ -395,10 +437,10 @@ class THttpRequest extends TMap implements IModule $this->_requestResolved=true;
foreach($this->_services as $id)
{
- if(isset($_GET[$id]))
+ if($this->contains($id))
{
$this->setServiceID($id);
- $this->setServiceParameter($_GET[$id]);
+ $this->setServiceParameter($this->itemAt($id));
break;
}
}
diff --git a/framework/Web/THttpResponse.php b/framework/Web/THttpResponse.php index ea41ab16..d51c0cf2 100644 --- a/framework/Web/THttpResponse.php +++ b/framework/Web/THttpResponse.php @@ -274,24 +274,25 @@ class THttpResponse extends TModule implements ITextWriter */
public function flush()
{
- $header = $this->getContentTypeHeader();
- $this->appendHeader($header);
+ Prado::trace("Flushing output",'System.Web.THttpResponse');
+ $this->sendContentTypeHeader();
if($this->_bufferOutput)
ob_flush();
- Prado::trace("Flushing output $header",'System.Web.THttpResponse');
}
/**
- * @return string content type and charset header
+ * Sends content type header if charset is not empty.
*/
- protected function getContentTypeHeader()
+ protected function sendContentTypeHeader()
{
- $app = $this->getApplication()->getGlobalization();
$charset = $this->getCharset();
- if(empty($charset))
- $charset = !is_null($app) ? $app->getCharset() : 'UTF-8';
- $type = $this->getContentType();
- return "Content-Type: $type; charset=$charset";
+ if(empty($charset) && ($globalization=$this->getApplication()->getGlobalization())!==null)
+ $charset = $globalization->getCharset();
+ if(!empty($charset))
+ {
+ $header='Content-Type: '.$this->getContentType().';charset='.$charset;
+ $this->appendHeader($header);
+ }
}
/**
@@ -310,14 +311,10 @@ class THttpResponse extends TModule implements ITextWriter */
public function appendHeader($value)
{
+ Prado::trace("Sending header '$value'",'System.Web.THttpResponse');
header($value);
}
- public function sendContentTypeHeader($type=null)
- {
-
- }
-
/**
* Writes a log message into error log.
* This method is simple wrapper of PHP function error_log.
|