public function PlatformInfo::__construct in Acquia Purge 8
Constructs a PlatformInfo object.
Parameters
\Symfony\Component\HttpFoundation\RequestStack $request_stack: The request stack.
\Drupal\Core\Site\Settings $settings: Drupal site settings object.
\Drupal\Core\State\StateInterface $state: The state key value store.
File
- src/
AcquiaCloud/ PlatformInfo.php, line 101
Class
- PlatformInfo
- Provides an information object interfacing with the Acquia platform.
Namespace
Drupal\acquia_purge\AcquiaCloudCode
public function __construct(RequestStack $request_stack, Settings $settings, StateInterface $state) {
// Generate the Drupal sitepath by querying the SitePath from this request.
$this->sitePath = DrupalKernel::findSitePath($request_stack
->getCurrentRequest());
// Take the IP addresses from the 'reverse_proxies' setting.
if (is_array($reverse_proxies = $settings
->get('reverse_proxies'))) {
foreach ($reverse_proxies as $reverse_proxy) {
if ($reverse_proxy && strpos($reverse_proxy, '.')) {
$this->balancerAddresses[] = $reverse_proxy;
}
}
}
// Call the AH_INFO_FUNCTION and take the keys 'sitename' and 'sitegroup'.
$function = self::AH_INFO_FUNCTION;
if (function_exists($function)) {
// @phpstan-ignore-next-line
if (is_array($info = $function())) {
if (isset($info['environment'])) {
if (is_string($info['environment']) && $info['environment']) {
$this->siteEnvironment = $info['environment'];
}
}
if (isset($info['sitename'])) {
if (is_string($info['sitename']) && $info['sitename']) {
$this->siteName = $info['sitename'];
}
}
if (isset($info['sitegroup'])) {
if (is_string($info['sitegroup']) && $info['sitegroup']) {
$this->siteGroup = $info['sitegroup'];
}
}
}
}
elseif (!empty($GLOBALS['gardens_site_settings'])) {
$this->siteEnvironment = $GLOBALS['gardens_site_settings']['env'];
$this->siteGroup = $GLOBALS['gardens_site_settings']['site'];
$this->siteName = $this->siteGroup . '.' . $this->siteEnvironment;
}
// Determine the authentication token is going to be, usually the site name.
$this->balancerToken = $this->siteName;
if (is_string($token = $settings
->get('acquia_purge_token'))) {
if ($token) {
$this->balancerToken = $token;
}
}
// Retrieval of the Acquia Platform CDN configuration is implemented via
// a *temporary* hybrid implementation. For as long as the Platform CDN
// product is in beta, the configuration object can come via state, after
// that it will come through platform settings (which takes priority).
$cdn_asc = $settings
->get('acquia_service_credentials');
$cdn_state = (array) $state
->get('acquia_purge.platform_cdn', []);
if (isset($cdn_asc['platform_cdn']['vendor']) && isset($cdn_asc['platform_cdn']['configuration']) && strlen($cdn_asc['platform_cdn']['vendor']) && is_array($cdn_asc['platform_cdn']['configuration']) && count($cdn_asc['platform_cdn']['configuration'])) {
$this->platformCdn['config'] = 'settings';
$this->platformCdn['vendor'] = (string) $cdn_asc['platform_cdn']['vendor'];
$this->platformCdn = array_merge($this->platformCdn, $cdn_asc['platform_cdn']['configuration']);
}
elseif (isset($cdn_state['vendor']) && strlen($cdn_state['vendor']) && count($cdn_state) > 2) {
$this->platformCdn = $cdn_state;
$this->platformCdn['config'] = 'state';
}
// Use the sitename and site path directory as site identifier.
$this->siteIdentifier = Hash::siteIdentifier($this->siteName, $this->sitePath);
// Test the gathered information to determine if this is/isn't Acquia Cloud.
$this->isThisAcquiaCloud = is_array($this->balancerAddresses) && $this->balancerToken && $this->siteEnvironment && $this->siteIdentifier && $this->siteName && $this->siteGroup;
}