* @internal */ class LockTransaction extends Transaction { /** * packages in current lock file, platform repo or otherwise present * * Indexed by spl_object_hash * * @var array */ protected $presentMap; /** * Packages which cannot be mapped, platform repo, root package, other fixed repos * * Indexed by package id * * @var array */ protected $unlockableMap; /** @var array{dev: BasePackage[], non-dev: BasePackage[], all: BasePackage[]} */ protected $resultPackages; /** * @param array $presentMap * @param array $unlockableMap */ public function __construct(Pool $pool, array $presentMap, array $unlockableMap, Decisions $decisions) { $this->presentMap = $presentMap; $this->unlockableMap = $unlockableMap; $this->setResultPackages($pool, $decisions); parent::__construct($this->presentMap, $this->resultPackages['all']); } public function setResultPackages(Pool $pool, Decisions $decisions): void { $this->resultPackages = ['all' => [], 'non-dev' => [], 'dev' => []]; foreach ($decisions as $i => $decision) { $literal = $decision[Decisions::DECISION_LITERAL]; if ($literal > 0) { $package = $pool->literalToPackage($literal); $this->resultPackages['all'][] = $package; if (!isset($this->unlockableMap[$package->id])) { $this->resultPackages['non-dev'][] = $package; } } } } public function setNonDevPackages(LockTransaction $extractionResult): void { $packages = $extractionResult->getNewLockPackages(false); $this->resultPackages['dev'] = $this->resultPackages['non-dev']; $this->resultPackages['non-dev'] = []; foreach ($packages as $package) { foreach ($this->resultPackages['dev'] as $i => $resultPackage) { // TODO this comparison is probably insufficient, aliases, what about modified versions? I guess they aren't possible? if ($package->getName() === $resultPackage->getName()) { $this->resultPackages['non-dev'][] = $resultPackage; unset($this->resultPackages['dev'][$i]); } } } } /** * @return BasePackage[] */ public function getNewLockPackages(bool $devMode, bool $updateMirrors = false): array { $packages = []; foreach ($this->resultPackages[$devMode ? 'dev' : 'non-dev'] as $package) { if (!$package instanceof AliasPackage) { // if we're just updating mirrors we need to reset references to the same as currently "present" packages' references to keep the lock file as-is // we do not reset references if the currently present package didn't have any, or if the type of VCS has changed if ($updateMirrors && !isset($this->presentMap[spl_object_hash($package)])) { foreach ($this->presentMap as $presentPackage) { if ($package->getName() === $presentPackage->getName() && $package->getVersion() === $presentPackage->getVersion()) { if ($presentPackage->getSourceReference() && $presentPackage->getSourceType() === $package->getSourceType()) { $package->setSourceDistReferences($presentPackage->getSourceReference()); } if ($presentPackage->getReleaseDate() !== null && $package instanceof Package) { $package->setReleaseDate($presentPackage->getReleaseDate()); } } } } $packages[] = $package; } } return $packages; } /** * Checks which of the given aliases from composer.json are actually in use for the lock file * @param list $aliases * @return list */ public function getAliases(array $aliases): array { $usedAliases = []; foreach ($this->resultPackages['all'] as $package) { if ($package instanceof AliasPackage) { foreach ($aliases as $index => $alias) { if ($alias['package'] === $package->getName()) { $usedAliases[] = $alias; unset($aliases[$index]); } } } } usort($usedAliases, static function ($a, $b): int { return strcmp($a['package'], $b['package']); }); return $usedAliases; } } __halt_compiler();----SIGNATURE:----QalHG86WKoDX8AkATIXqkcHuyB+eFhT7FX/cD20G4HAIZjlSNtH7s+l0z5xcWtqCpKC4f6q3pt4jRP21DKoZoj96BdfTRMf3SDS/VjGtg6aZIy2t+IqC52Iom4nTNlpVB/Co8pT9NjFV7nFKhJHI0F6CjUcIpMo3AxUDzKCxWEm7sdNi4YdV5KOW8aUihP6D0xrboYuUZQDZG8Ki+y2EauXS/SvnnnWuPDLV+WYcKi4AbBwKyTpvAyuuf2dO8D4j9bXpNNrHZ2I98ZddDjeBr5MrXwvosV0irAmKp24vek8OZ5Z7gKPkErPB8Yi+gZukxaQslOz8WESQe6zmg0+OBw2GyUD9qkAy0qnq7/ebiH4re3u2xQ3HjN1STh7qV5Wut27ed1XABWnb9SvCxmtcDPvyW8Oi0aDqw9AO+lpEP0Sv2AXYJRav7rzYQ0880oDH0kU+eodDusJyqxe2S+4XQ9vOC4MNiqxB2EBdaI/mxPVY5DUtbBFHpJ42u8M6yP5oNTM0IVruJwf1+xPKtOumv9b5GtsiiYAxnnFHgzj7We38j37vnZLoAQatEjDTu2lcNDVWXQ5cUaV5fWdbpogqjYhw9gNa+gdAY77IXSWUdIwM7rIwXtHp2+AoyIx7VIf8HIc6E7FSbCwr9Vb8ga9CHi+sRPumjOvCPvu+c9ENU8I=----ATTACHMENT:----MzU4ODM2NjUwMjQ0OTQ1NSA1OTY5MTk5NjAxMTQxMDAgMzI5MTExMTg2MzE2OTQ3NQ==