Puli\Manager\Conflict\DependencyGraph::getSortedModuleNames PHP Method

getSortedModuleNames() public method

The names are sorted such that if a module m1 depends on a module m2, then m2 comes before m1 in the sorted set. If module names are passed, only those module names are sorted. Otherwise all module names are sorted.
public getSortedModuleNames ( array $namesToSort = [] ) : string[]
$namesToSort array The module names which should be sorted.
return string[] The sorted module names.
    public function getSortedModuleNames(array $namesToSort = array())
    {
        if (count($namesToSort) > 0) {
            $namesToSort = array_flip($namesToSort);
            foreach ($namesToSort as $module => $_) {
                if (!isset($this->moduleNames[$module])) {
                    throw new RuntimeException(sprintf('The module "%s" does not exist in the graph.', $module));
                }
            }
        } else {
            $namesToSort = $this->moduleNames;
        }
        $sorted = array();
        // Do a topologic sort
        // Start with any module and process until no more are left
        while (false !== reset($namesToSort)) {
            $this->sortModulesDFS(key($namesToSort), $namesToSort, $sorted);
        }
        return $sorted;
    }

Usage Example

Example #1
0
 private function getEnabledFilesystemPaths($repositoryPath)
 {
     // Get a copy so that we can remove the entries that we processed
     // already
     $inMappings = $this->mappings->toArray();
     $outMappings = array();
     $filesystemPaths = array();
     $this->filterEnabledMappings($repositoryPath, $inMappings, $outMappings);
     foreach ($outMappings as $mappingPath => $mappingsByModule) {
         foreach ($mappingsByModule as $moduleName => $mapping) {
             $filesystemPaths[$moduleName][$mappingPath] = $mapping->getFilesystemPaths();
         }
     }
     if (!$filesystemPaths) {
         return array();
     }
     // Sort primary keys (module names)
     $sortedNames = $this->overrideGraph->getSortedModuleNames(array_keys($filesystemPaths));
     $filesystemPaths = array_replace(array_flip($sortedNames), $filesystemPaths);
     // Sort secondary keys (repository paths)
     foreach ($filesystemPaths as $moduleName => $pathsByModule) {
         ksort($filesystemPaths[$moduleName]);
     }
     return $filesystemPaths;
 }
All Usage Examples Of Puli\Manager\Conflict\DependencyGraph::getSortedModuleNames