vendor/ibexa/http-cache/src/lib/ProxyClient/Varnish.php line 26

Open in your IDE?
  1. <?php
  2. /**
  3. * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4. * @license For full copyright and license information view LICENSE file distributed with this source code.
  5. */
  6. declare(strict_types=1);
  7. namespace Ibexa\HttpCache\ProxyClient;
  8. use FOS\HttpCache\ProxyClient\Dispatcher;
  9. use FOS\HttpCache\ProxyClient\Invalidation\BanCapable;
  10. use FOS\HttpCache\ProxyClient\Invalidation\PurgeCapable;
  11. use FOS\HttpCache\ProxyClient\Invalidation\RefreshCapable;
  12. use FOS\HttpCache\ProxyClient\Invalidation\TagCapable;
  13. use FOS\HttpCache\ProxyClient\Varnish as FosVarnish;
  14. use Http\Message\RequestFactory;
  15. use Ibexa\Bundle\HttpCache\Controller\InvalidateTokenController;
  16. use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
  17. final class Varnish extends FosVarnish implements BanCapable, PurgeCapable, RefreshCapable, TagCapable
  18. {
  19. /** @var \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface */
  20. private $configResolver;
  21. public function __construct(
  22. ConfigResolverInterface $configResolver,
  23. Dispatcher $httpDispatcher,
  24. array $options = [],
  25. ?RequestFactory $messageFactory = null
  26. ) {
  27. parent::__construct($httpDispatcher, $options, $messageFactory);
  28. $this->configResolver = $configResolver;
  29. }
  30. private function fetchAndMergeAuthHeaders(array $headers): array
  31. {
  32. $invalidateToken = $this->getInvalidateToken();
  33. if (null !== $invalidateToken) {
  34. $headers[InvalidateTokenController::TOKEN_HEADER_NAME] = $invalidateToken;
  35. }
  36. return $headers;
  37. }
  38. private function getInvalidateToken(): ?string
  39. {
  40. if ($this->configResolver->hasParameter('http_cache.varnish_invalidate_token')) {
  41. return $this->configResolver->getParameter('http_cache.varnish_invalidate_token');
  42. }
  43. return null;
  44. }
  45. protected function queueRequest($method, $url, array $headers, $validateHost = true, $body = null)
  46. {
  47. parent::queueRequest($method, $url, $this->fetchAndMergeAuthHeaders($headers), $body);
  48. }
  49. }
  50. class_alias(Varnish::class, 'EzSystems\PlatformHttpCacheBundle\ProxyClient\Varnish');