/** * {@inheritdoc} */ public function migrate($targetVersion) { $previousVersion = $this->rootPackageFile->getVersion(); if ($previousVersion === $targetVersion) { return; } $this->rootPackageFile->setVersion($targetVersion); try { $this->packageFileStorage->saveRootPackageFile($this->rootPackageFile); } catch (Exception $e) { $this->rootPackageFile->setVersion($previousVersion); throw $e; } }
/** * {@inheritdoc} */ public function serializeRootPackageFile(RootPackageFile $packageFile) { $this->assertVersionSupported($packageFile->getVersion()); $jsonData = (object) array('version' => $this->targetVersion); $this->packageFileToJson($packageFile, $jsonData); $this->rootPackageFileToJson($packageFile, $jsonData); // Sort according to key order $jsonArray = (array) $jsonData; $orderedKeys = array_intersect_key(array_flip(self::$keyOrder), $jsonArray); $jsonData = (object) array_replace($orderedKeys, $jsonArray); $this->migrationManager->migrate($jsonData, $packageFile->getVersion()); return $this->encode($jsonData, $packageFile->getPath()); }