Debian Codegraph @

lib/3rdParty/composer/symfony/translation/Dumper/YamlFileDumper.php

raw symbols SCIP
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
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\Exception\LogicException;
15 use Symfony\Component\Translation\MessageCatalogue;
16 use Symfony\Component\Translation\Util\ArrayConverter;
17 use Symfony\Component\Yaml\Yaml;
18
19 /**
20 * YamlFileDumper generates yaml files from a message catalogue.
21 *
22 * @author Michel Salib <[email protected]>
23 */
24 class YamlFileDumper extends FileDumper
25 {
26 public function __construct(
27 private string $extension = 'yml',
28 ) {
29 }
30
31 public function formatCatalogue(MessageCatalogue $messages, string $domain, array $options = []): string
32 {
33 if (!class_exists(Yaml::class)) {
34 throw new LogicException('Dumping translations in the YAML format requires the Symfony Yaml component.');
35 }
36
37 $data = $messages->all($domain);
38
39 if (isset($options['as_tree']) && $options['as_tree']) {
40 $data = ArrayConverter::expandToTree($data);
41 }
42
43 if (isset($options['inline']) && ($inline = (int) $options['inline']) > 0) {
44 return Yaml::dump($data, $inline);
45 }
46
47 return Yaml::dump($data);
48 }
49
50 protected function getExtension(): string
51 {
52 return $this->extension;
53 }
54 }