class BackendFactory in Acquia Purge 8
Provides a backend for the Platform CDN purger.
Hierarchy
- class \Drupal\acquia_purge\AcquiaPlatformCdn\BackendFactory
Expanded class hierarchy of BackendFactory
3 files declare their use of BackendFactory
- AcquiaPlatformCdnCheck.php in src/
Plugin/ Purge/ DiagnosticCheck/ AcquiaPlatformCdnCheck.php - AcquiaPlatformCdnPurger.php in src/
Plugin/ Purge/ Purger/ AcquiaPlatformCdnPurger.php - AcquiaPlatformCdnTagsHeader.php in src/
Plugin/ Purge/ TagsHeader/ AcquiaPlatformCdnTagsHeader.php
File
- src/
AcquiaPlatformCdn/ BackendFactory.php, line 13
Namespace
Drupal\acquia_purge\AcquiaPlatformCdnView source
class BackendFactory {
/**
* Backends for Platform CDN vendors.
*
* @var string[]
*/
protected static $backendClasses = [
'fastly' => FastlyBackend::class,
];
/**
* Get a instantiated Platform CDN purger backend.
*
* @param \Drupal\acquia_purge\AcquiaCloud\PlatformInfoInterface $platforminfo
* Information object interfacing with the Acquia platform.
* @param \Drupal\purge\Logger\LoggerChannelPartInterface $logger
* The logger passed to the Platform CDN purger.
* @param \Drupal\acquia_purge\Plugin\Purge\Purger\DebuggerInterface $debugger
* The centralized debugger for Acquia purger plugins.
* @param \GuzzleHttp\ClientInterface $http_client
* An HTTP client that can perform remote requests.
*
* @return null|\Drupal\acquia_purge\AcquiaPlatformCdn\BackendInterface
* The instantiated backend or NULL in case of failure.
*/
public static function get(PlatformInfoInterface $platforminfo, LoggerChannelPartInterface $logger, DebuggerInterface $debugger, ClientInterface $http_client) {
if (!($backend_config = self::getConfig($platforminfo))) {
return NULL;
}
if (!($backend_class = self::getClassFromConfig($backend_config))) {
return NULL;
}
if (!$backend_class::validateConfiguration($backend_config)) {
return NULL;
}
return new $backend_class($backend_config, $platforminfo, $logger, $debugger, $http_client);
}
/**
* Get the CDN configuration array.
*
* @param \Drupal\acquia_purge\AcquiaCloud\PlatformInfoInterface $platforminfo
* Information object interfacing with the Acquia platform.
*
* @return array|null
* NULL when unconfigured, or associative array with arbitrary settings
* coming from:
* \Drupal\acquia_purge\AcquiaCloud\PlatformInfoInterface::getPlatformCdnConfiguration
*/
public static function getConfig(PlatformInfoInterface $platforminfo) {
try {
return $platforminfo
->getPlatformCdnConfiguration();
} catch (\RuntimeException $e) {
return NULL;
}
}
/**
* Get the backend class based on platform configuration.
*
* @param \Drupal\acquia_purge\AcquiaCloud\PlatformInfoInterface $platforminfo
* Information object interfacing with the Acquia platform.
*
* @return string|null
* Class providing the Platform CDN purger backend, or NULL if unconfigured.
*/
public static function getClass(PlatformInfoInterface $platforminfo) {
if ($config = self::getConfig($platforminfo)) {
return self::getClassFromConfig($config);
}
return NULL;
}
/**
* Get the backend class from the Platform CDN configuration array.
*
* @param array $config
* Acquia Platform CDN configuration settings.
*
* @return string|null
* Class providing the Platform CDN purger backend, or NULL if unconfigured.
*/
public static function getClassFromConfig(array $config) {
if (isset(self::$backendClasses[$config['vendor']])) {
return self::$backendClasses[$config['vendor']];
}
return NULL;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BackendFactory:: |
protected static | property | Backends for Platform CDN vendors. | |
BackendFactory:: |
public static | function | Get a instantiated Platform CDN purger backend. | |
BackendFactory:: |
public static | function | Get the backend class based on platform configuration. | |
BackendFactory:: |
public static | function | Get the backend class from the Platform CDN configuration array. | |
BackendFactory:: |
public static | function | Get the CDN configuration array. |