packageArtifactsFile = $packageArtifactsPath . self::ARTIFACTS_FILE; $this->filesystem = $filesystem; $this->cacheIdentifier = $cacheIdentifier; } public function fetch(): PackageCacheEntry { if ($this->isComposerBuildContext()) { throw new \RuntimeException('Can not load package states during generation', 1629820498); } if (isset($this->cacheEntry)) { return $this->cacheEntry; } $packageData = @include $this->packageArtifactsFile; if (!$packageData) { throw new \RuntimeException('Package artifact not found. Run "composer install" to create it.', 1629819799); } return $this->cacheEntry = PackageCacheEntry::fromCache($packageData); } public function store(PackageCacheEntry $cacheEntry): void { if (!$this->isComposerBuildContext()) { throw new \RuntimeException('Can not modify package states in Composer mode', 1629819858); } $this->filesystem->ensureDirectoryExists(dirname($this->packageArtifactsFile)); file_put_contents($this->packageArtifactsFile, 'withIdentifier($this->cacheIdentifier)->serialize() . ';'); } public function invalidate(): void { throw new \RuntimeException('Can not modify package states in Composer mode', 1629824596); } public function getIdentifier(): string { if (!isset($this->cacheEntry)) { $this->fetch(); } return $this->cacheEntry->getIdentifier(); } private function isComposerBuildContext(): bool { return isset($this->filesystem, $this->cacheIdentifier); } }