2018-04-18 19:03:39 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Grocy\Helpers;
|
|
|
|
|
|
|
|
class UrlManager
|
|
|
|
{
|
2018-04-21 19:18:00 +02:00
|
|
|
public function __construct(string $basePath)
|
|
|
|
{
|
|
|
|
if ($basePath === '/')
|
|
|
|
{
|
|
|
|
$this->BasePath = $this->GetBaseUrl();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->BasePath = $basePath;
|
|
|
|
}
|
2018-04-18 19:03:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected $BasePath;
|
|
|
|
|
2018-06-15 20:50:40 +02:00
|
|
|
public function ConstructUrl($relativePath, $isResource = false)
|
2018-04-18 19:03:39 +02:00
|
|
|
{
|
2018-06-15 20:50:40 +02:00
|
|
|
if (DISABLE_URL_REWRITING === false || $isResource === true)
|
|
|
|
{
|
|
|
|
return rtrim($this->BasePath, '/') . $relativePath;
|
|
|
|
}
|
|
|
|
else // Is not a resource and URL rewriting is disabled
|
|
|
|
{
|
|
|
|
return rtrim($this->BasePath, '/') . '/index.php' . $relativePath;
|
|
|
|
}
|
2018-04-18 19:03:39 +02:00
|
|
|
}
|
2018-04-21 19:18:00 +02:00
|
|
|
|
|
|
|
private function GetBaseUrl()
|
|
|
|
{
|
|
|
|
return (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]";
|
|
|
|
}
|
2018-04-18 19:03:39 +02:00
|
|
|
}
|