71 lines
1.7 KiB
PHP
71 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace CrocWork\Zappy\Routing;
|
|
|
|
use CrocWork\Zappy\I18n\Translator;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
class UrlGenerator
|
|
{
|
|
protected $translator;
|
|
|
|
protected $routes;
|
|
|
|
protected $request;
|
|
|
|
protected $baseUrl;
|
|
|
|
public function __construct(string $baseUrl, Request $request, Translator $translator)
|
|
{
|
|
$this->request = $request;
|
|
$this->translator = $translator;
|
|
$this->baseUrl = $baseUrl ?? $request->getBaseUrl();
|
|
}
|
|
|
|
public function getBaseUrl(string $path = '', array $data = [], ?string $locale = null): string
|
|
{
|
|
$overrideLocale = $locale ?? $this->translator->getLocale();
|
|
$localePrefix = ($overrideLocale != $this->translator->getDefaultLocale())
|
|
? $overrideLocale . DIRECTORY_SEPARATOR
|
|
: '';
|
|
|
|
$url = $this->baseUrl . $localePrefix . ($path ? DIRECTORY_SEPARATOR.$path : '');
|
|
|
|
//Attach data as a query string.
|
|
if(!empty($data)) {
|
|
|
|
}
|
|
|
|
return $url;
|
|
}
|
|
|
|
public function getUrl(string $path = '', array $data = [], ?string $locale = null): string
|
|
{
|
|
return $this->getBaseUrl($path, $data, $locale);
|
|
}
|
|
|
|
public function getStorageUrl(string $path = '', array $data = [], ?string $locale = null): string
|
|
{
|
|
return '';
|
|
}
|
|
|
|
public function getAssetUrl(string $path = '', array $data = [], ?string $locale = null): string
|
|
{
|
|
return '';
|
|
}
|
|
|
|
public function getRouteUrl(string $route = '', array $data = [], ?string $locale = null): string
|
|
{
|
|
return '';
|
|
}
|
|
|
|
public function setRoutes(array $routes): bool
|
|
{
|
|
if(!empty($this->routes)) {
|
|
$this->routes = $routes;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
} |