summaryrefslogtreecommitdiff
path: root/src/Http/UrlGenerator.php
blob: d84a02b5909358dfa67ff9de4969e8b484529588 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php

namespace Engelsystem\Http;

/**
 * Provides urls when rewriting on the webserver is enabled. (default)
 *
 * The urls have the form <app url>/<path>?<parameters>
 */
class UrlGenerator implements UrlGeneratorInterface
{
    /**
     * @param string $path
     * @param array  $parameters
     * @return string url in the form [app url]/[path]?[parameters]
     */
    public function to($path, $parameters = [])
    {
        $path = '/' . ltrim($path, '/');
        $request = app('request');
        $uri = $request->getUriForPath($path);

        if (!empty($parameters) && is_array($parameters)) {
            $parameters = http_build_query($parameters);
            $uri .= '?' . $parameters;
        }

        return $uri;
    }
}