src/acdhOeaw/fedora/dissemination/parameter/AddParam.php
public function transform(string $value, string $paramName = '',
                              string $paramValue = ''): string {
        $value = parse_url($value);

        if (!isset($value['query'])) {
            $value['query'] = '';
        }
        $param = [];
        parse_str($value['query'], $param);
        if (!isset($param[$paramName])) {
            $param[$paramName] = $paramValue;
        } else {
            if (!is_array($param[$paramName])) {
                $param[$paramName] = [$param[$paramName]];
            }
            $param[$paramName][] = $paramValue;
            $param[$paramName]   = array_unique($param[$paramName]);
        }
        $value['query'] = http_build_query($param);

        $scheme   = isset($value['scheme']) ? $value['scheme'] . '://' : '';
        $host     = isset($value['host']) ? $value['host'] : '';
        $port     = isset($value['port']) ? ':' . $value['port'] : '';
        $user     = isset($value['user']) ? $value['user'] : '';
        $pass     = isset($value['pass']) ? ':' . $value['pass'] : '';
        $pass     = ($user || $pass) ? "$pass@" : '';
        $path     = isset($value['path']) ? $value['path'] : '';
        $query    = isset($value['query']) ? '?' . $value['query'] : '';
        $fragment = isset($value['fragment']) ? '#' . $value['fragment'] : '';
        return $scheme . $user . $pass . $host . $port . $path . $query . $fragment;
    }
public function transform(string $value, string $paramName = '',
                              string $paramValue = ''): string {
        $value = parse_url($value);

        if (!isset($value['query'])) {
            $value['query'] = '';
        }
        $param = [];
        parse_str($value['query'], $param);
        if (!isset($param[$paramName])) {
            $param[$paramName] = $paramValue;
        } else {
            if (!is_array($param[$paramName])) {
                $param[$paramName] = [$param[$paramName]];
            }
            $param[$paramName][] = $paramValue;
            $param[$paramName]   = array_unique($param[$paramName]);
        }
        $value['query'] = http_build_query($param);

        $scheme   = isset($value['scheme']) ? $value['scheme'] . '://' : '';
        $host     = isset($value['host']) ? $value['host'] : '';
        $port     = isset($value['port']) ? ':' . $value['port'] : '';
        $user     = isset($value['user']) ? $value['user'] : '';
        $pass     = isset($value['pass']) ? ':' . $value['pass'] : '';
        $pass     = ($user || $pass) ? "$pass@" : '';
        $path     = isset($value['path']) ? $value['path'] : '';
        $query    = isset($value['query']) ? '?' . $value['query'] : '';
        $fragment = isset($value['fragment']) ? '#' . $value['fragment'] : '';
        return $scheme . $user . $pass . $host . $port . $path . $query . $fragment;
    }
public function transform ( string $ value , string $ paramName = '' , string $ paramValue = '' ) : string { $ value = parse_url ( $ value ) ; if ( ! isset ( $ value [ 'query' ] ) ) { $ value [ 'query' ] = '' ; } $ param = [ ] ; parse_str ( $ value [ 'query' ] , $ param ) ; if ( ! isset ( $ param [ $ paramName ] ) ) { $ param [ $ paramName ] = $ paramValue ; } else { if ( ! is_array ( $ param [ $ paramName ] ) ) { $ param [ $ paramName ] = [ $ param [ $ paramName ] ] ; } $ param [ $ paramName ] [ ] = $ paramValue ; $ param [ $ paramName ] = array_unique ( $ param [ $ paramName ] ) ; } $ value [ 'query' ] = http_build_query ( $ param ) ; $ scheme = isset ( $ value [ 'scheme' ] ) ? $ value [ 'scheme' ] . '://' : '' ; $ host = isset ( $ value [ 'host' ] ) ? $ value [ 'host' ] : '' ; $ port = isset ( $ value [ 'port' ] ) ? ':' . $ value [ 'port' ] : '' ; $ user = isset ( $ value [ 'user' ] ) ? $ value [ 'user' ] : '' ; $ pass = isset ( $ value [ 'pass' ] ) ? ':' . $ value [ 'pass' ] : '' ; $ pass = ( $ user || $ pass ) ? "$pass@" : '' ; $ path = isset ( $ value [ 'path' ] ) ? $ value [ 'path' ] : '' ; $ query = isset ( $ value [ 'query' ] ) ? '?' . $ value [ 'query' ] : '' ; $ fragment = isset ( $ value [ 'fragment' ] ) ? '#' . $ value [ 'fragment' ] : '' ; return $ scheme . $ user . $ pass . $ host . $ port . $ path . $ query . $ fragment ; }
Adds a given query parameter value to the URL. If the parameter already
exists in the query, it's turned into an array.
@param string $value URL to be transformed
@param string $paramName query parameter name
@param string $paramValue query parameter value
@return string
Adds a given query parameter value to the URL . If the parameter already exists in the query it s turned into an array .