PHP Class Puli\Manager\Conflict\ModuleConflictDetector

Modules may claim "tokens" for themselves. A token, in that sense, can be any integer or string. If modules claim the same token, a conflict is raised: php use Puli\Manager\Conflict\ModuleConflictDetector; $detector = new ModuleConflictDetector(); $detector->claim('/app/config', 'module1'); $detector->claim('/app/views', 'module2'); $conflicts = $detector->detectConflicts(array('/app/config', '/app/views')); => array() $detector->claim('/app/config', 'module2'); $conflicts = $detector->detectConflicts(array('/app/config', '/app/views')); => array(ModuleConflict) You can resolve conflicts by passing an {@link OverrideGraph} to the detector. The override graph has module names as nodes. When the conflict graph contains an edge from module A to module B, then module A is considered to be overridden by module B. Claims for the same resources will not result in conflicts for these modules: php use Puli\Manager\Conflict\OverrideGraph; use Puli\Manager\Conflict\ModuleConflictDetector; $graph = new OverrideGraph(); $graph->addModuleName('module1'); $graph->addModuleName('module2'); module1 is overridden by module2 $graph->addEdge('module1', 'module2'); $detector = new ModuleConflictDetector($graph); $detector->claim('/app/config', 'module1'); $detector->claim('/app/config', 'module2'); The conflict has been resolved $conflict s= $detector->detectConflict(array('/app/config')); => array()
Since: 1.0
Author: Bernhard Schussek ([email protected])
Mostrar archivo Open project: puli/manager Class Usage Examples

Public Methods

Method Description
__construct ( DependencyGraph $dependencyGraph = null ) Creates a new conflict detector.
claim ( integer | string $token, string $moduleName ) Claims a token for a module.
detectConflicts ( array $tokens = null ) : Puli\Manager\Conflict\ModuleConflict[] Checks the passed tokens for conflicts.
release ( integer | string $token, string $moduleName ) Releases a module's claim for a token.

Method Details

__construct() public method

Creates a new conflict detector.
public __construct ( DependencyGraph $dependencyGraph = null )
$dependencyGraph DependencyGraph The graph indicating which module depends on which other module.

claim() public method

Claims a token for a module.
public claim ( integer | string $token, string $moduleName )
$token integer | string The claimed token. Can be any integer or string.
$moduleName string The module name.

detectConflicts() public method

If no tokens are passed, all tokens are checked. A conflict is returned for every token that is claimed by two modules that are not connected by an edge in the override graph. In other words, if two modules A and B claim the same token, an edge must exist from A to B (A is overridden by B) or from B to A (B is overridden by A). Otherwise a conflict is returned.
public detectConflicts ( array $tokens = null ) : Puli\Manager\Conflict\ModuleConflict[]
$tokens array The tokens to check. If `null`, all claimed tokens are checked for conflicts. You are advised to pass tokens if possible to improve the performance of the conflict detection.
return Puli\Manager\Conflict\ModuleConflict[] The detected conflicts.

release() public method

Releases a module's claim for a token.
public release ( integer | string $token, string $moduleName )
$token integer | string The claimed token. Can be any integer or string.
$moduleName string The module name.