Deprecated: Constant E_STRICT is deprecated in /home/pastorz/old-espace-client/vendor/symfony/error-handler/ErrorHandler.php on line 58

Deprecated: Constant E_STRICT is deprecated in /home/pastorz/old-espace-client/vendor/symfony/error-handler/ErrorHandler.php on line 76
Symfony Profiler

vendor/symfony/http-client/ScopingHttpClient.php line 46

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\HttpClient;
  11. use Psr\Log\LoggerAwareInterface;
  12. use Psr\Log\LoggerInterface;
  13. use Symfony\Component\HttpClient\Exception\InvalidArgumentException;
  14. use Symfony\Contracts\HttpClient\HttpClientInterface;
  15. use Symfony\Contracts\HttpClient\ResponseInterface;
  16. use Symfony\Contracts\HttpClient\ResponseStreamInterface;
  17. use Symfony\Contracts\Service\ResetInterface;
  18. /**
  19.  * Auto-configure the default options based on the requested URL.
  20.  *
  21.  * @author Anthony Martin <anthony.martin@sensiolabs.com>
  22.  */
  23. class ScopingHttpClient implements HttpClientInterfaceResetInterfaceLoggerAwareInterface
  24. {
  25.     use HttpClientTrait;
  26.     private $client;
  27.     private $defaultOptionsByRegexp;
  28.     private $defaultRegexp;
  29.     public function __construct(HttpClientInterface $client, array $defaultOptionsByRegexpstring $defaultRegexp null)
  30.     {
  31.         $this->client $client;
  32.         $this->defaultOptionsByRegexp $defaultOptionsByRegexp;
  33.         $this->defaultRegexp $defaultRegexp;
  34.         if (null !== $defaultRegexp && !isset($defaultOptionsByRegexp[$defaultRegexp])) {
  35.             throw new InvalidArgumentException(sprintf('No options are mapped to the provided "%s" default regexp.'$defaultRegexp));
  36.         }
  37.     }
  38.     public static function forBaseUri(HttpClientInterface $clientstring $baseUri, array $defaultOptions = [], string $regexp null): self
  39.     {
  40.         if (null === $regexp) {
  41.             $regexp preg_quote(implode(''self::resolveUrl(self::parseUrl('.'), self::parseUrl($baseUri))));
  42.         }
  43.         $defaultOptions['base_uri'] = $baseUri;
  44.         return new self($client, [$regexp => $defaultOptions], $regexp);
  45.     }
  46.     /**
  47.      * {@inheritdoc}
  48.      */
  49.     public function request(string $methodstring $url, array $options = []): ResponseInterface
  50.     {
  51.         $e null;
  52.         $url self::parseUrl($url$options['query'] ?? []);
  53.         if (\is_string($options['base_uri'] ?? null)) {
  54.             $options['base_uri'] = self::parseUrl($options['base_uri']);
  55.         }
  56.         try {
  57.             $url implode(''self::resolveUrl($url$options['base_uri'] ?? null));
  58.         } catch (InvalidArgumentException $e) {
  59.             if (null === $this->defaultRegexp) {
  60.                 throw $e;
  61.             }
  62.             $defaultOptions $this->defaultOptionsByRegexp[$this->defaultRegexp];
  63.             $options self::mergeDefaultOptions($options$defaultOptionstrue);
  64.             if (\is_string($options['base_uri'] ?? null)) {
  65.                 $options['base_uri'] = self::parseUrl($options['base_uri']);
  66.             }
  67.             $url implode(''self::resolveUrl($url$options['base_uri'] ?? null$defaultOptions['query'] ?? []));
  68.         }
  69.         foreach ($this->defaultOptionsByRegexp as $regexp => $defaultOptions) {
  70.             if (preg_match("{{$regexp}}A"$url)) {
  71.                 if (null === $e || $regexp !== $this->defaultRegexp) {
  72.                     $options self::mergeDefaultOptions($options$defaultOptionstrue);
  73.                 }
  74.                 break;
  75.             }
  76.         }
  77.         return $this->client->request($method$url$options);
  78.     }
  79.     /**
  80.      * {@inheritdoc}
  81.      */
  82.     public function stream($responsesfloat $timeout null): ResponseStreamInterface
  83.     {
  84.         return $this->client->stream($responses$timeout);
  85.     }
  86.     public function reset()
  87.     {
  88.         if ($this->client instanceof ResetInterface) {
  89.             $this->client->reset();
  90.         }
  91.     }
  92.     /**
  93.      * {@inheritdoc}
  94.      */
  95.     public function setLogger(LoggerInterface $logger): void
  96.     {
  97.         if ($this->client instanceof LoggerAwareInterface) {
  98.             $this->client->setLogger($logger);
  99.         }
  100.     }
  101.     /**
  102.      * {@inheritdoc}
  103.      */
  104.     public function withOptions(array $options): self
  105.     {
  106.         $clone = clone $this;
  107.         $clone->client $this->client->withOptions($options);
  108.         return $clone;
  109.     }
  110. }