‪TYPO3CMS  9.5
DependencyResolver.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
27 {
32 
37  {
38  $this->dependencyOrderingService = ‪$dependencyOrderingService;
39  }
40 
46  public function ‪sortPackageStatesConfigurationByDependency(array $packageStatesConfiguration)
47  {
48  trigger_error(self::class . ' will be removed in TYPO3 v10.0.', E_USER_DEPRECATED);
49  return $this->dependencyOrderingService->calculateOrder($this->‪buildDependencyGraph($packageStatesConfiguration));
50  }
51 
62  protected function ‪convertConfigurationForGraph(array $packageStatesConfiguration, array $packageKeys)
63  {
64  $dependencies = [];
65  foreach ($packageKeys as $packageKey) {
66  if (!isset($packageStatesConfiguration[$packageKey]['dependencies']) && !isset($packageStatesConfiguration[$packageKey]['suggestions'])) {
67  continue;
68  }
69  $dependencies[$packageKey] = [
70  'after' => []
71  ];
72  if (isset($packageStatesConfiguration[$packageKey]['dependencies'])) {
73  foreach ($packageStatesConfiguration[$packageKey]['dependencies'] as $dependentPackageKey) {
74  if (!in_array($dependentPackageKey, $packageKeys, true)) {
75  throw new \UnexpectedValueException(
76  'The package "' . $packageKey . '" depends on "'
77  . $dependentPackageKey . '" which is not present in the system.',
78  1382276561
79  );
80  }
81  $dependencies[$packageKey]['after'][] = $dependentPackageKey;
82  }
83  }
84  if (isset($packageStatesConfiguration[$packageKey]['suggestions'])) {
85  foreach ($packageStatesConfiguration[$packageKey]['suggestions'] as $suggestedPackageKey) {
86  // skip suggestions on not existing packages
87  if (in_array($suggestedPackageKey, $packageKeys, true)) {
88  // Suggestions actually have never been meant to influence loading order.
89  // We misuse this currently, as there is no other way to influence the loading order
90  // for not-required packages (soft-dependency).
91  // When considering suggestions for the loading order, we might create a cyclic dependency
92  // if the suggested package already has a real dependency on this package, so the suggestion
93  // has do be dropped in this case and must *not* be taken into account for loading order evaluation.
94  $dependencies[$packageKey]['after-resilient'][] = $suggestedPackageKey;
95  }
96  }
97  }
98  }
99  return $dependencies;
100  }
101 
112  protected function ‪addDependencyToFrameworkToAllExtensions(array $packageStateConfiguration, array $rootPackageKeys)
113  {
114  $frameworkPackageKeys = $this->‪findFrameworkPackages($packageStateConfiguration);
115  $extensionPackageKeys = array_diff(array_keys($packageStateConfiguration), $frameworkPackageKeys);
116  foreach ($extensionPackageKeys as $packageKey) {
117  // Remove framework packages from list
118  $packageKeysWithoutFramework = array_diff(
119  $packageStateConfiguration[$packageKey]['dependencies'],
120  $frameworkPackageKeys
121  );
122  // The order of the array_merge is crucial here,
123  // we want the framework first
124  $packageStateConfiguration[$packageKey]['dependencies'] = array_merge(
125  $rootPackageKeys,
126  $packageKeysWithoutFramework
127  );
128  }
129  return $packageStateConfiguration;
130  }
131 
141  protected function ‪buildDependencyGraph(array $packageStateConfiguration)
142  {
143  $frameworkPackageKeys = $this->‪findFrameworkPackages($packageStateConfiguration);
144  $frameworkPackagesDependencyGraph = $this->dependencyOrderingService->buildDependencyGraph($this->‪convertConfigurationForGraph($packageStateConfiguration, $frameworkPackageKeys));
145  $packageStateConfiguration = $this->‪addDependencyToFrameworkToAllExtensions($packageStateConfiguration, $this->dependencyOrderingService->findRootIds($frameworkPackagesDependencyGraph));
146 
147  $packageKeys = array_keys($packageStateConfiguration);
148  return $this->dependencyOrderingService->buildDependencyGraph($this->‪convertConfigurationForGraph($packageStateConfiguration, $packageKeys));
149  }
150 
155  protected function ‪findFrameworkPackages(array $packageStateConfiguration)
156  {
157  $frameworkPackageKeys = [];
158  $packageManager = GeneralUtility::makeInstance(PackageManager::class);
159  foreach ($packageStateConfiguration as $packageKey => $packageConfiguration) {
161  $package = $packageManager->getPackage($packageKey);
162  if ($package->getValueFromComposerManifest('type') === 'typo3-cms-framework') {
163  $frameworkPackageKeys[] = $packageKey;
164  }
165  }
166 
167  return $frameworkPackageKeys;
168  }
169 }
‪TYPO3\CMS\Core\Package\DependencyResolver\buildDependencyGraph
‪array buildDependencyGraph(array $packageStateConfiguration)
Definition: DependencyResolver.php:140
‪TYPO3\CMS\Core\Package\DependencyResolver
Definition: DependencyResolver.php:27
‪TYPO3\CMS\Core\Package\DependencyResolver\sortPackageStatesConfigurationByDependency
‪array sortPackageStatesConfigurationByDependency(array $packageStatesConfiguration)
Definition: DependencyResolver.php:45
‪TYPO3\CMS\Core\Package\DependencyResolver\addDependencyToFrameworkToAllExtensions
‪array addDependencyToFrameworkToAllExtensions(array $packageStateConfiguration, array $rootPackageKeys)
Definition: DependencyResolver.php:111
‪TYPO3\CMS\Core\Package\DependencyResolver\findFrameworkPackages
‪array findFrameworkPackages(array $packageStateConfiguration)
Definition: DependencyResolver.php:154
‪TYPO3\CMS\Core\Service\DependencyOrderingService
Definition: DependencyOrderingService.php:31
‪TYPO3\CMS\Core\Package\DependencyResolver\convertConfigurationForGraph
‪array convertConfigurationForGraph(array $packageStatesConfiguration, array $packageKeys)
Definition: DependencyResolver.php:61
‪TYPO3\CMS\Core\Package
Definition: DependencyResolver.php:2
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Package\DependencyResolver\injectDependencyOrderingService
‪injectDependencyOrderingService(DependencyOrderingService $dependencyOrderingService)
Definition: DependencyResolver.php:35
‪TYPO3\CMS\Core\Package\DependencyResolver\$dependencyOrderingService
‪DependencyOrderingService $dependencyOrderingService
Definition: DependencyResolver.php:30