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. |
리턴 | Puli\Manager\Conflict\ModuleConflict[] | The detected conflicts. |
public function detectConflicts(array $tokens = null)
{
$tokens = null === $tokens ? array_keys($this->tokens) : $tokens;
$conflicts = array();
foreach ($tokens as $token) {
// Claim was released
if (!isset($this->tokens[$token])) {
continue;
}
$moduleNames = array_keys($this->tokens[$token]);
// Token claimed by only one module
if (1 === count($moduleNames)) {
continue;
}
$sortedNames = $this->dependencyGraph->getSortedModuleNames($moduleNames);
$conflictingNames = array();
// An edge must exist between each module pair in the sorted set,
// otherwise the dependencies are not sufficiently defined
for ($i = 1, $l = count($sortedNames); $i < $l; ++$i) {
// Exclude recursive dependencies
if (!$this->dependencyGraph->hasDependency($sortedNames[$i], $sortedNames[$i - 1], false)) {
$conflictingNames[$sortedNames[$i - 1]] = true;
$conflictingNames[$sortedNames[$i]] = true;
}
}
if (count($conflictingNames) > 0) {
$conflicts[] = new ModuleConflict($token, array_keys($conflictingNames));
}
}
return $conflicts;
}
/** * {@inheritdoc} */ public function execute() { if (!$this->repositoryPaths) { // Check all paths if none are passed $this->repositoryPaths = $this->conflicts->getRepositoryPaths(); } // Mark all as resolved foreach ($this->repositoryPaths as $repositoryPath) { if ($this->conflicts->has($repositoryPath)) { $conflict = $this->conflicts->get($repositoryPath); $this->conflicts->remove($repositoryPath); $this->removedConflicts[$repositoryPath] = $conflict->getMappings(); $conflict->resolve(); } } $moduleConflicts = $this->conflictDetector->detectConflicts($this->repositoryPaths); $this->deduplicateModuleConflicts($moduleConflicts); foreach ($moduleConflicts as $moduleConflict) { $repositoryPath = $moduleConflict->getConflictingToken(); $conflict = new PathConflict($repositoryPath); foreach ($moduleConflict->getModuleNames() as $moduleName) { $conflict->addMapping($this->mappingsByResource->get($repositoryPath, $moduleName)); } $this->conflicts->add($conflict); $this->addedConflicts[] = $repositoryPath; } }