Modules can be added with {@link addModuleName()}. Edges between these modules can then be added using {@link addEdge()}. Both ends of an edge must have been defined before the edge is added. php $graph = new DependencyGraph(); $graph->addModuleName('acme/core'); $graph->addModuleName('acme/blog'); $graph->addModuleName('acme/blog-extension1'); $graph->addModuleName('acme/blog-extension2'); $graph->addDependency('acme/blog', 'acme/core'); $graph->addDependency('acme/blog-extension1', 'acme/blog'); $graph->addDependency('acme/blog-extension2', 'acme/blog'); $graph->addDependency('acme/blog-extension2', 'acme/blog-extension1'); You can use {@link getPath()} and {@link hasPath()} to check whether a path exists from one module to the other: php ... $graph->hasPath('acme/blog-extension1', 'acme/blog'); => true $graph->hasPath('acme/blog-extension2', 'acme/blog-extension1'); => false $graph->getPath('acme/blog-extension2', 'acme/core'); => array('acme/core', 'acme/blog', 'acme/blog-extension2') With {@link getSortedModuleNames()}, you can sort the modules such that the dependencies defined via the edges are respected: php ... $graph->getSortedModuleNames(); => array('acme/core', 'acme/blog', 'acme/blog-extension1', 'acme/blog-extension2')
Since: 1.0
Author: Bernhard Schussek (bschussek@gmail.com)
 /**
  * {@inheritdoc}
  */
 public function rollback()
 {
     $rootModuleName = $this->rootModule->getName();
     $rootModuleFile = $this->rootModule->getModuleFile();
     foreach ($this->overriddenModules as $moduleName) {
         $rootModuleFile->removeDependency($moduleName);
     }
     foreach ($this->addedEdgesFrom as $moduleName) {
         $this->overrideGraph->removeDependency($rootModuleName, $moduleName);
     }
 }
Example #2
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;
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     // Quit if no mappings exist
     if (!($moduleNames = $this->mappings->getModuleNames())) {
         return;
     }
     $sortedNames = $this->overrideGraph->getSortedModuleNames($moduleNames);
     try {
         foreach ($sortedNames as $moduleName) {
             foreach ($this->getEnabledMappingsByModuleName($moduleName) as $repositoryPath => $mapping) {
                 foreach ($mapping->getFilesystemPaths() as $filesystemPath) {
                     $this->repo->add($repositoryPath, $this->createResource($filesystemPath));
                     $this->added = true;
                 }
             }
         }
     } catch (Exception $e) {
         $this->repo->clear();
         throw $e;
     }
 }
Example #4
0
 /**
  * Adds the getModuleOrder() method.
  *
  * @param Clazz $class The factory class model.
  */
 public function addGetModuleOrderMethod(Clazz $class)
 {
     $class->addImport(new Import('Puli\\Discovery\\Api\\Discovery'));
     $class->addImport(new Import('Puli\\Manager\\Api\\Server\\ServerCollection'));
     $class->addImport(new Import('Puli\\UrlGenerator\\Api\\UrlGenerator'));
     $class->addImport(new Import('Puli\\UrlGenerator\\DiscoveryUrlGenerator'));
     $class->addImport(new Import('RuntimeException'));
     $method = new Method('getModuleOrder');
     $method->setDescription("Returns the order in which the installed modules should be loaded\naccording to the override statements.");
     $method->setReturnValue(new ReturnValue('$order', 'string[]', 'The sorted module names.'));
     $moduleOrderString = '';
     if (count($this->modules) > 0) {
         $overrideGraph = DependencyGraph::forModules($this->modules);
         foreach ($overrideGraph->getSortedModuleNames() as $moduleName) {
             $moduleOrderString .= sprintf("\n    %s,", var_export($moduleName, true));
         }
         $moduleOrderString .= "\n";
     }
     $method->addBody("\$order = array({$moduleOrderString});");
     $class->addMethod($method);
 }
Example #5
0
 private function loadPathMappings()
 {
     $this->overrideGraph = DependencyGraph::forModules($this->modules);
     $this->conflictDetector = new ModuleConflictDetector($this->overrideGraph);
     $this->mappings = new PathMappingCollection();
     $this->mappingsByResource = new PathMappingCollection();
     $this->conflicts = new ConflictCollection();
     // Load mappings
     foreach ($this->modules as $module) {
         if (null === $module->getModuleFile()) {
             continue;
         }
         foreach ($module->getModuleFile()->getPathMappings() as $mapping) {
             $this->loadPathMapping($mapping, $module)->execute();
         }
     }
     // Scan all paths for conflicts
     $this->updateConflicts($this->mappingsByResource->getRepositoryPaths())->execute();
 }