private function LibrariesLoad::librariesDetect in X Autoload 7.5
Tries to detect a library and its installed version.
Parameters
$name: The machine name of a library to return registered information for.
Return value
array|false An associative array containing registered information for the library specified by $name, or FALSE if the library $name is not registered. In addition to the keys returned by libraries_info(), the following keys are contained:
- installed: A boolean indicating whether the library is installed. Note that not only the top-level library, but also each variant contains this key.
- version: If the version could be detected, the full version string.
- error: If an error occurred during library detection, one of the following error statuses: "not found", "not detected", "not supported".
- error message: If an error occurred during library detection, a detailed error message.
See also
1 call to LibrariesLoad::librariesDetect()
- LibrariesLoad::librariesLoad in tests/
src/ VirtualDrupal/ LibrariesLoad.php
File
- tests/
src/ VirtualDrupal/ LibrariesLoad.php, line 117
Class
Namespace
Drupal\xautoload\Tests\VirtualDrupalCode
private function librariesDetect($name) {
// Re-use the statically cached value of libraries_info() to save memory.
$library =& $this->librariesInfo
->getLibrariesInfo($name);
if ($library === FALSE) {
return $library;
}
// If 'installed' is set, library detection ran already.
if (isset($library['installed'])) {
return $library;
}
$library['installed'] = FALSE;
// Check whether the library exists.
if (!isset($library['library path'])) {
$library['library path'] = $this->librariesInfo
->librariesGetPath($library['machine name']);
}
if ($library['library path'] === FALSE || !file_exists($library['library path'])) {
$library['error'] = 'not found';
$library['error message'] = t('The %library library could not be found.', array(
'%library' => $library['name'],
));
return $library;
}
// Invoke callbacks in the 'pre-detect' group.
$this
->librariesInvoke('pre-detect', $library);
// Detect library version, if not hardcoded.
if (!isset($library['version'])) {
// We support both a single parameter, which is an associative array, and an
// indexed array of multiple parameters.
if (isset($library['version arguments'][0])) {
// Add the library as the first argument.
$library['version'] = call_user_func_array($library['version callback'], array_merge(array(
$library,
), $library['version arguments']));
}
elseif ('libraries_get_version' === $library['version callback']) {
$library['version'] = $this
->librariesGetVersion($library, $library['version arguments']);
}
else {
$library['version'] = $library['version callback']($library, $library['version arguments']);
}
if (empty($library['version'])) {
$library['error'] = 'not detected';
$library['error message'] = t('The version of the %library library could not be detected.', array(
'%library' => $library['name'],
));
return $library;
}
}
// Determine to which supported version the installed version maps.
if (!empty($library['versions'])) {
ksort($library['versions']);
$version = 0;
foreach ($library['versions'] as $supported_version => $version_properties) {
if (version_compare($library['version'], $supported_version, '>=')) {
$version = $supported_version;
}
}
if (!$version) {
$library['error'] = 'not supported';
$library['error message'] = t('The installed version %version of the %library library is not supported.', array(
'%version' => $library['version'],
'%library' => $library['name'],
));
return $library;
}
// Apply version specific definitions and overrides.
$library = array_merge($library, $library['versions'][$version]);
unset($library['versions']);
}
// Check each variant if it is installed.
if (!empty($library['variants'])) {
foreach ($library['variants'] as $variant_name => &$variant) {
// If no variant callback has been set, assume the variant to be
// installed.
if (!isset($variant['variant callback'])) {
$variant['installed'] = TRUE;
}
else {
// We support both a single parameter, which is an associative array,
// and an indexed array of multiple parameters.
if (isset($variant['variant arguments'][0])) {
// Add the library as the first argument, and the variant name as the second.
$variant['installed'] = call_user_func_array($variant['variant callback'], array_merge(array(
$library,
$variant_name,
), $variant['variant arguments']));
}
else {
$variant['installed'] = $variant['variant callback']($library, $variant_name, $variant['variant arguments']);
}
if (!$variant['installed']) {
$variant['error'] = 'not found';
$variant['error message'] = t('The %variant variant of the %library library could not be found.', array(
'%variant' => $variant_name,
'%library' => $library['name'],
));
}
}
}
}
// If we end up here, the library should be usable.
$library['installed'] = TRUE;
// Invoke callbacks in the 'post-detect' group.
$this
->librariesInvoke('post-detect', $library);
return $library;
}