Webmozart\Json\Versioning\JsonVersioner::updateVersion PHP Méthode

updateVersion() public méthode

Updates the version of a JSON object.
public updateVersion ( stdClass $jsonData, string $version )
$jsonData stdClass The JSON object
$version string The version to set
    public function updateVersion(stdClass $jsonData, $version);

Usage Example

Exemple #1
0
 private function down($data, $sourceVersion, $targetVersion)
 {
     while (version_compare($sourceVersion, $targetVersion, '>')) {
         if (!isset($this->migrationsByTargetVersion[$sourceVersion])) {
             throw new MigrationFailedException(sprintf('No migration found to downgrade from version %s to %s.', $sourceVersion, $targetVersion));
         }
         $migration = $this->migrationsByTargetVersion[$sourceVersion];
         // Final version too low
         if (version_compare($migration->getSourceVersion(), $targetVersion, '<')) {
             throw new MigrationFailedException(sprintf('No migration found to downgrade from version %s to %s.', $sourceVersion, $targetVersion));
         }
         $migration->down($data);
         $this->versioner->updateVersion($data, $migration->getSourceVersion());
         $sourceVersion = $migration->getSourceVersion();
     }
 }