route : the baseURL is now relative by default. It allow the route module to work across a proxy

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2074 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2015-04-27 13:44:05 +00:00
parent 586a7fa075
commit 1578a21a6b

View File

@@ -30,7 +30,7 @@ class route
/** Return the baseURL of the site
Always finish with a slash
@param string|null $module The module name (if thereis one) */
function baseURL ($module = FALSE)
function baseURL ($module = FALSE, $absolute=false)
{
if ($this->module === NULL)
$this->module = $module;
@@ -47,12 +47,15 @@ class route
if (isset ($_SERVER["SCRIPT_NAME"]))
$this->baseURL = dirname ($_SERVER["SCRIPT_NAME"]);
if (isset ($_SERVER["SERVER_NAME"]))
$this->baseURL = "//".$_SERVER["SERVER_NAME"].$port.$this->baseURL;
if (isset ($_SERVER["HTTPS"]))
$this->baseURL = "https:".$this->baseURL;
else
$this->baseURL = "http:".$this->baseURL;
if ($absolute === true)
{
if (isset ($_SERVER["SERVER_NAME"]))
$this->baseURL = "//".$_SERVER["SERVER_NAME"].$port.$this->baseURL;
if (isset ($_SERVER["HTTPS"]))
$this->baseURL = "https:".$this->baseURL;
else
$this->baseURL = "http:".$this->baseURL;
}
if (substr ($this->baseURL, -1) !== "/")
$this->baseURL .= "/";
$this->baseURLmodule = $this->baseURL;
@@ -84,22 +87,26 @@ class route
}
/** Return the complete URL used to see this page */
function requestURL ()
function requestURL ($absolute = false)
{
if (isset ($_SERVER["HTTPS"]))
$url = "https:";
else
$url = "http:";
if (!isset ($_SERVER["SERVER_PORT"]))
$_SERVER["SERVER_PORT"] = "80";
$port = ":".$_SERVER["SERVER_PORT"];
if (!isset ($_SERVER["HTTPS"]) && $_SERVER["SERVER_PORT"] === "80")
$port = "";
if (isset ($_SERVER["HTTPS"]) && $_SERVER["SERVER_PORT"] === "443")
$port = "";
$url = "";
if ($absolute === true)
{
if (isset ($_SERVER["HTTPS"]))
$url = "https:";
else
$url = "http:";
if (!isset ($_SERVER["SERVER_PORT"]))
$_SERVER["SERVER_PORT"] = "80";
$port = ":".$_SERVER["SERVER_PORT"];
if (!isset ($_SERVER["HTTPS"]) && $_SERVER["SERVER_PORT"] === "80")
$port = "";
if (isset ($_SERVER["HTTPS"]) && $_SERVER["SERVER_PORT"] === "443")
$port = "";
if (isset ($_SERVER["SERVER_NAME"]))
$url .= "//".$_SERVER["SERVER_NAME"].$port;
if (isset ($_SERVER["SERVER_NAME"]))
$url .= "//".$_SERVER["SERVER_NAME"].$port;
}
if (isset ($_SERVER["REQUEST_URI"]))
$url .= $_SERVER["REQUEST_URI"];
return $url;
@@ -128,11 +135,6 @@ class route
// Absolute : return to project base
$destURL = $baseURL.substr ($destURL, 1);
}
if (substr ($destURL, 0, 4) !== "http")
{
// Relative to parameters : continue
$destURL = $requestURL.$destURL;
}
// Else http : keep the complete URL
if ($destURL === "")
@@ -222,6 +224,7 @@ class route
return;
}
file_put_contents ("/tmp/csrf.log", date ("Y-m-d H:i:s")." GET route->map ($route, ...)\n", FILE_APPEND);
return $this->map ($route, $function);
}
@@ -243,6 +246,7 @@ class route
return;
}
file_put_contents ("/tmp/csrf.log", date ("Y-m-d H:i:s")." POST route->map ($route, ...)\n", FILE_APPEND);
return $this->map ($route, $function);
}
@@ -264,6 +268,7 @@ class route
return;
}
file_put_contents ("/tmp/csrf.log", date ("Y-m-d H:i:s")." PUT route->map ($route, ...)\n", FILE_APPEND);
return $this->map ($route, $function);
}
@@ -285,6 +290,7 @@ class route
return;
}
file_put_contents ("/tmp/csrf.log", date ("Y-m-d H:i:s")." DELETE route->map ($route, ...)\n", FILE_APPEND);
return $this->map ($route, $function);
}
@@ -301,6 +307,7 @@ class route
{
if ($this->debug)
echo "==> FOUND EQUAL !\n";
file_put_contents ("/tmp/csrf.log", date ("Y-m-d H:i:s")." map : BACKTRACE = ".print_r(debug_backtrace(), TRUE)."\n", FILE_APPEND);
try
{
$function ();
@@ -329,6 +336,7 @@ class route
{
if ($this->debug)
echo "==> FOUND REGEX !\n";
file_put_contents ("/tmp/csrf.log", date ("Y-m-d H:i:s")." map : BACKTRACE = ".print_r(debug_backtrace(), TRUE)."\n", FILE_APPEND);
$params = array ();
$reflect = new ReflectionFunction ($function);
foreach ($reflect->getParameters() as $key=>$val)