VersionCache.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php declare(strict_types=1);
  2. namespace Packagist\WebBundle\Service;
  3. use Composer\Repository\VersionCacheInterface;
  4. use Packagist\WebBundle\Entity\Package;
  5. use Packagist\WebBundle\Entity\Version;
  6. class VersionCache implements VersionCacheInterface
  7. {
  8. /** @var Version[] */
  9. private $versionCache;
  10. private $package;
  11. public function __construct(Package $package, array $existingVersions)
  12. {
  13. $this->versionCache = [];
  14. foreach ($existingVersions as $version) {
  15. $this->versionCache[$version['version']] = $version;
  16. }
  17. $this->package = $package;
  18. }
  19. public function getVersionPackage($version, $identifier)
  20. {
  21. if (!empty($this->versionCache[$version]['source']['reference']) && $this->versionCache[$version]['source']['reference'] === $identifier) {
  22. return [
  23. 'name' => $this->package->getName(),
  24. 'version' => $this->versionCache[$version]['version'],
  25. 'version_normalized' => $this->versionCache[$version]['normalizedVersion'],
  26. 'source' => $this->versionCache[$version]['source'],
  27. ];
  28. }
  29. return null;
  30. }
  31. }