You are here

class Edgescape in Akamai 8.3

Provides help for working with Akamai Edgescape.

Hierarchy

Expanded class hierarchy of Edgescape

See also

https://developer.akamai.com/edgescape

3 files declare their use of Edgescape
ConfigForm.php in src/Form/ConfigForm.php
EdgescapeTest.php in tests/src/Functional/EdgescapeTest.php
EdgescapeTest.php in tests/src/Unit/Helper/EdgescapeTest.php
2 string references to 'Edgescape'
akamai.services.yml in ./akamai.services.yml
akamai.services.yml
akamai_token_info in ./akamai.module
Implements hook_token_info().
1 service uses Edgescape
akamai.helper.edgescape in ./akamai.services.yml
Drupal\akamai\Helper\Edgescape

File

src/Helper/Edgescape.php, line 14

Namespace

Drupal\akamai\Helper
View source
class Edgescape {
  const EDGESCAPE_HEADER = 'X-Akamai-Edgescape';
  const AKAMAI_SETTINGS = 'akamai.settings';
  const EDGESCAPE_SUPPORT = 'edgescape_support';
  const EMPTY_STRING = '';
  const EDGESCAPE_SEPARATOR = ',';
  const ARG_SEPARATOR = '&';

  /**
   * The config factory service.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * The current request.
   *
   * @var \Symfony\Component\HttpFoundation\Request
   */
  protected $request;

  /**
   * Constructs an Edgescape helper object.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory service.
   * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
   *   The request stack service.
   */
  public function __construct(ConfigFactoryInterface $config_factory, RequestStack $request_stack) {
    $this->configFactory = $config_factory;
    $this->request = $request_stack
      ->getCurrentRequest();
  }

  /**
   * Get Edgecape information by type.
   *
   * @param string $type
   *   An Edgescape location information type identifier string.
   *
   * @return string
   *   A string containing Edgescape location information, if available.
   */
  public function getInformationByType($type) {
    $info = self::EMPTY_STRING;
    $enabled = $this->configFactory
      ->get(self::AKAMAI_SETTINGS)
      ->get(self::EDGESCAPE_SUPPORT);
    if ($enabled && ($header = $this->request->headers
      ->get(self::EDGESCAPE_HEADER, self::EMPTY_STRING))) {
      $header = strtr($header, self::EDGESCAPE_SEPARATOR, self::ARG_SEPARATOR);
      $header_values = [];
      parse_str($header, $header_values);
      if (array_key_exists($type, $header_values)) {
        $info = Html::escape($header_values[(string) $type]);
      }
    }
    return $info;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Edgescape::$configFactory protected property The config factory service.
Edgescape::$request protected property The current request.
Edgescape::AKAMAI_SETTINGS constant
Edgescape::ARG_SEPARATOR constant
Edgescape::EDGESCAPE_HEADER constant
Edgescape::EDGESCAPE_SEPARATOR constant
Edgescape::EDGESCAPE_SUPPORT constant
Edgescape::EMPTY_STRING constant
Edgescape::getInformationByType public function Get Edgecape information by type.
Edgescape::__construct public function Constructs an Edgescape helper object.