PHP Class 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')
Since: 1.0
Author: Bernhard Schussek ([email protected])
Mostra file Open project: puli/manager Class Usage Examples

Public Methods

Method Description
__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.

Private Methods

Method Description
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.

Method Details

__construct() public method

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

addDependency() public method

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() public method

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

addModuleNames() public method

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

forModules() public static method

Creates an override graph for the given modules.
public static forModules ( ModuleList $modules ) : static
$modules Puli\Manager\Api\Module\ModuleList The modules to load.
return static The created override graph.

getModuleNames() public method

Returns all module names in the graph.
public getModuleNames ( ) : array
return array All module names in the graph.

getPath() public method

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.
return null | string[] The sorted module names on the path or `null` if no path was found.

getSortedModuleNames() public method

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.
return string[] The sorted module names.

hasDependency() public method

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.
return boolean Whether an edge exists from the origin to the target module.

hasModuleName() public method

Returns whether a module name exists in the graph.
public hasModuleName ( string $moduleName ) : boolean
$moduleName string The module name.
return boolean Whether the module name exists.

hasPath() public method

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.
return boolean Whether a path exists from the origin to the target module.

removeDependency() public method

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.