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;
|
|
|
|
|
|
|
|
public function ConstructUrl($relativePath)
|
|
|
|
{
|
|
|
|
return rtrim($this->BasePath, '/') . $relativePath;
|
|
|
|
}
|
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
|
|
|
}
|