2017-08-29 16:21:25 +02:00
|
|
|
<?php
|
|
|
|
|
2018-08-22 03:10:08 +02:00
|
|
|
namespace Engelsystem\Http;
|
2017-08-29 16:21:25 +02:00
|
|
|
|
2018-08-06 12:50:34 +02:00
|
|
|
/**
|
|
|
|
* Provides urls when rewriting on the webserver is enabled. (default)
|
2019-04-24 11:01:37 +02:00
|
|
|
*
|
2018-08-06 12:50:34 +02:00
|
|
|
* The urls have the form <app url>/<path>?<parameters>
|
|
|
|
*/
|
2018-03-31 05:19:49 +02:00
|
|
|
class UrlGenerator implements UrlGeneratorInterface
|
2017-08-29 16:21:25 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param string $path
|
|
|
|
* @param array $parameters
|
2018-08-06 12:50:34 +02:00
|
|
|
* @return string url in the form [app url]/[path]?[parameters]
|
2017-08-29 16:21:25 +02:00
|
|
|
*/
|
2017-09-20 01:09:11 +02:00
|
|
|
public function to($path, $parameters = [])
|
2017-08-29 16:21:25 +02:00
|
|
|
{
|
|
|
|
$path = '/' . ltrim($path, '/');
|
2017-08-31 17:30:54 +02:00
|
|
|
$request = app('request');
|
2017-08-29 16:21:25 +02:00
|
|
|
$uri = $request->getUriForPath($path);
|
|
|
|
|
|
|
|
if (!empty($parameters) && is_array($parameters)) {
|
|
|
|
$parameters = http_build_query($parameters);
|
|
|
|
$uri .= '?' . $parameters;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $uri;
|
|
|
|
}
|
|
|
|
}
|