Graph example


          $this->addDependency($dependency_graph$id$dependency$dynamic_ids);
        }
      }
      if (!empty($migration_dependencies['optional'])) {
        foreach ($migration_dependencies['optional'] as $dependency) {
          $this->addDependency($dependency_graph$id$dependency$dynamic_ids);
        }
        $have_optional = TRUE;
      }
    }
    $dependency_graph = (new Graph($dependency_graph))->searchAndSort();
    if ($have_optional) {
      $required_dependency_graph = (new Graph($required_dependency_graph))->searchAndSort();
    }
    else {
      $required_dependency_graph = $dependency_graph;
    }
    $weights = [];
    foreach ($migrations as $migration_id => $migration) {
      // Populate a weights array to use with array_multisort() later.       $weights[] = $dependency_graph[$migration_id]['weight'];
      if (!empty($required_dependency_graph[$migration_id]['paths'])) {
        

  public function buildModuleDependencies(array $modules) {
    foreach ($modules as $module) {
      $graph[$module->getName()]['edges'] = [];
      if (isset($module->info['dependencies']) && is_array($module->info['dependencies'])) {
        foreach ($module->info['dependencies'] as $dependency) {
          $dependency_data = Dependency::createFromString($dependency);
          $graph[$module->getName()]['edges'][$dependency_data->getName()] = $dependency_data;
        }
      }
    }
    $graph_object = new Graph($graph ?? []);
    $graph = $graph_object->searchAndSort();
    foreach ($graph as $module_name => $data) {
      $modules[$module_name]->required_by = $data['reverse_paths'] ?? [];
      $modules[$module_name]->requires = $data['paths'] ?? [];
      $modules[$module_name]->sort = $data['weight'];
    }
    return $modules;
  }

  /** * {@inheritdoc} */
    // @endcode     $graph = $this->normalizeGraph([
      1 => [2],
      2 => [3, 4],
      3 => [],
      4 => [3],
      5 => [6],
      7 => [4, 5],
      8 => [9],
      9 => [],
    ]);
    $graph_object = new Graph($graph);
    $graph = $graph_object->searchAndSort();

    $expected_paths = [
      1 => [2, 3, 4],
      2 => [3, 4],
      3 => [],
      4 => [3],
      5 => [6],
      7 => [4, 3, 5, 6],
      8 => [9],
      9 => [],
    ];

        }
        // Include all dependencies in the graph so that topographical sorting         // works.         foreach (array_merge($entity->getDependencies('config')$entity->getDependencies('module')$entity->getDependencies('theme')) as $dependency) {
          $graph[$dependency]['edges'][$graph_key] = TRUE;
          $graph[$dependency]['name'] = $dependency;
        }
      }
      // Ensure that order of the graph is consistent.       krsort($graph);
      $graph_object = new Graph($graph);
      $this->graph = $graph_object->searchAndSort();
    }
    return $this->graph;
  }

  /** * Sets data to calculate dependencies for. * * The data is converted into lightweight ConfigEntityDependency objects. * * @param array $data * Configuration data keyed by configuration object name. Typically the * output of \Drupal\Core\Config\StorageInterface::loadMultiple(). * * @return $this */


      // Generate a graph object in order to populate the `_depth`, `_ancestors`       // and '_descendants' properties for all the entities.       $graph = [];
      foreach ($workspaces as $workspace_id => $workspace) {
        $graph[$workspace_id]['edges'] = [];
        if (!$workspace->parent->isEmpty()) {
          $graph[$workspace_id]['edges'][$workspace->parent->target_id] = TRUE;
        }
      }
      $graph = (new Graph($graph))->searchAndSort();

      $this->tree = [];
      foreach (array_keys($tree) as $workspace_id) {
        $this->tree[$workspace_id] = [
          'depth' => count($graph[$workspace_id]['paths']),
          'ancestors' => array_keys($graph[$workspace_id]['paths']),
          'descendants' => isset($graph[$workspace_id]['reverse_paths']) ? array_keys($graph[$workspace_id]['reverse_paths']) : [],
        ];
      }

      // Use the 'workspace_list' entity type cache tag because it will be
Home | Imprint | This part of the site doesn't use cookies.