awssdk.module in AWS SDK for PHP 7.4
Same filename and directory in other branches
Provides primary Drupal hook implementations.
@author Jimmy Berry ("boombatower", http://drupal.org/user/214218)
File
awssdk.moduleView 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'), 'admin/reports/awssdk') . ']',
);
// Instead of calling the CLI script in a separate process to check for
// compatibility load the capatiblity test in the same process to ensure it
// uses the same configuration as Drupal.
ob_start();
include $info['library path'] . '/_compatibility_test/sdk_compatibility_test_cli.php';
$compatible = strpos(ob_get_clean(), '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($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() {
// Attempt to load the sample configuration file provided with AWSSDK.
if (file_exists($sample_config = libraries_get_path('awssdk') . '/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[strtolower($match[1])] = eval('return ' . $match[2] . ';');
}
return $defaults;
}
}
return FALSE;
}
/**
* Implements hook_menu()
*/
function awssdk_menu() {
$items['admin/reports/awssdk'] = array(
'page callback' => 'awssdk_report',
'page arguments' => array(
libraries_get_path('awssdk') . '/_compatibility_test/sdk_compatibility_test.php',
),
'access arguments' => array(
'access site reports',
),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Provide a function to wrap the require construct to be used as menu callback.
*/
function awssdk_report($file) {
require $file;
}
Functions
Name | 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_menu | Implements hook_menu() |
awssdk_report | Provide a function to wrap the require construct to be used as menu callback. |
awssdk_requirements | Implements hook_requirements() |