/** * {@inheritdoc} */ public function rollback() { $rootPackageName = $this->rootPackage->getName(); $rootPackageFile = $this->rootPackage->getPackageFile(); foreach ($this->overriddenPackages as $packageName) { $rootPackageFile->removeOverriddenPackage($packageName); } foreach ($this->addedEdgesFrom as $packageName) { $this->overrideGraph->removeEdge($packageName, $rootPackageName); } }
/** * {@inheritdoc} */ public function rollback() { $rootModuleName = $this->rootModule->getName(); $rootModuleFile = $this->rootModule->getModuleFile(); foreach ($this->overriddenModules as $moduleName) { $rootModuleFile->removeOverriddenModule($moduleName); } foreach ($this->addedEdgesFrom as $moduleName) { $this->overrideGraph->removeEdge($moduleName, $rootModuleName); } }
private function getEnabledFilesystemPaths($repositoryPath) { // Get a copy so that we can remove the entries that we processed // already $inMappings = $this->mappings->toArray(); $outMappings = array(); $filesystemPaths = array(); $this->filterEnabledMappings($repositoryPath, $inMappings, $outMappings); foreach ($outMappings as $mappingPath => $mappingsByPackage) { foreach ($mappingsByPackage as $packageName => $mapping) { $filesystemPaths[$packageName][$mappingPath] = $mapping->getFilesystemPaths(); } } if (!$filesystemPaths) { return array(); } // Sort primary keys (package names) $sortedNames = $this->overrideGraph->getSortedPackageNames(array_keys($filesystemPaths)); $filesystemPaths = array_replace(array_flip($sortedNames), $filesystemPaths); // Sort secondary keys (repository paths) foreach ($filesystemPaths as $packageName => $pathsByPackage) { ksort($filesystemPaths[$packageName]); } return $filesystemPaths; }
/** * {@inheritdoc} */ public function execute() { // Quit if no mappings exist if (!($packageNames = $this->mappings->getPackageNames())) { return; } $sortedNames = $this->overrideGraph->getSortedPackageNames($packageNames); try { foreach ($sortedNames as $packageName) { foreach ($this->getEnabledMappingsByPackageName($packageName) as $repositoryPath => $mapping) { foreach ($mapping->getFilesystemPaths() as $filesystemPath) { $this->repo->add($repositoryPath, $this->createResource($filesystemPath)); $this->added = true; } } } } catch (Exception $e) { $this->repo->clear(); throw $e; } }
public function testConflictIfTransitiveOverrideOrder() { $this->detector->claim('A', 'package1'); $this->detector->claim('A', 'package3'); // Transitive relations ("paths") are not supported. Each pair of // conflicting packages must have a relationship defined. Otherwise, // if package2 removes the override statement for package1, then // package3 and package1 suddenly have a conflict without changing their // configuration $this->overrideGraph->addEdge('package1', 'package2'); $this->overrideGraph->addEdge('package2', 'package3'); $conflicts = $this->detector->detectConflicts(array('A')); $this->assertCount(1, $conflicts); $this->assertInstanceOf('Puli\\Manager\\Conflict\\PackageConflict', $conflicts[0]); $this->assertSame('A', $conflicts[0]->getConflictingToken()); $this->assertSame(array('package1', 'package3'), $conflicts[0]->getPackageNames()); }
private function getEnabledFilesystemPaths($repositoryPath) { // Get a copy so that we can remove the entries that we processed // already $mappings = $this->mappingsByResource->toArray(); $this->collectEnabledFilesystemPaths($repositoryPath, $mappings, $filesystemPaths); if (!$filesystemPaths) { return array(); } // Sort primary keys (package names) $sortedNames = $this->overrideGraph->getSortedPackageNames(array_keys($filesystemPaths)); $filesystemPaths = array_replace(array_flip($sortedNames), $filesystemPaths); // Sort secondary keys (repository paths) foreach ($filesystemPaths as $packageName => $pathsByPackage) { ksort($filesystemPaths[$packageName]); } return $filesystemPaths; }
private function loadPathMappings() { $this->overrideGraph = OverrideGraph::forPackages($this->packages); $this->conflictDetector = new PackageConflictDetector($this->overrideGraph); $this->mappings = new PathMappingCollection(); $this->mappingsByResource = new PathMappingCollection(); $this->conflicts = new ConflictCollection(); // Load mappings foreach ($this->packages as $package) { foreach ($package->getPackageFile()->getPathMappings() as $mapping) { $this->loadPathMapping($mapping, $package)->execute(); } } // Scan all paths for conflicts $this->updateConflicts($this->mappingsByResource->getRepositoryPaths())->execute(); }
/** * Adds the getPackageOrder() method. * * @param Clazz $class The factory class model. */ public function addGetPackageOrderMethod(Clazz $class) { $class->addImport(new Import('Puli\\Discovery\\Api\\Discovery')); $class->addImport(new Import('Puli\\Manager\\Api\\Server\\ServerCollection')); $class->addImport(new Import('Puli\\UrlGenerator\\Api\\UrlGenerator')); $class->addImport(new Import('Puli\\UrlGenerator\\DiscoveryUrlGenerator')); $class->addImport(new Import('RuntimeException')); $method = new Method('getPackageOrder'); $method->setDescription("Returns the order in which the installed packages should be loaded\naccording to the override statements."); $method->setReturnValue(new ReturnValue('$order', 'string[]', 'The sorted package names.')); $packageOrderString = ''; if (count($this->packages) > 0) { $overrideGraph = OverrideGraph::forPackages($this->packages); foreach ($overrideGraph->getSortedPackageNames() as $packageName) { $packageOrderString .= sprintf("\n %s,", var_export($packageName, true)); } $packageOrderString .= "\n"; } $method->addBody("\$order = array({$packageOrderString});"); $class->addMethod($method); }
private function loadPathMappings() { $this->overrideGraph = OverrideGraph::forModules($this->modules); $this->conflictDetector = new ModuleConflictDetector($this->overrideGraph); $this->mappings = new PathMappingCollection(); $this->mappingsByResource = new PathMappingCollection(); $this->conflicts = new ConflictCollection(); // Load mappings foreach ($this->modules as $module) { if (null === $module->getModuleFile()) { continue; } foreach ($module->getModuleFile()->getPathMappings() as $mapping) { $this->loadPathMapping($mapping, $module)->execute(); } } // Scan all paths for conflicts $this->updateConflicts($this->mappingsByResource->getRepositoryPaths())->execute(); }
public function testCreateWithPackageNames() { $this->graph = new OverrideGraph(array('p1', 'p2')); $this->assertTrue($this->graph->hasPackageName('p1')); $this->assertTrue($this->graph->hasPackageName('p2')); }