*/ class ArrayRepository implements RepositoryInterface { /** @var ?array */ protected $packages = null; /** @var ?array indexed by package unique name and used to cache hasPackage calls */ protected $packageMap = null; /** * @param array $packages */ public function __construct(array $packages = []) { foreach ($packages as $package) { $this->addPackage($package); } } public function getRepoName() { return 'array repo (defining '.$this->count().' package'.($this->count() > 1 ? 's' : '').')'; } /** * @inheritDoc */ public function loadPackages( array $packageNameMap, array $acceptableStabilities, array $stabilityFlags, array $alreadyLoaded = [], ) { $packages = $this->getPackages(); $result = []; $namesFound = []; foreach ($packages as $package) { if (array_key_exists($package->getName(), $packageNameMap)) { if ( (!$packageNameMap[$package->getName()] || $packageNameMap[$package->getName()]->matches(new Constraint('==', $package->getVersion()))) && StabilityFilter::isPackageAcceptable($acceptableStabilities, $stabilityFlags, $package->getNames(), $package->getStability()) && !isset($alreadyLoaded[$package->getName()][$package->getVersion()]) ) { // add selected packages which match stability requirements $result[spl_object_hash($package)] = $package; // add the aliased package for packages where the alias matches if ($package instanceof AliasPackage && !isset($result[spl_object_hash($package->getAliasOf())])) { $result[spl_object_hash($package->getAliasOf())] = $package->getAliasOf(); } } $namesFound[$package->getName()] = true; } } // add aliases of packages that were selected, even if the aliases did not match foreach ($packages as $package) { if ($package instanceof AliasPackage) { if (isset($result[spl_object_hash($package->getAliasOf())])) { $result[spl_object_hash($package)] = $package; } } } return ['namesFound' => array_keys($namesFound), 'packages' => $result]; } /** * @inheritDoc */ public function findPackage(string $name, $constraint) { $name = strtolower($name); if (!$constraint instanceof ConstraintInterface) { $versionParser = new VersionParser(); $constraint = $versionParser->parseConstraints($constraint); } foreach ($this->getPackages() as $package) { if ($name === $package->getName()) { $pkgConstraint = new Constraint('==', $package->getVersion()); if ($constraint->matches($pkgConstraint)) { return $package; } } } return null; } /** * @inheritDoc */ public function findPackages(string $name, $constraint = null) { $name = strtolower($name); $packages = []; if (null !== $constraint && !$constraint instanceof ConstraintInterface) { $versionParser = new VersionParser(); $constraint = $versionParser->parseConstraints($constraint); } foreach ($this->getPackages() as $package) { if ($name === $package->getName()) { if (null === $constraint || $constraint->matches(new Constraint('==', $package->getVersion()))) { $packages[] = $package; } } } return $packages; } /** * @inheritDoc */ public function search(string $query, int $mode = 0, ?string $type = null) { if ($mode === self::SEARCH_FULLTEXT) { $regex = '{(?:'.implode('|', Preg::split('{\s+}', preg_quote($query))).')}i'; } else { // vendor/name searches expect the caller to have preg_quoted the query $regex = '{(?:'.implode('|', Preg::split('{\s+}', $query)).')}i'; } $matches = []; foreach ($this->getPackages() as $package) { $name = $package->getName(); if ($mode === self::SEARCH_VENDOR) { [$name] = explode('/', $name); } if (isset($matches[$name])) { continue; } if (null !== $type && $package->getType() !== $type) { continue; } if (Preg::isMatch($regex, $name) || ($mode === self::SEARCH_FULLTEXT && $package instanceof CompletePackageInterface && Preg::isMatch($regex, implode(' ', (array) $package->getKeywords()) . ' ' . $package->getDescription())) ) { if ($mode === self::SEARCH_VENDOR) { $matches[$name] = [ 'name' => $name, 'description' => null, ]; } else { $matches[$name] = [ 'name' => $package->getPrettyName(), 'description' => $package instanceof CompletePackageInterface ? $package->getDescription() : null, ]; if ($package instanceof CompletePackageInterface && $package->isAbandoned()) { $matches[$name]['abandoned'] = $package->getReplacementPackage() ?: true; } } } } return array_values($matches); } /** * @inheritDoc */ public function hasPackage(PackageInterface $package) { if ($this->packageMap === null) { $this->packageMap = []; foreach ($this->getPackages() as $repoPackage) { $this->packageMap[$repoPackage->getUniqueName()] = $repoPackage; } } return isset($this->packageMap[$package->getUniqueName()]); } /** * Adds a new package to the repository * * @return void */ public function addPackage(PackageInterface $package) { if (!$package instanceof BasePackage) { throw new \InvalidArgumentException('Only subclasses of BasePackage are supported'); } if (null === $this->packages) { $this->initialize(); } $package->setRepository($this); $this->packages[] = $package; if ($package instanceof AliasPackage) { $aliasedPackage = $package->getAliasOf(); if (null === $aliasedPackage->getRepository()) { $this->addPackage($aliasedPackage); } } // invalidate package map cache $this->packageMap = null; } /** * @inheritDoc */ public function getProviders(string $packageName) { $result = []; foreach ($this->getPackages() as $candidate) { if (isset($result[$candidate->getName()])) { continue; } foreach ($candidate->getProvides() as $link) { if ($packageName === $link->getTarget()) { $result[$candidate->getName()] = [ 'name' => $candidate->getName(), 'description' => $candidate instanceof CompletePackageInterface ? $candidate->getDescription() : null, 'type' => $candidate->getType(), ]; continue 2; } } } return $result; } /** * @return AliasPackage|CompleteAliasPackage */ protected function createAliasPackage(BasePackage $package, string $alias, string $prettyAlias) { while ($package instanceof AliasPackage) { $package = $package->getAliasOf(); } if ($package instanceof CompletePackage) { return new CompleteAliasPackage($package, $alias, $prettyAlias); } return new AliasPackage($package, $alias, $prettyAlias); } /** * Removes package from repository. * * @param PackageInterface $package package instance * * @return void */ public function removePackage(PackageInterface $package) { $packageId = $package->getUniqueName(); foreach ($this->getPackages() as $key => $repoPackage) { if ($packageId === $repoPackage->getUniqueName()) { array_splice($this->packages, $key, 1); // invalidate package map cache $this->packageMap = null; return; } } } /** * @inheritDoc */ public function getPackages() { if (null === $this->packages) { $this->initialize(); } if (null === $this->packages) { throw new \LogicException('initialize failed to initialize the packages array'); } return $this->packages; } /** * Returns the number of packages in this repository * * @return 0|positive-int Number of packages */ public function count(): int { if (null === $this->packages) { $this->initialize(); } return count($this->packages); } /** * Initializes the packages array. Mostly meant as an extension point. * * @return void */ protected function initialize() { $this->packages = []; } } __halt_compiler();----SIGNATURE:----mY0MX/y4r2p6najIJsELgbfto8Ux43GXUQwXrzz54FswyRTn9Bt6iN6QA+oFudbO8Ryj/ZhdGBWrltPtDKv7cCQshaBzPUu4fXnBNAepfnAYQYheKEiKYbrLaY+MKDI07pgCEIMxv6roJcJdv8a2l+tl3ijVqxOpzX2jcdG1kcrJJ/aiyBvTMYpF1NU0DdK0OlPlQu8JQMx9pV0DNvUAq1j3De873hjJ+T/GMxc8V1pYZwJr5y0FoHdWUO/1TWJXcaRA8N5rs2Bqss+lHIA17nE9bu53kcvGN+e9doYKqYn/AICc5EyI0zJWDlKQcSVESILxjcC9UuFQGtm75HfFcux6gBhwZu3+eQ2MtOnQkw8I6r7eH6ztAg0teJhu+wy/W1dCeKZ9JgPU4asGc/dh2LLOTOJ7FkLO/wf/vlx51C2ZxABobsmlltYYCMae6bX+y+30ublaM1KC3yXRxxcssmIyRxagCOtgvvT4xHlETjTz1chDzRK+QrOBIKPxkAw8nno1uQ9ZZxcrzYAU/xMnYfCfXumTm4gA+RZ0GGY6247Mv+Z69o9LH0+LYeOuP+IqAIJnxxlXmGBrctE/WEvSc2wf/gp9B9Br52zIJfSUz+n7knqu9a9fzt019XmP/O0wbDqqN0Ez3PtnIVZj2NZgMnJKMS7kMscwU6D2TE+yCRM=----ATTACHMENT:----NzM1NzQwMDY3MjkyMDQwOCAxMTU4MTM0Mjg3MTY3MTUgMTU3NDIzNDMyMTY0ODk3OA==