You are here

function saml_sp_requirements in SAML Service Provider 7.3

Same name and namespace in other branches
  1. 7.8 saml_sp.module \saml_sp_requirements()
  2. 7.2 saml_sp.module \saml_sp_requirements()

Implements hook_requirements().

File

./saml_sp.module, line 355
SAML Service Provider

Code

function saml_sp_requirements($phase) {
  $requirements = array();
  if ($phase == 'runtime') {
    $t = get_t();

    // php-saml library
    $library = libraries_detect('php-saml');
    $error_type = isset($library['error']) ? drupal_ucfirst($library['error']) : '';
    $error_message = isset($library['error message']) ? $library['error message'] : '';
    if (empty($library['installed'])) {
      $requirements['php_saml_library'] = array(
        'title' => $t('PHP SAML library'),
        'value' => $t('@e: At least @a', array(
          '@e' => $error_type,
          '@a' => PHP_SAML_LIBRARY_MIN_VERSION,
        )),
        'severity' => REQUIREMENT_ERROR,
        'description' => $t('!error You need to download the !library, extract the archive and place the !machine_name directory in the %path directory on your server.', array(
          '!error' => $error_message,
          '!library' => l($t('PHP SAML library'), $library['download url']),
          '%path' => 'sites/all/libraries',
          '!machine_name' => $library['machine name'],
        )),
      );
    }
    elseif (version_compare($library['version'], PHP_SAML_LIBRARY_MIN_VERSION, '>=')) {
      $requirements['php_saml_library'] = array(
        'title' => $t($library['name']),
        'severity' => REQUIREMENT_OK,
        'value' => $library['version'],
      );
    }
    else {
      $requirements['php_saml_library'] = array(
        'title' => $t($library['name']),
        'value' => $t('At least @a', array(
          '@a' => PHP_SAML_LIBRARY_MIN_VERSION,
        )),
        'severity' => REQUIREMENT_ERROR,
        'description' => $t('You need to download a later version of the !library and replace the old version (%current_version) located in the %path directory on your server.', array(
          '!library' => l($t('PHP SAML library'), $library['download url']),
          '%path' => $library['library path'],
          '%current_version' => $library['version'],
        )),
      );
    }
    $php_saml = $library;
    $library = libraries_detect('xmlseclibs');
    $error_type = isset($library['error']) ? drupal_ucfirst($library['error']) : '';
    $error_message = isset($library['error message']) ? $library['error message'] : '';
    if (!version_compare($php_saml['version'], 3, '<')) {
      if (empty($library['installed'])) {

        // xmlseclibs isn't installed
        $requirements['xmlseclibs'] = array(
          'title' => $t($library['name']),
          'value' => $t('@e: At least @a', array(
            '@e' => $error_type,
            '@a' => PHP_SAML_LIBRARY_MIN_VERSION,
          )),
          'severity' => REQUIREMENT_ERROR,
          'description' => $t('!error You need to download the !library, extract the archive and place the !machine_name directory in the %path directory on your server.', array(
            '!error' => $error_message,
            '!library' => l($library['name'], $library['download url']),
            '%path' => 'sites/all/libraries',
            '!machine_name' => $library['machine name'],
          )),
        );
      }
      elseif (version_compare($library['version'], 3, '>=')) {
        $requirements['xmlseclibs'] = array(
          'title' => $t($library['name']),
          'severity' => REQUIREMENT_OK,
          'value' => $library['version'],
        );
      }
      else {
        $requirements['xmlseclibs'] = array(
          'title' => $t($library['name']),
          'value' => $t('At least @a', array(
            '@a' => 3,
          )),
          'severity' => REQUIREMENT_ERROR,
          'description' => $t('You need to download a later version of the !library and replace the old version (%current_version) located in the %path directory on your server.', array(
            '!library' => l($library['name'], $library['download url']),
            '%path' => $library['library path'],
            '%current_version' => $library['version'],
          )),
        );
      }
    }
  }
  return $requirements;
}