You are here

class ComposerDependenciesCheck in CloudFlare 8

Same name in this branch
  1. 8 src/ComposerDependenciesCheck.php \Drupal\cloudflare\ComposerDependenciesCheck
  2. 8 modules/cloudflarepurger/src/Plugin/Purge/DiagnosticCheck/ComposerDependenciesCheck.php \Drupal\cloudflarepurger\Plugin\Purge\DiagnosticCheck\ComposerDependenciesCheck

Tests that composer dependencies are met.

Hierarchy

Expanded class hierarchy of ComposerDependenciesCheck

1 string reference to 'ComposerDependenciesCheck'
cloudflare.services.yml in ./cloudflare.services.yml
cloudflare.services.yml
1 service uses ComposerDependenciesCheck
cloudflare.composer_dependency_check in ./cloudflare.services.yml
Drupal\cloudflare\ComposerDependenciesCheck

File

src/ComposerDependenciesCheck.php, line 11

Namespace

Drupal\cloudflare
View source
class ComposerDependenciesCheck implements CloudFlareComposerDependenciesCheckInterface {

  /**
   * Set the first time that this function is called in a bootstrap.
   *
   * @var bool
   */
  public static $areDependenciesMet = NULL;

  /**
   * A logger instance.
   *
   * @var \Psr\Log\LoggerInterface
   */
  protected $logger;

  /**
   * {@inheritdoc}
   */
  public static function create(LoggerInterface $logger) {
    return new static($logger);
  }

  /**
   * ComposerDependenciesCheck constructor.
   *
   * @param \Psr\Log\LoggerInterface $logger
   *   A logger instance.
   */
  public function __construct(LoggerInterface $logger) {
    $this->logger = $logger;
  }

  /**
   * {@inheritdoc}
   */
  public function check() {

    // This check will help prevent multiple redundant criticals from being
    // logged.
    if (!is_null(self::$areDependenciesMet)) {
      return self::$areDependenciesMet;
    }
    if (class_exists('\\CloudFlarePhpSdk\\ApiEndpoints\\ZoneApi')) {
      self::$areDependenciesMet = TRUE;
    }
    else {
      self::$areDependenciesMet = FALSE;
      $this->logger
        ->critical(self::ERROR_MESSAGE);
    }
    return self::$areDependenciesMet;
  }

  /**
   * {@inheritdoc}
   */
  public function assert() {
    if (!$this
      ->check()) {
      throw new ComposerDependencyException(self::ERROR_MESSAGE);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CloudFlareComposerDependenciesCheckInterface::ERROR_MESSAGE constant
ComposerDependenciesCheck::$areDependenciesMet public static property Set the first time that this function is called in a bootstrap.
ComposerDependenciesCheck::$logger protected property A logger instance.
ComposerDependenciesCheck::assert public function Asserts that composer dependencies for CloudFlare are met. Overrides CloudFlareComposerDependenciesCheckInterface::assert
ComposerDependenciesCheck::check public function Tests that composer dependencies for CloudFlare are met. Overrides CloudFlareComposerDependenciesCheckInterface::check
ComposerDependenciesCheck::create public static function
ComposerDependenciesCheck::__construct public function ComposerDependenciesCheck constructor.