Minor dependency updates
[yaffs-website] / vendor / symfony / translation / Dumper / YamlFileDumper.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Translation\Dumper;
13
14 use Symfony\Component\Translation\MessageCatalogue;
15 use Symfony\Component\Translation\Util\ArrayConverter;
16 use Symfony\Component\Yaml\Yaml;
17
18 /**
19  * YamlFileDumper generates yaml files from a message catalogue.
20  *
21  * @author Michel Salib <michelsalib@hotmail.com>
22  */
23 class YamlFileDumper extends FileDumper
24 {
25     /**
26      * {@inheritdoc}
27      */
28     public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
29     {
30         if (!class_exists('Symfony\Component\Yaml\Yaml')) {
31             throw new \LogicException('Dumping translations in the YAML format requires the Symfony Yaml component.');
32         }
33
34         $data = $messages->all($domain);
35
36         if (isset($options['as_tree']) && $options['as_tree']) {
37             $data = ArrayConverter::expandToTree($data);
38         }
39
40         if (isset($options['inline']) && ($inline = (int) $options['inline']) > 0) {
41             return Yaml::dump($data, $inline);
42         }
43
44         return Yaml::dump($data);
45     }
46
47     /**
48      * {@inheritdoc}
49      */
50     protected function format(MessageCatalogue $messages, $domain)
51     {
52         @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the formatCatalogue() method instead.', E_USER_DEPRECATED);
53
54         return $this->formatCatalogue($messages, $domain);
55     }
56
57     /**
58      * {@inheritdoc}
59      */
60     protected function getExtension()
61     {
62         return 'yml';
63     }
64 }