예제 #1
0
 /**
  * {@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();
         }
     }
     $packageConflicts = $this->conflictDetector->detectConflicts($this->repositoryPaths);
     $this->deduplicatePackageConflicts($packageConflicts);
     foreach ($packageConflicts as $packageConflict) {
         $repositoryPath = $packageConflict->getConflictingToken();
         $conflict = new PathConflict($repositoryPath);
         foreach ($packageConflict->getPackageNames() as $packageName) {
             $conflict->addMapping($this->mappingsByResource->get($repositoryPath, $packageName));
         }
         $this->conflicts->add($conflict);
         $this->addedConflicts[] = $repositoryPath;
     }
 }
예제 #2
0
 /**
  * Adds a conflict to the mapping.
  *
  * A mapping can refer to at most one conflict per conflicting repository
  * path. If the same conflict is added twice, the second addition is
  * ignored. If a different conflict is added for an existing repository
  * path, the previous conflict is removed before adding the new conflict
  * for the repository path.
  *
  * The repository path of the conflict must either be the repository path
  * of the mapping or any path within. If a conflict with a different path
  * is added, an exception is thrown.
  *
  * The method {@link load()} needs to be called before calling this method,
  * otherwise an exception is thrown.
  *
  * @param PathConflict $conflict The conflict to be added.
  *
  * @throws NotLoadedException       If the mapping is not loaded.
  * @throws InvalidArgumentException If the path of the conflict is not
  *                                  within the repository path of the
  *                                  mapping.
  */
 public function addConflict(PathConflict $conflict)
 {
     if (null === $this->state) {
         throw new NotLoadedException('The mapping is not loaded.');
     }
     if (!Path::isBasePath($this->repositoryPath, $conflict->getRepositoryPath())) {
         throw new InvalidArgumentException(sprintf('The conflicting path %s is not within the path %s of the ' . 'mapping.', $conflict->getRepositoryPath(), $this->repositoryPath));
     }
     $repositoryPath = $conflict->getRepositoryPath();
     $previousConflict = isset($this->conflicts[$repositoryPath]) ? $this->conflicts[$repositoryPath] : null;
     if ($previousConflict === $conflict) {
         return;
     }
     if ($previousConflict) {
         $previousConflict->removeMapping($this);
     }
     $this->conflicts[$repositoryPath] = $conflict;
     $conflict->addMapping($this);
     $this->refreshState();
 }
예제 #3
0
 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());
 }