From 299fcc0a9f69f06eb36fc2643ef465e5ef42e92f Mon Sep 17 00:00:00 2001 From: BourotBenjamin Date: Mon, 21 Nov 2016 15:08:23 +0100 Subject: [PATCH 1/2] Complex YAML bridge for symfony --- Gateways/Impl/FileGatewayImpl.php | 10 +++++++++- README.md | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Gateways/Impl/FileGatewayImpl.php b/Gateways/Impl/FileGatewayImpl.php index 5891323..8d781b2 100644 --- a/Gateways/Impl/FileGatewayImpl.php +++ b/Gateways/Impl/FileGatewayImpl.php @@ -12,6 +12,7 @@ use OpenClassrooms\Bundle\OneSkyBundle\Model\ExportFile; use OpenClassrooms\Bundle\OneSkyBundle\Model\UploadFile; use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\Yaml\Yaml as SFYaml; /** * @author Romain Kuzniak @@ -58,7 +59,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() From a0c7230b65c5b0b8520b43da4d41dfe46de60eb0 Mon Sep 17 00:00:00 2001 From: Benjamin Bourot Date: Mon, 21 Nov 2016 15:26:25 +0100 Subject: [PATCH 2/2] Fix missing use --- Gateways/Impl/FileGatewayImpl.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Gateways/Impl/FileGatewayImpl.php b/Gateways/Impl/FileGatewayImpl.php index 8d781b2..ffd15b3 100644 --- a/Gateways/Impl/FileGatewayImpl.php +++ b/Gateways/Impl/FileGatewayImpl.php @@ -13,6 +13,7 @@ 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