* @author Jordi Boggiano */ class Pool implements \Countable { /** @var BasePackage[] */ protected $packages = []; /** @var array */ protected $packageByName = []; /** @var VersionParser */ protected $versionParser; /** @var array> */ protected $providerCache = []; /** @var BasePackage[] */ protected $unacceptableFixedOrLockedPackages; /** @var array> Map of package name => normalized version => pretty version */ protected $removedVersions = []; /** @var array> Map of package object hash => removed normalized versions => removed pretty version */ protected $removedVersionsByPackage = []; /** * @param BasePackage[] $packages * @param BasePackage[] $unacceptableFixedOrLockedPackages * @param array> $removedVersions * @param array> $removedVersionsByPackage */ public function __construct( array $packages = [], array $unacceptableFixedOrLockedPackages = [], array $removedVersions = [], array $removedVersionsByPackage = [], ) { $this->versionParser = new VersionParser; $this->setPackages($packages); $this->unacceptableFixedOrLockedPackages = $unacceptableFixedOrLockedPackages; $this->removedVersions = $removedVersions; $this->removedVersionsByPackage = $removedVersionsByPackage; } /** * @return array */ public function getRemovedVersions(string $name, ConstraintInterface $constraint): array { if (!isset($this->removedVersions[$name])) { return []; } $result = []; foreach ($this->removedVersions[$name] as $version => $prettyVersion) { if ($constraint->matches(new Constraint('==', $version))) { $result[$version] = $prettyVersion; } } return $result; } /** * @return array */ public function getRemovedVersionsByPackage(string $objectHash): array { if (!isset($this->removedVersionsByPackage[$objectHash])) { return []; } return $this->removedVersionsByPackage[$objectHash]; } /** * @param BasePackage[] $packages */ private function setPackages(array $packages): void { $id = 1; foreach ($packages as $package) { $this->packages[] = $package; $package->id = $id++; foreach ($package->getNames() as $provided) { $this->packageByName[$provided][] = $package; } } } /** * @return BasePackage[] */ public function getPackages(): array { return $this->packages; } /** * Retrieves the package object for a given package id. */ public function packageById(int $id): BasePackage { return $this->packages[$id - 1]; } /** * Returns how many packages have been loaded into the pool */ public function count(): int { return \count($this->packages); } /** * Searches all packages providing the given package name and match the constraint * * @param string $name The package name to be searched for * @param ?ConstraintInterface $constraint A constraint that all returned * packages must match or null to return all * @return BasePackage[] A set of packages */ public function whatProvides(string $name, ?ConstraintInterface $constraint = null): array { $key = (string) $constraint; if (isset($this->providerCache[$name][$key])) { return $this->providerCache[$name][$key]; } return $this->providerCache[$name][$key] = $this->computeWhatProvides($name, $constraint); } /** * @param string $name The package name to be searched for * @param ?ConstraintInterface $constraint A constraint that all returned * packages must match or null to return all * @return BasePackage[] */ private function computeWhatProvides(string $name, ?ConstraintInterface $constraint = null): array { if (!isset($this->packageByName[$name])) { return []; } $matches = []; foreach ($this->packageByName[$name] as $candidate) { if ($this->match($candidate, $name, $constraint)) { $matches[] = $candidate; } } return $matches; } public function literalToPackage(int $literal): BasePackage { $packageId = abs($literal); return $this->packageById($packageId); } /** * @param array $installedMap */ public function literalToPrettyString(int $literal, array $installedMap): string { $package = $this->literalToPackage($literal); if (isset($installedMap[$package->id])) { $prefix = ($literal > 0 ? 'keep' : 'remove'); } else { $prefix = ($literal > 0 ? 'install' : 'don\'t install'); } return $prefix.' '.$package->getPrettyString(); } /** * Checks if the package matches the given constraint directly or through * provided or replaced packages * * @param string $name Name of the package to be matched */ public function match(BasePackage $candidate, string $name, ?ConstraintInterface $constraint = null): bool { $candidateName = $candidate->getName(); $candidateVersion = $candidate->getVersion(); if ($candidateName === $name) { return $constraint === null || CompilingMatcher::match($constraint, Constraint::OP_EQ, $candidateVersion); } $provides = $candidate->getProvides(); $replaces = $candidate->getReplaces(); // aliases create multiple replaces/provides for one target so they can not use the shortcut below if (isset($replaces[0]) || isset($provides[0])) { foreach ($provides as $link) { if ($link->getTarget() === $name && ($constraint === null || $constraint->matches($link->getConstraint()))) { return true; } } foreach ($replaces as $link) { if ($link->getTarget() === $name && ($constraint === null || $constraint->matches($link->getConstraint()))) { return true; } } return false; } if (isset($provides[$name]) && ($constraint === null || $constraint->matches($provides[$name]->getConstraint()))) { return true; } if (isset($replaces[$name]) && ($constraint === null || $constraint->matches($replaces[$name]->getConstraint()))) { return true; } return false; } public function isUnacceptableFixedOrLockedPackage(BasePackage $package): bool { return \in_array($package, $this->unacceptableFixedOrLockedPackages, true); } /** * @return BasePackage[] */ public function getUnacceptableFixedOrLockedPackages(): array { return $this->unacceptableFixedOrLockedPackages; } public function __toString(): string { $str = "Pool:\n"; foreach ($this->packages as $package) { $str .= '- '.str_pad((string) $package->id, 6, ' ', STR_PAD_LEFT).': '.$package->getName()."\n"; } return $str; } } __halt_compiler();----SIGNATURE:----H2kFu8Uf3D3G+jF3K2GRrJJzcEsFRFfpZWWBogsBORNbAStc4QVq14SsWE9PLnqqYqdxAot1cqXx+oxDmtC+bmyISNOiTeqY0uKNnbqCvyxVleRdP5Xc/BF+1FgLlW1mmAWfI8bifQ4mZZeUQa8GEP/j2wcwxZVAl312UBwdycOBqrAaytZEAbHqXpgN9Mu9aYXG2KBllxb0KN1yPPcWaLd11nLAqRh6VT6eGNs+taAoRH+CQ0JbTvgOvOui8MiKnxGb4EtxV/ipkWjSUamCAzH4+xHgfobg/Fm8tRsAZGFiT8/fSb96u2afn3J4cZXwt/D4s+T4Z68QCz7Fdb+0XddJyW6YY6xFD7K6H80Q4gus/EsJenlE4vZUI9X1/JIgjS8wV46cIWw1e7JwwMrMhYhR1wS8uF9EAIjaKYr0Y+3xuqpNwsi2bdPP8G4fAKTkmQoqld2iZgxnkzx9m4t4pq/DF1NtTxaRBUYCacAFJS4AeQgNKUMXjjKS9DBMpvBg1jUQyART7ucZosEtxO1ez5LrH5qzO2I+9AtHagzIGK40jZ6dP/dDNYIlKu7jbmUDrhS5uk0XZrviVXe3BfxLLtB36NUF2hZlptopWgyq9gy38SL0mGS8WmqEtrgpb8+3IgyfaJSqk/MeqmtXSHhcY1P4nez1olwMIZ4/ZS62PuI=----ATTACHMENT:----NTkzNzk3OTI5NjE4MTMwNCA4MTQzMzEzMTUxNDgzMjY0IDU5NTI3MDgyNDkzNjE2MA==