Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 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\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 <michelsalib@hotmail.com>
23
 */
24
class YamlFileDumper extends FileDumper
25
{
26
    private string $extension;
27
 
28
    public function __construct(string $extension = 'yml')
29
    {
30
        $this->extension = $extension;
31
    }
32
 
33
    public function formatCatalogue(MessageCatalogue $messages, string $domain, array $options = []): string
34
    {
35
        if (!class_exists(Yaml::class)) {
36
            throw new LogicException('Dumping translations in the YAML format requires the Symfony Yaml component.');
37
        }
38
 
39
        $data = $messages->all($domain);
40
 
41
        if (isset($options['as_tree']) && $options['as_tree']) {
42
            $data = ArrayConverter::expandToTree($data);
43
        }
44
 
45
        if (isset($options['inline']) && ($inline = (int) $options['inline']) > 0) {
46
            return Yaml::dump($data, $inline);
47
        }
48
 
49
        return Yaml::dump($data);
50
    }
51
 
52
    protected function getExtension(): string
53
    {
54
        return $this->extension;
55
    }
56
}