Version 1
[yaffs-website] / vendor / symfony / translation / Dumper / CsvFileDumper.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
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 $delimiter = ';';
24     private $enclosure = '"';
25
26     /**
27      * {@inheritdoc}
28      */
29     public function format(MessageCatalogue $messages, $domain = 'messages')
30     {
31         @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);
32
33         return $this->formatCatalogue($messages, $domain);
34     }
35
36     /**
37      * {@inheritdoc}
38      */
39     public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
40     {
41         $handle = fopen('php://memory', 'rb+');
42
43         foreach ($messages->all($domain) as $source => $target) {
44             fputcsv($handle, array($source, $target), $this->delimiter, $this->enclosure);
45         }
46
47         rewind($handle);
48         $output = stream_get_contents($handle);
49         fclose($handle);
50
51         return $output;
52     }
53
54     /**
55      * Sets the delimiter and escape character for CSV.
56      *
57      * @param string $delimiter delimiter character
58      * @param string $enclosure enclosure character
59      */
60     public function setCsvControl($delimiter = ';', $enclosure = '"')
61     {
62         $this->delimiter = $delimiter;
63         $this->enclosure = $enclosure;
64     }
65
66     /**
67      * {@inheritdoc}
68      */
69     protected function getExtension()
70     {
71         return 'csv';
72     }
73 }