You are here

function warden_requirements in Warden 8

Same name and namespace in other branches
  1. 8.2 warden.install \warden_requirements()
  2. 6 warden.install \warden_requirements()
  3. 7 warden.install \warden_requirements()
  4. 3.x warden.install \warden_requirements()

Implements hook_requirements().

File

./warden.install, line 11
Clean up file for warden

Code

function warden_requirements($phase) {
  $requirements = array();
  $ssl_available = function_exists('openssl_seal');
  $requirements['warden_openssl'] = array(
    'title' => t('Warden'),
    'value' => $ssl_available ? t('Open SSL is available') : t('Open SSL is not available'),
    'description' => t('The <a href="@url">PHP OpenSSL</a> extension needs to be available to communicate with Warden', array(
      '@url' => 'http://php.net/manual/en/openssl.installation.php',
    )),
    'severity' => $ssl_available ? REQUIREMENT_OK : REQUIREMENT_ERROR,
  );
  if ($phase == 'runtime') {
    $warden_available = FALSE;
    $error = '';
    $url = \Drupal::service('warden.manager')
      ->getWardenUrl();
    try {
      if (empty($url)) {
        throw new \Exception(t('Warden server URL is not configured. Read the README for more information.'));
      }
      \Drupal::service('warden.manager')
        ->getPublicKey();
      $warden_available = TRUE;
    } catch (\Exception $e) {
      $error = $e
        ->getMessage();
    }
    $requirements['warden_available'] = array(
      'title' => t('Warden available'),
      'value' => $warden_available ? t('The Warden server can be contacted') : t('The Warden server cannot be contacted'),
      'severity' => $warden_available ? REQUIREMENT_OK : REQUIREMENT_ERROR,
    );
    if (empty($warden_available)) {
      $requirements['warden_available']['description'] = t('Error message: :message', array(
        ':message' => $error,
      ));
    }
    else {
      $requirements['warden_available']['description'] = t('Configured Warden server URL: :url', array(
        ':url' => $url,
      ));
    }
  }
  return $requirements;
}