ecf00fa64ba923f889640b083ecaae3e7ee801c9
[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 use Symfony\Component\Translation\Exception\LogicException;
18
19 /**
20  * YamlFileDumper generates yaml files from a message catalogue.
21  *
22  * @author Michel Salib <michelsalib@hotmail.com>
23  */
24 class YamlFileDumper extends FileDumper
25 {
26     private $extension;
27
28     public function __construct(/**string */$extension = 'yml')
29     {
30         $this->extension = $extension;
31     }
32
33     /**
34      * {@inheritdoc}
35      */
36     public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
37     {
38         if (!class_exists('Symfony\Component\Yaml\Yaml')) {
39             throw new LogicException('Dumping translations in the YAML format requires the Symfony Yaml component.');
40         }
41
42         $data = $messages->all($domain);
43
44         if (isset($options['as_tree']) && $options['as_tree']) {
45             $data = ArrayConverter::expandToTree($data);
46         }
47
48         if (isset($options['inline']) && ($inline = (int) $options['inline']) > 0) {
49             return Yaml::dump($data, $inline);
50         }
51
52         return Yaml::dump($data);
53     }
54
55     /**
56      * {@inheritdoc}
57      */
58     protected function getExtension()
59     {
60         return $this->extension;
61     }
62 }