function _s3fs_validate_config in S3 File System 7.3
Same name and namespace in other branches
- 7 s3fs.module \_s3fs_validate_config()
- 7.2 s3fs.module \_s3fs_validate_config()
Checks all the configuration options to ensure that they're valid.
Parameters
array $config: An s3fs configuration array.
Return value
bool TRUE if config is good to go, otherwise FALSE.
4 calls to _s3fs_validate_config()
- drush_s3fs_copy_local in ./
s3fs.drush.inc - Copys all files from the local public/private filesystem folders into S3, if s3fs is configured to take over those systems.
- drush_s3fs_refresh_cache in ./
s3fs.drush.inc - Refreshes the file metadata cache.
- s3fs_settings_validate in ./
s3fs.admin.inc - Validates the values on the admin form.
- _s3fs_refresh_cache in ./
s3fs.module - Refreshes the metadata cache.
File
- ./
s3fs.module, line 302 - Hook implementations and other primary functionality for S3 File System.
Code
function _s3fs_validate_config($config) {
if (!empty($config['use_customhost']) && empty($config['hostname'])) {
form_set_error('s3fs_hostname', 'You must specify a Hostname to use the Custom Host feature.');
return FALSE;
}
if (!empty($config['use_cname']) && empty($config['domain'])) {
form_set_error('s3fs_domain', 'You must specify a CDN Domain Name to use the CNAME feature.');
return FALSE;
}
switch ($config['domain_root']) {
case 'root':
if (empty($config['root_folder'])) {
form_set_error('s3fs_root_folder', 'You must specify a Root folder to map the Domain Name to it.');
return FALSE;
}
break;
case 'public':
if (empty($config['public_folder'])) {
form_set_error('s3fs_public_folder', 'You must specify a Public folder to map the Domain Name to it.');
return FALSE;
}
elseif (!empty($config['root_folder'])) {
form_set_error('s3fs_root_folder', 'For the Public folder option, the Root folder must be blank. Otherwise, use the "Root & Public folders" option.');
return FALSE;
}
break;
case 'root_public':
if (empty($config['root_folder']) || empty($config['public_folder'])) {
form_set_error('s3fs_domain_root', 'You must specify both Root and Public folders to map the Domain Name to it.');
return FALSE;
}
break;
}
try {
$s3 = _s3fs_get_amazons3_client($config);
} catch (S3fsException $e) {
form_set_error('form', $e
->getMessage());
return FALSE;
}
// Test the connection to S3, and the bucket name.
try {
$list_obj_args = array(
'Bucket' => $config['bucket'],
'MaxKeys' => 1,
);
if (!empty($config['root_folder'])) {
// If the root_folder option has been set, retrieve from S3 only those files
// which reside in the root folder.
$list_obj_args['Prefix'] = "{$config['root_folder']}/";
}
// listObjects() will trigger descriptive exceptions if the credentials,
// bucket name, or region are invalid/mismatched.
$s3
->listObjects($list_obj_args);
} catch (S3Exception $e) {
form_set_error('form', t('An unexpected %exception occurred, with the following error message:<br>%error', array(
'%exception' => $e
->getAwsErrorCode(),
'%error' => $e
->getMessage(),
)));
return FALSE;
}
return TRUE;
}