diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 3b13d85..448dc4c 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,4 +1,7 @@ +Libraries 8.x-3.x, xxxx-xx-xx +----------------------------- + Libraries 7.x-3.x, xxxx-xx-xx ----------------------------- diff --git a/lib/Drupal/libraries/Library/LibraryBase.php b/lib/Drupal/libraries/Library/LibraryBase.php index 54ac1e6..283c6c4 100644 --- a/lib/Drupal/libraries/Library/LibraryBase.php +++ b/lib/Drupal/libraries/Library/LibraryBase.php @@ -7,7 +7,7 @@ namespace Drupal\libraries\Library; -use Drupal\libraries\Library\Exception\LibraryVersionUndeterminedException +use Drupal\libraries\Library\Exception\LibraryVersionUndeterminedException; /** * Defines a base library for typical implementations. diff --git a/libraries.info b/libraries.info index 725ac95..6f848ca 100644 --- a/libraries.info +++ b/libraries.info @@ -1,5 +1,4 @@ name = Libraries description = Allows version dependent and shared usage of external libraries. -core = 7.x -dependencies[] = classloader +core = 8.x dependencies[] = system_stream_wrapper diff --git a/libraries.module b/libraries.module index 0ddb0ef..b73b0f0 100644 --- a/libraries.module +++ b/libraries.module @@ -552,6 +552,43 @@ function libraries_detect($name) { } /** + * Gets the version information from an arbitrary library. + * + * This function is being replaced in Drupal/libraries/Library/LibraryBase + * however that abstract class does not seem to be used anywhere. + * + * @param $library + * @param $file + * @param $pattern + * @param int $lines + * @param int $cols + * @return mixed + */ +function libraries_get_version($library, $arguments) { //$file, $pattern, $lines = 20, $cols = 200) { + extract($arguments); + if (empty($lines)) { + $lines = 20; + } + if (empty($cols)) { + $cols = 200; + } + + $file = DRUPAL_ROOT . '/' . $library['library path'] . '/' . $file; + if (!file_exists($file)) { + return; + } + $file = fopen($file, 'r'); + while ($lines && $line = fgets($file, $cols)) { + if (preg_match($pattern, $line, $version)) { + fclose($file); + return $version[1]; + } + $lines--; + } + fclose($file); +} + +/** * Loads a library. * * @param $name @@ -575,13 +612,14 @@ function libraries_load($name, $variant = NULL) { $loaded = &drupal_static(__FUNCTION__, array()); if (!isset($loaded[$name])) { - $library = cache_get($name, 'cache_libraries'); - if ($library) { + + if ($library = cache($name)->get('cache_libraries')) { $library = $library->data; } else { $library = libraries_detect($name); - cache_set($name, $library, 'cache_libraries'); + $cache = cache($name); + $cache->set('cache_libraries', $library); } // If a variant was specified, override the top-level properties with the