PHP Класс Puli\Manager\Conflict\DependencyGraph

Modules can be added with {@link addModuleName()}. Edges between these modules can then be added using {@link addEdge()}. Both ends of an edge must have been defined before the edge is added. php $graph = new DependencyGraph(); $graph->addModuleName('acme/core'); $graph->addModuleName('acme/blog'); $graph->addModuleName('acme/blog-extension1'); $graph->addModuleName('acme/blog-extension2'); $graph->addDependency('acme/blog', 'acme/core'); $graph->addDependency('acme/blog-extension1', 'acme/blog'); $graph->addDependency('acme/blog-extension2', 'acme/blog'); $graph->addDependency('acme/blog-extension2', 'acme/blog-extension1'); You can use {@link getPath()} and {@link hasPath()} to check whether a path exists from one module to the other: php ... $graph->hasPath('acme/blog-extension1', 'acme/blog'); => true $graph->hasPath('acme/blog-extension2', 'acme/blog-extension1'); => false $graph->getPath('acme/blog-extension2', 'acme/core'); => array('acme/core', 'acme/blog', 'acme/blog-extension2') With {@link getSortedModuleNames()}, you can sort the modules such that the dependencies defined via the edges are respected: php ... $graph->getSortedModuleNames(); => array('acme/core', 'acme/blog', 'acme/blog-extension1', 'acme/blog-extension2')
С версии: 1.0
Автор: Bernhard Schussek ([email protected])
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__construct ( array $moduleNames = [] ) Creates a new graph.
addDependency ( string $moduleName, string $dependency ) Adds a dependency from one to another module.
addModuleName ( string $moduleName ) Adds a module name to the graph.
addModuleNames ( array $moduleNames ) Adds a list of module names to the graph.
forModules ( ModuleList $modules ) : static Creates an override graph for the given modules.
getModuleNames ( ) : array Returns all module names in the graph.
getPath ( string $moduleName, string $dependency ) : null | string[] Returns the path from a module name to a dependency.
getSortedModuleNames ( array $namesToSort = [] ) : string[] Returns the sorted module names.
hasDependency ( string $moduleName, string $dependency, boolean $recursive = true ) : boolean Returns whether a module directly depends on another module.
hasModuleName ( string $moduleName ) : boolean Returns whether a module name exists in the graph.
hasPath ( string $moduleName, string $dependency ) : boolean Returns whether a path exists from a module to a dependency.
removeDependency ( string $moduleName, string $dependency ) Removes a dependency from one to another module.

Приватные методы

Метод Описание
getPathDFS ( string $moduleName, string $dependency, array &$reversePath = [] ) : boolean Finds a path between modules using Depth-First Search.
sortModulesDFS ( string $currentName, array &$namesToSort, array &$output ) Topologically sorts the given module name into the output array.

Описание методов

__construct() публичный Метод

Creates a new graph.
public __construct ( array $moduleNames = [] )
$moduleNames array The module names stored in the nodes of the graph.

addDependency() публичный Метод

Adds a dependency from one to another module.
public addDependency ( string $moduleName, string $dependency )
$moduleName string The module name.
$dependency string The name of the dependency.

addModuleName() публичный Метод

Adds a module name to the graph.
public addModuleName ( string $moduleName )
$moduleName string The module name.

addModuleNames() публичный Метод

Adds a list of module names to the graph.
public addModuleNames ( array $moduleNames )
$moduleNames array The module names.

forModules() публичный статический Метод

Creates an override graph for the given modules.
public static forModules ( ModuleList $modules ) : static
$modules Puli\Manager\Api\Module\ModuleList The modules to load.
Результат static The created override graph.

getModuleNames() публичный Метод

Returns all module names in the graph.
public getModuleNames ( ) : array
Результат array All module names in the graph.

getPath() публичный Метод

Returns the path from a module name to a dependency.
public getPath ( string $moduleName, string $dependency ) : null | string[]
$moduleName string The module name.
$dependency string The name of the dependency.
Результат null | string[] The sorted module names on the path or `null` if no path was found.

getSortedModuleNames() публичный Метод

The names are sorted such that if a module m1 depends on a module m2, then m2 comes before m1 in the sorted set. If module names are passed, only those module names are sorted. Otherwise all module names are sorted.
public getSortedModuleNames ( array $namesToSort = [] ) : string[]
$namesToSort array The module names which should be sorted.
Результат string[] The sorted module names.

hasDependency() публичный Метод

Returns whether a module directly depends on another module.
public hasDependency ( string $moduleName, string $dependency, boolean $recursive = true ) : boolean
$moduleName string The module name.
$dependency string The name of the dependency.
$recursive boolean Whether to take recursive dependencies into account.
Результат boolean Whether an edge exists from the origin to the target module.

hasModuleName() публичный Метод

Returns whether a module name exists in the graph.
public hasModuleName ( string $moduleName ) : boolean
$moduleName string The module name.
Результат boolean Whether the module name exists.

hasPath() публичный Метод

Returns whether a path exists from a module to a dependency.
public hasPath ( string $moduleName, string $dependency ) : boolean
$moduleName string The module name.
$dependency string The name of the dependency.
Результат boolean Whether a path exists from the origin to the target module.

removeDependency() публичный Метод

Removes a dependency from one to another module.
public removeDependency ( string $moduleName, string $dependency )
$moduleName string The module name.
$dependency string The name of the dependency.