src/Http/Psr7/RequestTrait.php
public function withRequestTarget($requestTarget)
    {
        $request = clone $this;
        if (preg_match('~^(?:[a-z]+:)?//~i', $requestTarget)) {
            $result = parse_url($requestTarget);
            if (isset($result['user'])) {
                $result['username'] = $result['user'];
                unset($result['user']);
            }
            if (isset($result['pass'])) {
                $result['password'] = $result['pass'];
                unset($result['pass']);
            }
            foreach ($result as $method => $value) {
                $request->$method($value);
            }
            $request->mode('absolute');
            return $request;
        }
        if (preg_match("~^(?:(?P<username>[^:]+)(?::(?P<password>[^@]+))?@)?(?P<host>[^/]+)$~", $requestTarget, $matches)) {
            $request->username($matches['username'] ?: null);
            $request->password($matches['password'] ?: null);
            $request->host($matches['host']);
            $request->mode('authority');
            return $request;
        }
        if ($requestTarget === '*') {
            $request->mode('asterisk');
            return $request;
        }
        $parts = explode('#', $requestTarget);
        if (isset($parts[1])) {
            $request->fragment($parts[1]);
        }
        $parts = explode('?', $parts[0]);
        if (isset($parts[1])) {
            $request->query($parts[1]);
        }
        $request->path($parts[0]);
        return $request;
    }
public function withRequestTarget($requestTarget)
    {
        $request = clone $this;
        if (preg_match('~^(?:[a-z]+:)?//~i', $requestTarget)) {
            $result = parse_url($requestTarget);
            if (isset($result['user'])) {
                $result['username'] = $result['user'];
                unset($result['user']);
            }
            if (isset($result['pass'])) {
                $result['password'] = $result['pass'];
                unset($result['pass']);
            }
            foreach ($result as $method => $value) {
                $request->$method($value);
            }
            $request->mode('absolute');
            return $request;
        }
        if (preg_match("~^(?:(?P<username>[^:]+)(?::(?P<password>[^@]+))?@)?(?P<host>[^/]+)$~", $requestTarget, $matches)) {
            $request->username($matches['username'] ?: null);
            $request->password($matches['password'] ?: null);
            $request->host($matches['host']);
            $request->mode('authority');
            return $request;
        }
        if ($requestTarget === '*') {
            $request->mode('asterisk');
            return $request;
        }
        $parts = explode('#', $requestTarget);
        if (isset($parts[1])) {
            $request->fragment($parts[1]);
        }
        $parts = explode('?', $parts[0]);
        if (isset($parts[1])) {
            $request->query($parts[1]);
        }
        $request->path($parts[0]);
        return $request;
    }
public function withRequestTarget ( $ requestTarget ) { $ request = clone $ this ; if ( preg_match ( '~^(?:[a-z]+:)?//~i' , $ requestTarget ) ) { $ result = parse_url ( $ requestTarget ) ; if ( isset ( $ result [ 'user' ] ) ) { $ result [ 'username' ] = $ result [ 'user' ] ; unset ( $ result [ 'user' ] ) ; } if ( isset ( $ result [ 'pass' ] ) ) { $ result [ 'password' ] = $ result [ 'pass' ] ; unset ( $ result [ 'pass' ] ) ; } foreach ( $ result as $ method => $ value ) { $ request -> $ method ( $ value ) ; } $ request -> mode ( 'absolute' ) ; return $ request ; } if ( preg_match ( "~^(?:(?P<username>[^:]+)(?::(?P<password>[^@]+))?@)?(?P<host>[^/]+)$~" , $ requestTarget , $ matches ) ) { $ request -> username ( $ matches [ 'username' ] ? : null ) ; $ request -> password ( $ matches [ 'password' ] ? : null ) ; $ request -> host ( $ matches [ 'host' ] ) ; $ request -> mode ( 'authority' ) ; return $ request ; } if ( $ requestTarget === '*' ) { $ request -> mode ( 'asterisk' ) ; return $ request ; } $ parts = explode ( '#' , $ requestTarget ) ; if ( isset ( $ parts [ 1 ] ) ) { $ request -> fragment ( $ parts [ 1 ] ) ; } $ parts = explode ( '?' , $ parts [ 0 ] ) ; if ( isset ( $ parts [ 1 ] ) ) { $ request -> query ( $ parts [ 1 ] ) ; } $ request -> path ( $ parts [ 0 ] ) ; return $ request ; }
Returns a new instance with the specific request-target.

If the request needs a non-origin-form request-target — e.g., for
specifying an absolute-form, authority-form, or asterisk-form —
this method may be used to create an instance with the specified
request-target, verbatim.

@link http://tools.ietf.org/html/rfc7230#section-2.7

@param  mixed $requestTarget
@return self
Returns a new instance with the specific request - target .