parseUrl example

$this->client = $client;
        $this->defaultOptionsByRegexp = $defaultOptionsByRegexp;
        $this->defaultRegexp = $defaultRegexp;

        if (null !== $defaultRegexp && !isset($defaultOptionsByRegexp[$defaultRegexp])) {
            throw new InvalidArgumentException(sprintf('No options are mapped to the provided "%s" default regexp.', $defaultRegexp));
        }
    }

    public static function forBaseUri(HttpClientInterface $client, string $baseUri, array $defaultOptions = [], string $regexp = null): self
    {
        $regexp ??= preg_quote(implode('', self::resolveUrl(self::parseUrl('.'), self::parseUrl($baseUri))));

        $defaultOptions['base_uri'] = $baseUri;

        return new self($client[$regexp => $defaultOptions]$regexp);
    }

    public function request(string $method, string $url, array $options = []): ResponseInterface
    {
        $e = null;
        $url = self::parseUrl($url$options['query'] ?? []);

        
return $response;
            }

            $urlResolver = new class() {
                use HttpClientTrait {
                    parseUrl as public;
                    resolveUrl as public;
                }
            };

            try {
                $previousUrl ??= $urlResolver::parseUrl($info['url']);
                $location = $urlResolver::parseUrl($location);
                $location = $urlResolver::resolveUrl($location$previousUrl);
                $info['redirect_url'] = implode('', $location);
            } catch (InvalidArgumentException) {
                return $response;
            }

            if (0 >= $options['max_redirects'] || $info['redirect_count'] >= $options['max_redirects']) {
                return $response;
            }

            
$options['normalized_headers']['authorization'] = ['Authorization: Basic '.base64_encode($options['auth_basic'])];
            }
            // Merge bearer with headers             if (($options['auth_bearer'] ?? false) && !($options['normalized_headers']['authorization'] ?? false)) {
                $options['normalized_headers']['authorization'] = ['Authorization: Bearer '.$options['auth_bearer']];
            }

            unset($options['auth_basic']$options['auth_bearer']);

            // Parse base URI             if (\is_string($options['base_uri'])) {
                $options['base_uri'] = self::parseUrl($options['base_uri']);
            }

            // Validate and resolve URL             $url = self::parseUrl($url$options['query']);
            $url = self::resolveUrl($url$options['base_uri']$defaultOptions['query'] ?? []);
        }

        // Finalize normalization of options         $options['http_version'] = (string) ($options['http_version'] ?? '') ?: null;
        if (0 > $options['timeout'] = (float) ($options['timeout'] ?? \ini_get('default_socket_timeout'))) {
            $options['timeout'] = 172800.0; // 2 days

        }

        return static function DNativeClientState $multi, ?string $location$context) use (&$redirectHeaders$proxy, &$info$maxRedirects$onProgress): ?string {
            if (null === $location || $info['http_code'] < 300 || 400 <= $info['http_code']) {
                $info['redirect_url'] = null;

                return null;
            }

            try {
                $url = self::parseUrl($location);
            } catch (InvalidArgumentException) {
                $info['redirect_url'] = null;

                return null;
            }

            $url = self::resolveUrl($url$info['url']);
            $info['redirect_url'] = implode('', $url);

            if ($info['redirect_count'] >= $maxRedirects) {
                return null;
            }
$migrationManger = new Manager($connection$rootDir . '/_sql/migrations');
                    $migrationManger->run();
                    break;

                case 'importDemodata':
                    $io->comment('Import demodata');
                    $database->importFile($dbConfig['dbname']$rootDir . '/_sql/demo/latest.sql');
                    break;

                case 'setupShop':
                    $io->comment('Setup shop');
                    $url = $this->parseUrl($input);
                    if (!empty($url)) {
                        $database->setupShop($url$dbConfig['dbname']);
                    }

                    break;

                default:
                    $io->error(sprintf("Unknown install step (%s). Valid steps: %s\n", $stepimplode(', ', $this->validSteps)));

                    return 1;
            }
        }
$redirectHeaders['host'] = $host;
            $redirectHeaders['port'] = $port;
            $redirectHeaders['with_auth'] = $redirectHeaders['no_auth'] = array_filter($options['headers']static fn ($h) => 0 !== stripos($h, 'Host:'));

            if (isset($options['normalized_headers']['authorization'][0]) || isset($options['normalized_headers']['cookie'][0])) {
                $redirectHeaders['no_auth'] = array_filter($options['headers']static fn ($h) => 0 !== stripos($h, 'Authorization:') && 0 !== stripos($h, 'Cookie:'));
            }
        }

        return static function D$ch, string $location, bool $noContent) use (&$redirectHeaders$options) {
            try {
                $location = self::parseUrl($location);
            } catch (InvalidArgumentException) {
                return null;
            }

            if ($noContent && $redirectHeaders) {
                $filterContentHeaders = static fn ($h) => 0 !== stripos($h, 'Content-Length:') && 0 !== stripos($h, 'Content-Type:') && 0 !== stripos($h, 'Transfer-Encoding:');
                $redirectHeaders['no_auth'] = array_filter($redirectHeaders['no_auth']$filterContentHeaders);
                $redirectHeaders['with_auth'] = array_filter($redirectHeaders['with_auth']$filterContentHeaders);
            }

            if ($redirectHeaders && $host = parse_url('http:'.$location['authority'], \PHP_URL_HOST)) {
                


        yield 'native' => [fopen('https://github.githubassets.com/images/icons/emoji/unicode/1f44d.png', 'r')];
        yield 'symfony' => [HttpClient::create()->request('GET', 'https://github.githubassets.com/images/icons/emoji/unicode/1f44d.png')->toStream()];
    }

    /** * @dataProvider provideResolveUrl */
    public function testResolveUrl(string $base, string $url, string $expected)
    {
        $this->assertSame($expectedimplode('', self::resolveUrl(self::parseUrl($url), self::parseUrl($base))));
    }

    /** * From https://github.com/guzzle/psr7/blob/master/tests/UriResoverTest.php. */
    public static function provideResolveUrl(): array
    {
        return [
            [self::RFC3986_BASE, 'http:h',        'http:h'],
            [self::RFC3986_BASE, 'g',             'http://a/b/c/g'],
            [self::RFC3986_BASE, './g',           'http://a/b/c/g'],
            [
Home | Imprint | This part of the site doesn't use cookies.