function IPF_Context_Current($request)
{
- return array('CURRENT_URL' => IPF_HTTP_URL::getAction());
+ return array('CURRENT_URL' => $request->query);
}
+
public $remote_addr = '';
public $http_host = '';
public $SERVER = array();
+ public $is_secure = false;
- function __construct($query)
+ public function __construct()
{
$http = new IPF_HTTP();
$http->removeTheMagic();
$this->REQUEST =& $_REQUEST;
$this->COOKIE =& $_COOKIE;
$this->FILES =& $_FILES;
- $this->query = $query;
$this->method = $_SERVER['REQUEST_METHOD'];
$this->uri = $_SERVER['REQUEST_URI'];
$this->remote_addr = $_SERVER['REMOTE_ADDR'];
$this->http_host = $_SERVER['HTTP_HOST'];
+
+ if (isset($_SERVER['REQUEST_URI'])) {
+ $uri = $_SERVER['REQUEST_URI'];
+ $pq = strpos($uri,'?');
+ if ($pq !== false)
+ $uri = substr($uri, 0, $pq);
+ $this->query = preg_replace('#^(//+)#', '/', '/'.$uri);
+ } else {
+ $this->query = '/';
+ }
+
if (isset($_SERVER['PATH_INFO']))
$this->path_info = $_SERVER['PATH_INFO'];
else
$this->path_info = '/';
$this->SERVER =& $_SERVER;
+ $this->is_secure = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off';
}
-
- function isSecure(){
- return false; // # FIXME
- }
-
- function addUrlrotocol($uri){
- if ($this->isSecure())
- $proto = 'https';
- else
- $proto = 'http';
- return $proto.'://'.$uri;
+
+ public function absoluteUrl()
+ {
+ return ($this->is_secure ? 'https://' : 'http://') . $this->http_host . $this->query;
}
}
+
return $url;
}
- public static function getAction()
- {
- if (isset($_SERVER['REQUEST_URI'])) {
- $uri = $_SERVER['REQUEST_URI'];
- $pq = strpos($uri,'?');
- if ($pq!==false)
- $uri = substr($uri,0,$pq);
- return $uri;
- }
- return '/';
- }
-
public static function urlForView($view, $params=array(), $get_params=array(), $encoded=true)
{
$action = IPF_Project::getInstance()->router->reverse($view, $params);
function processRequest(&$request)
{
if (IPF::get('append_slash', true)) {
- $url = $request->http_host . IPF_HTTP_URL::getAction();
- if (substr($url,-1)!='/') {
- $url = $request->addUrlrotocol($url).'/';
- return new IPF_HTTP_Response_Redirect($url);
- }
+ $url = $request->absoluteUrl();
+ if (substr($url, -1) !== '/')
+ return new IPF_HTTP_Response_Redirect($url.'/');
}
return false;
}
$cli->run();
} else {
$this->loadAllModels();
- $this->router->dispatch(IPF_HTTP_URL::getAction());
+ $request = new IPF_HTTP_Request;
+ $this->router->dispatch($request);
}
return true;
return new IPF_HTTP_Response_ServerError($e);
}
- public function dispatch($query='')
+ public function dispatch($req)
{
- try{
- $query = preg_replace('#^(/)+#', '/', '/'.$query);
- $req = new IPF_HTTP_Request($query);
+ try {
$middleware = array();
foreach (IPF::get('middlewares', array()) as $mw) {
$middleware[] = new $mw();