diff --git a/Gateways/Impl/FileGatewayImpl.php b/Gateways/Impl/FileGatewayImpl.php index 5891323..ffd15b3 100644 --- a/Gateways/Impl/FileGatewayImpl.php +++ b/Gateways/Impl/FileGatewayImpl.php @@ -12,6 +12,8 @@ use OpenClassrooms\Bundle\OneSkyBundle\Model\ExportFile; use OpenClassrooms\Bundle\OneSkyBundle\Model\UploadFile; use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\Yaml\Yaml as SFYaml; +use Symfony\Component\HttpKernel\Exception\HttpException; /** * @author Romain Kuzniak @@ -58,7 +60,14 @@ private function downloadTranslation(ExportFile $file) ); $downloadedContent = $this->client->translations(self::DOWNLOAD_METHOD, $file->format()); $this->checkTranslation($downloadedContent, $file); - file_put_contents($file->getTargetFilePath(), $downloadedContent); + if(!empty($downloadedContent)) { + if (is_callable("yaml_parse")) + file_put_contents($file->getTargetFilePath(), SFYaml::dump(yaml_parse($downloadedContent))); + else + throw new HttpException(500, "PHP YAML extension is missing ( https://pecl.php.net/package/yaml )"); + } + else + file_put_contents($file->getTargetFilePath(), $downloadedContent); return $file; } diff --git a/README.md b/README.md index 0d196d4..8b74a6d 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,24 @@ or by adding the package to the composer.json file directly: } ``` +This bundle need the YAML extension : https://pecl.php.net/package/yaml + +#### PHP 7 +``` +apt-get install php-pear libyaml-dev +pecl install yaml-2.0.0 +``` +Add "extension=yaml.so" to php.ini for CLI + +#### PHP 5 +``` +apt-get install php-pear libyaml-dev +pecl install yaml +``` +Add "extension=yaml.so" to php.ini for CLI + + + After the package has been installed, add the bundle to the AppKernel.php file: ```php // in AppKernel::registerBundles()