| @@ 137-156 (lines=20) @@ | ||
| 134 | * @throws WriteException If the file cannot be written. |
|
| 135 | * @throws InvalidConfigException If the file contains invalid configuration. |
|
| 136 | */ |
|
| 137 | public function saveConfigFile(ConfigFile $configFile) |
|
| 138 | { |
|
| 139 | try { |
|
| 140 | $jsonData = $this->configFileConverter->toJson($configFile); |
|
| 141 | } catch (ConversionFailedException $e) { |
|
| 142 | throw new InvalidConfigException(sprintf( |
|
| 143 | 'The data written to %s could not be converted: %s', |
|
| 144 | $configFile->getPath(), |
|
| 145 | $e->getMessage() |
|
| 146 | ), 0, $e); |
|
| 147 | } |
|
| 148 | ||
| 149 | $json = $this->encode($jsonData, $configFile->getPath()); |
|
| 150 | ||
| 151 | $this->storage->write($configFile->getPath(), $json); |
|
| 152 | ||
| 153 | if ($this->factoryManager) { |
|
| 154 | $this->factoryManager->autoGenerateFactoryClass(); |
|
| 155 | } |
|
| 156 | } |
|
| 157 | ||
| 158 | private function encode(stdClass $jsonData, $path) |
|
| 159 | { |
|
| @@ 210-231 (lines=22) @@ | ||
| 207 | * @throws WriteException If the file cannot be written. |
|
| 208 | * @throws InvalidConfigException If the file contains invalid configuration. |
|
| 209 | */ |
|
| 210 | public function saveRootPackageFile(RootPackageFile $packageFile) |
|
| 211 | { |
|
| 212 | try { |
|
| 213 | $jsonData = $this->rootPackageFileConverter->toJson($packageFile, array( |
|
| 214 | 'targetVersion' => $packageFile->getVersion(), |
|
| 215 | )); |
|
| 216 | } catch (ConversionFailedException $e) { |
|
| 217 | throw new InvalidConfigException(sprintf( |
|
| 218 | 'The data written to %s could not be converted: %s', |
|
| 219 | $packageFile->getPath(), |
|
| 220 | $e->getMessage() |
|
| 221 | ), 0, $e); |
|
| 222 | } |
|
| 223 | ||
| 224 | $json = $this->encode($jsonData, $packageFile->getPath()); |
|
| 225 | ||
| 226 | $this->storage->write($packageFile->getPath(), $json); |
|
| 227 | ||
| 228 | if ($this->factoryManager) { |
|
| 229 | $this->factoryManager->autoGenerateFactoryClass(); |
|
| 230 | } |
|
| 231 | } |
|
| 232 | ||
| 233 | private function encode(stdClass $jsonData, $path) |
|
| 234 | { |
|