Puli\Manager\Repository\Mapping\SyncRepositoryPath::replace PHP Method

replace() private method

private replace ( array $filesystemPathsBefore, array $filesystemPathsAfter )
$filesystemPathsBefore array
$filesystemPathsAfter array
    private function replace(array $filesystemPathsBefore, array $filesystemPathsAfter)
    {
        $filesystemPathsAfterSuffix = $filesystemPathsAfter;
        $filesystemPathsAfterPrefix = array_splice($filesystemPathsAfterSuffix, 0, count($filesystemPathsBefore));
        if ($filesystemPathsBefore === $filesystemPathsAfterPrefix) {
            // Optimization: If the module names before are a prefix of the
            // module names after, we can simply add the mappings for the
            // remaining module names
            // Note: array_splice() already removed the prefix of $filesystemPathsAfterSuffix
            $this->addInOrder($filesystemPathsAfterSuffix);
            return;
        }
        $shortestRepositoryPath = $this->getShortestRepositoryPath($filesystemPathsBefore, $filesystemPathsAfter);
        // Remove the shortest repository path before adding
        $this->remove($shortestRepositoryPath);
        try {
            $this->add($shortestRepositoryPath, $filesystemPathsAfter);
        } catch (Exception $e) {
            try {
                // Try to restore the previous paths before failing
                $this->add($shortestRepositoryPath, $filesystemPathsBefore);
            } catch (Exception $e) {
                // We are already handling an exception
            }
            throw $e;
        }
    }