class LibraryDependencyResolver implements LibraryDependencyResolverInterface (View source)

Resolves the dependencies of asset (CSS/JavaScript) libraries.

Properties

protected LibraryDiscoveryInterface $libraryDiscovery

The library discovery service.

protected array $librariesDependencies

The libraries dependencies.

Methods

__construct(LibraryDiscoveryInterface $library_discovery)

Constructs a new LibraryDependencyResolver instance.

string[]
getLibrariesWithDependencies(array $libraries)

Gets the given libraries with their dependencies.

string[]
doGetDependencies(array $libraries_with_unresolved_dependencies, array $final_libraries = [])

Gets the given libraries with its dependencies.

string[]
getMinimalRepresentativeSubset(array $libraries)

Gets the minimal representative subset of the given libraries.

Details

__construct(LibraryDiscoveryInterface $library_discovery)

Constructs a new LibraryDependencyResolver instance.

Parameters

LibraryDiscoveryInterface $library_discovery

The library discovery service.

string[] getLibrariesWithDependencies(array $libraries)

Gets the given libraries with their dependencies.

Given ['core/a', 'core/b', 'core/c'], with core/a depending on core/c and core/b on core/d, returns ['core/a', 'core/b', 'core/c', 'core/d'].

Parameters

array $libraries

A list of libraries, in the order they should be loaded.

Return Value

string[]

A list of libraries, in the order they should be loaded, including their dependencies.

protected string[] doGetDependencies(array $libraries_with_unresolved_dependencies, array $final_libraries = [])

Gets the given libraries with its dependencies.

Helper method for ::getLibrariesWithDependencies().

Parameters

array $libraries_with_unresolved_dependencies

A list of libraries, with unresolved dependencies, in the order they should be loaded.

array $final_libraries

The final list of libraries (the return value) that is being built recursively.

Return Value

string[]

A list of libraries, in the order they should be loaded, including their dependencies.

string[] getMinimalRepresentativeSubset(array $libraries)

Gets the minimal representative subset of the given libraries.

A minimal representative subset means that any library in the given set of libraries that is a dependency of another library in the set, is removed.

Hence a minimal representative subset is the most compact representation possible of a set of libraries.

(Each asset library has dependencies and can therefore be seen as a tree. Hence the given list of libraries represent a forest. This function returns all roots of trees that are not a subtree of another tree in the forest.)

Parameters

array $libraries

A set of libraries.

Return Value

string[]

A representative subset of the given set of libraries.