PlatformInfo.php in Acquia Purge 8
File
src/AcquiaCloud/PlatformInfo.php
View source
<?php
namespace Drupal\acquia_purge\AcquiaCloud;
use Drupal\Core\DrupalKernel;
use Drupal\Core\Site\Settings;
use Drupal\Core\State\StateInterface;
use Symfony\Component\HttpFoundation\RequestStack;
class PlatformInfo implements PlatformInfoInterface {
const AH_INFO_FUNCTION = 'ah_site_info_keyed';
protected $balancerAddresses = [];
protected $balancerToken = '';
protected $platformCdn = [];
protected $isThisAcquiaCloud = FALSE;
protected $siteEnvironment = '';
protected $siteGroup = '';
protected $siteIdentifier = '';
protected $siteName = '';
protected $sitePath = '';
public function __construct(RequestStack $request_stack, Settings $settings, StateInterface $state) {
$this->sitePath = DrupalKernel::findSitePath($request_stack
->getCurrentRequest());
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;
}
}
}
$function = self::AH_INFO_FUNCTION;
if (function_exists($function)) {
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;
}
$this->balancerToken = $this->siteName;
if (is_string($token = $settings
->get('acquia_purge_token'))) {
if ($token) {
$this->balancerToken = $token;
}
}
$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';
}
$this->siteIdentifier = Hash::siteIdentifier($this->siteName, $this->sitePath);
$this->isThisAcquiaCloud = is_array($this->balancerAddresses) && $this->balancerToken && $this->siteEnvironment && $this->siteIdentifier && $this->siteName && $this->siteGroup;
}
public function getBalancerAddresses() {
return $this->balancerAddresses;
}
public function getBalancerToken() {
return $this->balancerToken;
}
public function getPlatformCdnConfiguration() {
if (empty($this->platformCdn)) {
throw new \RuntimeException("No Platform CDN configuration available.");
}
if (!(isset($this->platformCdn['vendor']) && strlen($this->platformCdn['vendor']))) {
throw new \RuntimeException("Platform CDN vendor not specified.");
}
if (!(isset($this->platformCdn['config']) && strlen($this->platformCdn['config']))) {
throw new \RuntimeException("Platform CDN config has no 'config' key.");
}
return $this->platformCdn;
}
public function getSiteEnvironment() {
return $this->siteEnvironment;
}
public function getSiteGroup() {
return $this->siteGroup;
}
public function getSiteIdentifier() {
return $this->siteIdentifier;
}
public function getSiteName() {
return $this->siteName;
}
public function getSitePath() {
return $this->sitePath;
}
public function isThisAcquiaCloud() {
return $this->isThisAcquiaCloud;
}
}
Classes
Name |
Description |
PlatformInfo |
Provides an information object interfacing with the Acquia platform. |