The filesystem paths are passed in the form of *path references* that are
either paths relative to the module's root directory or paths relative
to another modules's root directory prefixed with @vendor/module:,
where "vendor/module" is the name of the referenced module.
The path references are turned into absolute filesystem paths when
{@link load()} is called.
/** * {@inheritdoc} */ public function rollback() { if ($this->previousMapping) { $this->rootPackageFile->addPathMapping($this->previousMapping); } else { $this->rootPackageFile->removePathMapping($this->mapping->getRepositoryPath()); } }
/** * {@inheritdoc} */ public function rollback() { if (!$this->mapping->isLoaded()) { return; } $packageName = $this->containingPackage->getName(); $this->mappings->remove($this->mapping->getRepositoryPath(), $packageName); foreach ($this->mapping->listRepositoryPaths() as $repositoryPath) { $this->mappingsByResource->remove($repositoryPath, $packageName); $this->conflictDetector->release($repositoryPath, $packageName); } // Unload after iterating, otherwise the paths are gone $this->mapping->unload(); }
/** * {@inheritdoc} */ public function execute() { $rootPackageName = $this->rootPackage->getName(); $rootPackageFile = $this->rootPackage->getPackageFile(); foreach ($this->mapping->getConflictingPackages() as $conflictingPackage) { $packageName = $conflictingPackage->getName(); if (!$rootPackageFile->hasOverriddenPackage($packageName)) { $rootPackageFile->addOverriddenPackage($packageName); $this->overriddenPackages[] = $packageName; } if (!$this->overrideGraph->hasEdge($packageName, $rootPackageName)) { $this->overrideGraph->addEdge($packageName, $rootPackageName); $this->addedEdgesFrom[] = $packageName; } } }
/** * {@inheritdoc} */ public function execute() { $rootModuleName = $this->rootModule->getName(); $rootModuleFile = $this->rootModule->getModuleFile(); foreach ($this->mapping->getConflictingModules() as $conflictingModule) { $moduleName = $conflictingModule->getName(); if (!$rootModuleFile->hasDependency($moduleName)) { $rootModuleFile->addDependency($moduleName); $this->overriddenModules[] = $moduleName; } if (!$this->overrideGraph->hasDependency($rootModuleName, $moduleName)) { $this->overrideGraph->addDependency($rootModuleName, $moduleName); $this->addedEdgesFrom[] = $moduleName; } } }
/** * {@inheritdoc} */ public function rollback() { if ($this->mapping->isLoaded() || !$this->containingModule) { return; } $this->mapping->load($this->containingModule, $this->modules); $moduleName = $this->containingModule->getName(); foreach ($this->mapping->listRepositoryPaths() as $repositoryPath) { $this->mappings->add($this->mapping); $this->conflictDetector->claim($repositoryPath, $moduleName); } // Restore conflicts foreach ($this->conflicts as $repositoryPath => $conflict) { $conflict->addMappings($this->conflictingMappings[$repositoryPath]); } }
private function assertNoLoadErrors(PathMapping $mapping) { $loadErrors = $mapping->getLoadErrors(); if (count($loadErrors) > 0) { // Rethrow first error throw reset($loadErrors); } }
/** * Removes a path mapping from the conflict. * * If only one path mapping is left after removing this mapping, that * mapping is removed as well. The conflict is then resolved. * * @param PathMapping $mapping The path mapping to remove. * * @throws NotLoadedException If the passed mapping is not loaded. */ public function removeMapping(PathMapping $mapping) { if (!$mapping->isLoaded()) { throw new NotLoadedException('The passed mapping must be loaded.'); } $packageName = $mapping->getContainingPackage()->getName(); if (!isset($this->mappings[$packageName]) || $mapping !== $this->mappings[$packageName]) { return; } unset($this->mappings[$packageName]); $mapping->removeConflict($this); // Conflict was resolved if (count($this->mappings) < 2) { $resolvedMappings = $this->mappings; $this->mappings = array(); foreach ($resolvedMappings as $resolvedMapping) { $resolvedMapping->removeConflict($this); } } }
private function initDefaultManager() { $conflictMappingRoot1 = new PathMapping('/conflict1', array('res', 'assets')); $conflictMappingPackage11 = new PathMapping('/conflict1', array('res', '@vendor/package2:res')); $conflictMappingPackage12 = new PathMapping('/conflict2', 'res'); $conflictMappingPackage21 = new PathMapping('/conflict1', 'res'); $conflictMappingPackage22 = new PathMapping('/conflict2', 'res'); $conflictMappingRoot1->load($this->packages->getRootPackage(), $this->packages); $conflictMappingPackage11->load($this->packages->get('vendor/package1'), $this->packages); $conflictMappingPackage12->load($this->packages->get('vendor/package1'), $this->packages); $conflictMappingPackage21->load($this->packages->get('vendor/package2'), $this->packages); $conflictMappingPackage22->load($this->packages->get('vendor/package2'), $this->packages); $conflict1 = new PathConflict('/conflict1'); $conflict1->addMappings(array($conflictMappingRoot1, $conflictMappingPackage11, $conflictMappingPackage21)); $conflict2 = new PathConflict('/conflict2/sub/path'); $conflict2->addMappings(array($conflictMappingPackage12, $conflictMappingPackage22)); $this->repoManager->expects($this->any())->method('findPathMappings')->willReturnCallback($this->returnFromMap(array(array($this->packageAndState('vendor/root', PathMappingState::ENABLED), array(new PathMapping('/root/enabled', array('res', 'assets')))), array($this->packageAndState('vendor/package1', PathMappingState::ENABLED), array(new PathMapping('/package1/enabled', array('res', '@vendor/package2:res')))), array($this->packageAndState('vendor/package2', PathMappingState::ENABLED), array(new PathMapping('/package2/enabled', 'res'))), array($this->packageAndState('vendor/root', PathMappingState::NOT_FOUND), array(new PathMapping('/root/not-found', 'res'))), array($this->packageAndState('vendor/package1', PathMappingState::NOT_FOUND), array(new PathMapping('/package1/not-found', 'res'))), array($this->packageAndState('vendor/package2', PathMappingState::NOT_FOUND), array(new PathMapping('/package2/not-found', 'res'))), array($this->packagesAndState(array('vendor/root'), PathMappingState::CONFLICT), array($conflictMappingRoot1)), array($this->packagesAndState(array('vendor/package1'), PathMappingState::CONFLICT), array($conflictMappingPackage11, $conflictMappingPackage12)), array($this->packagesAndState(array('vendor/package2'), PathMappingState::CONFLICT), array($conflictMappingPackage21, $conflictMappingPackage22)), array($this->packagesAndState(array('vendor/root', 'vendor/package1'), PathMappingState::CONFLICT), array($conflictMappingRoot1, $conflictMappingPackage11, $conflictMappingPackage12)), array($this->packagesAndState(array('vendor/root', 'vendor/package2'), PathMappingState::CONFLICT), array($conflictMappingRoot1, $conflictMappingPackage21, $conflictMappingPackage22)), array($this->packagesAndState(array('vendor/package1', 'vendor/package2'), PathMappingState::CONFLICT), array($conflictMappingPackage11, $conflictMappingPackage12, $conflictMappingPackage21, $conflictMappingPackage22)), array($this->packagesAndState(array('vendor/root', 'vendor/package1', 'vendor/package2'), PathMappingState::CONFLICT), array($conflictMappingRoot1, $conflictMappingPackage11, $conflictMappingPackage12, $conflictMappingPackage21, $conflictMappingPackage22))))); }
public function testResolveRemovesAllMappings() { $mapping1 = new PathMapping('/path', 'resources'); $mapping1->load($this->package1, $this->packages); $mapping2 = new PathMapping('/path', 'resources'); $mapping2->load($this->package2, $this->packages); $mapping3 = new PathMapping('/path', 'resources'); $mapping3->load($this->package3, $this->packages); $conflict = new PathConflict('/path/conflict'); $conflict->addMapping($mapping1); $conflict->addMapping($mapping2); $conflict->addMapping($mapping3); $conflict->resolve(); $this->assertCount(0, $conflict->getMappings()); $this->assertCount(0, $mapping1->getConflicts()); $this->assertCount(0, $mapping2->getConflicts()); $this->assertCount(0, $mapping3->getConflicts()); $this->assertTrue($conflict->isResolved()); }
/** * Adds a path mapping. * * @param PathMapping $mapping The path mapping. */ public function addPathMapping(PathMapping $mapping) { $this->pathMappings[$mapping->getRepositoryPath()] = $mapping; ksort($this->pathMappings); }
public function testMatch() { $mapping = new PathMapping('/path', 'resources'); $mapping->load($this->package1, $this->packages); $this->assertFalse($mapping->match(Expr::same('foobar', PathMapping::CONTAINING_PACKAGE))); $this->assertTrue($mapping->match(Expr::same($this->package1->getName(), PathMapping::CONTAINING_PACKAGE))); $this->assertFalse($mapping->match(Expr::same(PathMappingState::CONFLICT, PathMapping::STATE))); $this->assertTrue($mapping->match(Expr::same(PathMappingState::ENABLED, PathMapping::STATE))); $this->assertFalse($mapping->match(Expr::startsWith('/foo', PathMapping::REPOSITORY_PATH))); $this->assertTrue($mapping->match(Expr::startsWith('/pa', PathMapping::REPOSITORY_PATH))); }
private function mappingsEqual(PathMapping $mapping1, PathMapping $mapping2) { return $mapping1->getRepositoryPath() === $mapping2->getRepositoryPath() && $mapping1->getPathReferences() === $mapping2->getPathReferences(); }
public function testClearRootPathMappings() { $this->initDefaultManager(); $this->repo->expects($this->at(0))->method('remove')->with('/app1'); $this->repo->expects($this->at(1))->method('remove')->with('/app2'); $this->packageFileStorage->expects($this->once())->method('saveRootPackageFile')->with($this->rootPackageFile)->will($this->returnCallback(function (RootPackageFile $rootPackageFile) { PHPUnit_Framework_Assert::assertFalse($rootPackageFile->hasPathMappings()); })); $this->rootPackageFile->addPathMapping($mapping1 = new PathMapping('/app1', 'resources')); $this->rootPackageFile->addPathMapping($mapping2 = new PathMapping('/app2', 'resources')); $this->manager->clearRootPathMappings(); $this->assertFalse($mapping1->isLoaded()); $this->assertFalse($mapping2->isLoaded()); }
private function mappingsEqual(PathMapping $mapping1, PathMapping $mapping2) { if ($mapping1->getRepositoryPath() !== $mapping2->getRepositoryPath()) { return false; } if ($mapping1->getPathReferences() !== $mapping2->getPathReferences()) { return false; } return true; }