engelsystem/src/Http/UrlGenerator.php

31 lines
746 B
PHP
Raw Normal View History

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