/** * Saves a configuration file. * * The configuration file is saved to the same path that it was read from. * * @param ConfigFile $configFile The configuration file to save. * * @throws WriteException If the file cannot be written. * @throws InvalidConfigException If the file contains invalid configuration. */ public function saveConfigFile(ConfigFile $configFile) { try { $jsonData = $this->configFileConverter->toJson($configFile); } catch (ConversionFailedException $e) { throw new InvalidConfigException(sprintf('The data written to %s could not be converted: %s', $configFile->getPath(), $e->getMessage()), 0, $e); } $json = $this->encode($jsonData, $configFile->getPath()); $this->storage->write($configFile->getPath(), $json); if ($this->factoryManager) { $this->factoryManager->autoGenerateFactoryClass(); } }
/** * {@inheritdoc} */ public function toJson($data, array $options = array()) { $targetVersion = isset($options['targetVersion']) ? $options['targetVersion'] : $this->currentVersion; $this->assertVersionSupported($targetVersion); $jsonData = $this->innerConverter->toJson($data, $options); $this->assertObject($jsonData); $jsonData->version = $this->currentVersion; if ($jsonData->version !== $targetVersion) { $this->migrate($jsonData, $targetVersion); $jsonData->version = $targetVersion; } return $jsonData; }
/** * {@inheritdoc} */ public function toJson($data, array $options = array()) { $jsonData = $this->innerConverter->toJson($data, $options); $this->validate($jsonData); return $jsonData; }