Puli\Manager\Api\Repository\PathMapping::addConflict PHP Method

addConflict() public method

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.
public addConflict ( Puli\Manager\Api\Repository\PathConflict $conflict )
$conflict Puli\Manager\Api\Repository\PathConflict The conflict to be added.
    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();
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Adds a path mapping involved in the conflict.
  *
  * @param PathMapping $mapping The path mapping to add.
  *
  * @throws NotLoadedException If the passed mapping is not loaded.
  */
 public function addMapping(PathMapping $mapping)
 {
     if (!$mapping->isLoaded()) {
         throw new NotLoadedException('The passed mapping must be loaded.');
     }
     $packageName = $mapping->getContainingPackage()->getName();
     $previousMapping = isset($this->mappings[$packageName]) ? $this->mappings[$packageName] : null;
     if ($previousMapping === $mapping) {
         return;
     }
     if ($previousMapping) {
         $previousMapping->removeConflict($this);
     }
     $this->mappings[$packageName] = $mapping;
     $mapping->addConflict($this);
 }
All Usage Examples Of Puli\Manager\Api\Repository\PathMapping::addConflict