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

load() public method

Loads the mapping.
public load ( Puli\Manager\Api\Module\Module $containingModule, ModuleList $modules )
$containingModule Puli\Manager\Api\Module\Module The module that contains the mapping.
$modules Puli\Manager\Api\Module\ModuleList A list of modules that can be referenced using `@vendor/module:` prefixes in the path references.
    public function load(Module $containingModule, ModuleList $modules)
    {
        if (null !== $this->state) {
            throw new AlreadyLoadedException('The mapping is already loaded.');
        }
        $filesystemPaths = array();
        $pathMappings = array();
        $loadErrors = array();
        foreach ($this->pathReferences as $relativePath) {
            $loadError = null;
            try {
                $absolutePath = $this->makeAbsolute($relativePath, $containingModule, $modules);
                $this->assertFileExists($absolutePath, $relativePath, $containingModule);
                $filesystemPaths[] = $absolutePath;
            } catch (NoSuchModuleException $loadError) {
            } catch (FileNotFoundException $loadError) {
            }
            if ($loadError) {
                $loadErrors[] = $loadError;
            }
        }
        foreach ($filesystemPaths as $filesystemPath) {
            $pathMappings[$filesystemPath] = $this->repositoryPath;
            if (!is_dir($filesystemPath)) {
                continue;
            }
            $prefixLength = strlen($filesystemPath);
            $directoryEntries = iterator_to_array(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($filesystemPath, RecursiveDirectoryIterator::CURRENT_AS_PATHNAME | RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST));
            // RecursiveDirectoryIterator is not guaranteed to sort its results,
            // so sort them here
            // We need to sort in the loop and not at the very end because the
            // order of the $filesystemPaths should be kept in $pathMappings
            ksort($directoryEntries);
            foreach ($directoryEntries as $nestedFilesystemPath) {
                $pathMappings[$nestedFilesystemPath] = substr_replace($nestedFilesystemPath, $this->repositoryPath, 0, $prefixLength);
            }
        }
        $this->repositoryPaths = array_unique($pathMappings);
        $this->filesystemPaths = $filesystemPaths;
        $this->pathMappings = $pathMappings;
        $this->loadErrors = $loadErrors;
        $this->containingModule = $containingModule;
        sort($this->repositoryPaths);
        $this->refreshState();
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     if ($this->mapping->isLoaded()) {
         return;
     }
     $this->mapping->load($this->containingPackage, $this->packages);
     $packageName = $this->containingPackage->getName();
     $this->mappings->add($this->mapping);
     foreach ($this->mapping->listRepositoryPaths() as $repositoryPath) {
         $this->mappingsByResource->set($repositoryPath, $this->mapping);
         $this->conflictDetector->claim($repositoryPath, $packageName);
     }
 }
All Usage Examples Of Puli\Manager\Api\Repository\PathMapping::load