engelsystem/src/Routing/UrlGenerator.php

31 lines
755 B
PHP
Raw Normal View History

<?php
namespace Engelsystem\Routing;
/**
* 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]
*/
public function link_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;
}
}