protected function sortPackage($packageKey)
{
if (!isset($this->packageStates[$packageKey])) {
// Package does not exist; so that means it is just skipped; but that's to the outside as if sorting was successful.
return true;
}
if (!isset($this->unsortedPackages[$packageKey])) {
// Safeguard: Package is not unsorted anymore.
return true;
}
$iterationForPackage = $this->unsortedPackages[$packageKey];
// $iterationForPackage will be -1 if the package is already worked on in a stack, in that case we will return instantly.
if ($iterationForPackage === -1) {
return false;
}
$this->unsortedPackages[$packageKey] = -1;
$packageComposerManifest = $this->manifestData[$packageKey];
$unresolvedDependencies = 0;
$packageRequirements = isset($packageComposerManifest['require']) ? array_keys($packageComposerManifest['require']) : [];
$unresolvedDependencies += $this->sortListBefore($packageKey, $packageRequirements);
if (isset($packageComposerManifest['extra']['neos']['loading-order']['after']) && is_array($packageComposerManifest['extra']['neos']['loading-order']['after'])) {
$sortingConfiguration = $packageComposerManifest['extra']['neos']['loading-order']['after'];
$unresolvedDependencies += $this->sortListBefore($packageKey, $sortingConfiguration);
}
/** @var array $packageState */
$packageState = $this->packageStates[$packageKey];
$this->unsortedPackages[$packageKey] = $iterationForPackage + 1;
if ($unresolvedDependencies === 0) {
// we are validly able to sort the package to this position.
unset($this->unsortedPackages[$packageKey]);
$this->sortedPackages[$packageKey] = $packageState;
return true;
}
if ($this->unsortedPackages[$packageKey] > 20) {
// SECOND case: ERROR case. This happens with MANY cyclic dependencies, in this case we just degrade by arbitarily sorting the package; and continue. Alternative would be throwing an Exception.
unset($this->unsortedPackages[$packageKey]);
// In order to be able to debug this kind of error (if we hit it), we at least try to write to PackageStates.php
// so if people send it to us, we have some chance of finding the error.
$packageState['error-sorting-limit-reached'] = true;
$this->sortedPackages[$packageKey] = $packageState;
return true;
}
return false;
}