You are here

public function ZeroConfigPurger::__construct in Varnish purger 8.2

Constructs a ZeroConfigPurger object.

Parameters

\Drupal\Core\Site\Settings $settings: The site settings to load reverse proxy addresses from.

\GuzzleHttp\ClientInterface $http_client: An HTTP client that can perform remote requests.

array $configuration: A configuration array containing information about the plugin instance.

string $plugin_id: The plugin_id for the plugin instance.

mixed $plugin_definition: The plugin implementation definition.

Overrides PurgerBase::__construct

File

src/Plugin/Purge/Purger/ZeroConfigPurger.php, line 96

Class

ZeroConfigPurger
A purger with minimal configuration required.

Namespace

Drupal\varnish_purger\Plugin\Purge\Purger

Code

public function __construct(Settings $settings, ClientInterface $http_client, array $configuration, $plugin_id, $plugin_definition) {
  parent::__construct($configuration, $plugin_id, $plugin_definition);

  // Take the IP addresses from the 'reverse_proxies' setting.
  if (is_array($reverse_proxies = $settings
    ->get('reverse_proxy_addresses'))) {
    foreach ($reverse_proxies as $reverse_proxy) {
      if ($reverse_proxy && strpos($reverse_proxy, '.')) {
        $this->reverseProxies[] = $reverse_proxy;
      }
    }
  }

  // Drupal's reverse proxy addresses only supports addresses and not ports.
  // For tests, we need to run Apache on the same host as Varnish, so we need
  // a way to set an alternate port.
  if ($port = $settings
    ->get('varnish_purge_zeroconfig_port')) {
    $this->proxyPort = $port;
  }
  $this->client = $http_client;
}