You are here

awssdk.module in AWS SDK for PHP 7.3

Same filename and directory in other branches
  1. 7.5 awssdk.module
  2. 7.2 awssdk.module
  3. 7.4 awssdk.module

Provides primary Drupal hook implementations.

@author Jimmy Berry ("boombatower", http://drupal.org/user/214218)

File

awssdk.module
View source
<?php

/**
 * @file
 * Provides primary Drupal hook implementations.
 *
 * @author Jimmy Berry ("boombatower", http://drupal.org/user/214218)
 */

/**
 * Implements hook_libraries_info()
 */
function awssdk_libraries_info() {
  return array(
    'awssdk' => array(
      'title' => 'AWS SDK for PHP',
      'vendor url' => 'http://aws.amazon.com/sdkforphp/',
      'download url' => 'http://aws.amazon.com/sdkforphp/',
      'version arguments' => array(
        'file' => 'sdk.class.php',
        'pattern' => "/define\\('CFRUNTIME_VERSION', '(\\d+\\.\\d+(\\.\\d+)?)'\\);/",
        'lines' => 200,
      ),
      'files' => array(
        'php' => array(
          'sdk.class.php',
        ),
      ),
      'integration files' => array(
        'awssdk' => array(
          'php' => array(
            'config.inc',
          ),
        ),
      ),
    ),
  );
}

/**
 * Implements hook_requirements()
 */
function awssdk_requirements() {
  $t = get_t();
  $requirements = array();
  $info = libraries_load('awssdk');
  if (!$info['loaded']) {
    $requirements['awssdk'] = array(
      'severity' => REQUIREMENT_ERROR,
      'title' => $t('AWSSDK'),
      'value' => $t('Failed to load the AWSSDK'),
      'description' => $t('Please make sure the AWSSDK library is installed in the libraries directory. Use the drush make file for easy installation.'),
    );
  }
  else {
    global $base_url;
    $requirements['awssdk'] = array(
      'severity' => REQUIREMENT_OK,
      'title' => $t('AWSSDK'),
      'value' => $info['version'] . ' [' . l(t('compatibility test'), $base_url . '/' . $info['library path'] . '/_compatibility_test/sdk_compatibility_test.php', array(
        'external' => TRUE,
      )) . ']',
    );
    $compatible = strpos(shell_exec('php ' . $info['library path'] . '/_compatibility_test/sdk_compatibility_test_cli.php'), 'Bottom Line: Yes, you can!') !== FALSE;
    if (!$compatible) {
      $requirements['awssdk']['severity'] = REQUIREMENT_ERROR;
      $requirements['awssdk']['description'] = $t('Your PHP environment does not support the minimum requirements for the AWS SDK for PHP.');
    }
  }
  return $requirements;
}

/**
 * Load the default AWSSDK settings and apply variable overrides.
 *
 * @return
 *   An associative array containing AWSSDK setting values.
 */
function awssdk_config_load() {
  if (!($config =& drupal_static(__FUNCTION__))) {
    $config = ($cache = cache_get(__FUNCTION__)) ? $cache->data : array();
  }
  if (!$config) {
    if ($defaults = awssdk_config_defaults()) {
      foreach ($defaults as $key => $value) {
        if ($override = variable_get(strtolower($key))) {
          $value = $override;
        }
        $config[$key] = $value;
      }
    }
    cache_set(__FUNCTION__, $config);
  }
  return $config;
}

/**
 * Load the default AWSSDK settings.
 *
 * @return
 *   An associative array containing default settings, or FALSE.
 */
function awssdk_config_defaults() {
  $info = libraries_load('awssdk');

  // Attempt to load the sample configuration file provided with AWSSDK.
  if (file_exists($sample_config = $info['library path'] . '/config-sample.inc.php')) {

    // Use a regular expression to determine the default values for the
    // configuration constants instead of including the file so that the
    // constants are never defined in the current process to prevent possible
    // conflicts that might occur if caches are cleared when the AWSSDK is
    // attempting to be used.
    $contents = file_get_contents($sample_config);
    if (preg_match_all("/define\\('(\\w+)', (.*)\\);/", $contents, $matches, PREG_SET_ORDER)) {
      $defaults = array();
      foreach ($matches as $match) {
        $defaults[$match[1]] = eval('return ' . $match[2] . ';');
      }
      return $defaults;
    }
  }
  return FALSE;
}

Functions

Namesort descending Description
awssdk_config_defaults Load the default AWSSDK settings.
awssdk_config_load Load the default AWSSDK settings and apply variable overrides.
awssdk_libraries_info Implements hook_libraries_info()
awssdk_requirements Implements hook_requirements()