Classes/Helper/LinkHelper.php
public function buildLink(
        string $protocol = null,
        string $host = null,
        $path = null,
        array $query = null,
        string $fragment = null
    ): string {
        if (empty($protocol)) {
            $protocol = (array_key_exists('HTTPS', $_SERVER) && !empty($_SERVER['HTTPS']) ? 'https' : 'http');
        }

        if (empty($host)) {
            $host = $_SERVER['HTTP_HOST'];
        }

        $link = "$protocol://$host/";

        if (!empty($path)) {
            if (is_string($path)) {
                $link .= $path;
            } elseif (is_array($path)) {
                $path = $this->pathHelper->joinArray($path);
                $link .= $path;
            } else {
                $type = gettype($path);
                throw new InvalidArgumentException(
                    "Expected a the path argument to be of type string or array, $type given!",
                    1530398563
                );
            }
        }

        if (!empty($query)) {
            $link .= '?'.array_keys($query)[0].'='.array_shift($query);

            foreach ($query as $key => $value) {
                $link .= "&$key=$value";
            }
        }

        if (!empty($fragment)) {
            $link .= "#$fragment";
        }

        return $link;
    }
public function buildLink(
        string $protocol = null,
        string $host = null,
        $path = null,
        array $query = null,
        string $fragment = null
    ): string {
        if (empty($protocol)) {
            $protocol = (array_key_exists('HTTPS', $_SERVER) && !empty($_SERVER['HTTPS']) ? 'https' : 'http');
        }

        if (empty($host)) {
            $host = $_SERVER['HTTP_HOST'];
        }

        $link = "$protocol://$host/";

        if (!empty($path)) {
            if (is_string($path)) {
                $link .= $path;
            } elseif (is_array($path)) {
                $path = $this->pathHelper->joinArray($path);
                $link .= $path;
            } else {
                $type = gettype($path);
                throw new InvalidArgumentException(
                    "Expected a the path argument to be of type string or array, $type given!",
                    1530398563
                );
            }
        }

        if (!empty($query)) {
            $link .= '?'.array_keys($query)[0].'='.array_shift($query);

            foreach ($query as $key => $value) {
                $link .= "&$key=$value";
            }
        }

        if (!empty($fragment)) {
            $link .= "#$fragment";
        }

        return $link;
    }
public function buildLink ( string $ protocol = null , string $ host = null , $ path = null , array $ query = null , string $ fragment = null ) : string { if ( empty ( $ protocol ) ) { $ protocol = ( array_key_exists ( 'HTTPS' , $ _SERVER ) && ! empty ( $ _SERVER [ 'HTTPS' ] ) ? 'https' : 'http' ) ; } if ( empty ( $ host ) ) { $ host = $ _SERVER [ 'HTTP_HOST' ] ; } $ link = "$protocol://$host/" ; if ( ! empty ( $ path ) ) { if ( is_string ( $ path ) ) { $ link .= $ path ; } elseif ( is_array ( $ path ) ) { $ path = $ this -> pathHelper -> joinArray ( $ path ) ; $ link .= $ path ; } else { $ type = gettype ( $ path ) ; throw new InvalidArgumentException ( "Expected a the path argument to be of type string or array, $type given!" , 1530398563 ) ; } } if ( ! empty ( $ query ) ) { $ link .= '?' . array_keys ( $ query ) [ 0 ] . '=' . array_shift ( $ query ) ; foreach ( $ query as $ key => $ value ) { $ link .= "&$key=$value" ; } } if ( ! empty ( $ fragment ) ) { $ link .= "#$fragment" ; } return $ link ; }
Build an URL by the given arguments.

@param string            $protocol The link protocol (defaults to the current request protocol)
@param string            $host     The link host (defaults to the current http host)
@param string|array|null $path     The link path (optional)
@param array|null        $query    Additional query parameters (optional)
@param string|null       $fragment The link fragment (optional)

@return string
Build an URL by the given arguments .