| 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\MessageCatalogue;
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* CsvFileDumper generates a csv formatted string representation of a message catalogue.
|
|
|
18 |
*
|
|
|
19 |
* @author Stealth35
|
|
|
20 |
*/
|
|
|
21 |
class CsvFileDumper extends FileDumper
|
|
|
22 |
{
|
|
|
23 |
private string $delimiter = ';';
|
|
|
24 |
private string $enclosure = '"';
|
|
|
25 |
|
|
|
26 |
public function formatCatalogue(MessageCatalogue $messages, string $domain, array $options = []): string
|
|
|
27 |
{
|
|
|
28 |
$handle = fopen('php://memory', 'r+');
|
|
|
29 |
|
|
|
30 |
foreach ($messages->all($domain) as $source => $target) {
|
|
|
31 |
fputcsv($handle, [$source, $target], $this->delimiter, $this->enclosure);
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
rewind($handle);
|
|
|
35 |
$output = stream_get_contents($handle);
|
|
|
36 |
fclose($handle);
|
|
|
37 |
|
|
|
38 |
return $output;
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* Sets the delimiter and escape character for CSV.
|
|
|
43 |
*/
|
|
|
44 |
public function setCsvControl(string $delimiter = ';', string $enclosure = '"')
|
|
|
45 |
{
|
|
|
46 |
$this->delimiter = $delimiter;
|
|
|
47 |
$this->enclosure = $enclosure;
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
protected function getExtension(): string
|
|
|
51 |
{
|
|
|
52 |
return 'csv';
|
|
|
53 |
}
|
|
|
54 |
}
|