You are here

private function LibrariesLoad::librariesTraverseLibrary in X Autoload 7.5

Helper function to apply a callback to all parts of a library.

Because library declarations can include variants and versions, and those version declarations can in turn include variants, modifying e.g. the 'files' property everywhere it is declared can be quite cumbersome, in which case this helper function is useful.

Parameters

array $library: An array of library information, passed by reference.

callback $callback: A string containing the callback to apply to all parts of a library.

See also

libraries_traverse_library()

1 call to LibrariesLoad::librariesTraverseLibrary()
LibrariesLoad::librariesInvoke in tests/src/VirtualDrupal/LibrariesLoad.php
Invokes library callbacks.

File

tests/src/VirtualDrupal/LibrariesLoad.php, line 283

Class

LibrariesLoad

Namespace

Drupal\xautoload\Tests\VirtualDrupal

Code

private function librariesTraverseLibrary(&$library, $callback) {

  // Always apply the callback to the top-level library.
  $callback($library, NULL, NULL);

  // Apply the callback to versions.
  if (isset($library['versions'])) {
    foreach ($library['versions'] as $version_string => &$version) {
      $callback($version, $version_string, NULL);

      // Versions can include variants as well.
      if (isset($version['variants'])) {
        foreach ($version['variants'] as $version_variant_name => &$version_variant) {
          $callback($version_variant, $version_string, $version_variant_name);
        }
      }
    }
  }

  // Apply the callback to variants.
  if (isset($library['variants'])) {
    foreach ($library['variants'] as $variant_name => &$variant) {
      $callback($variant, NULL, $variant_name);
    }
  }
}