diff options
Diffstat (limited to 'vendor/symfony/translation/Symfony/Component/Translation/Dumper/FileDumper.php')
-rw-r--r-- | vendor/symfony/translation/Symfony/Component/Translation/Dumper/FileDumper.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/vendor/symfony/translation/Symfony/Component/Translation/Dumper/FileDumper.php b/vendor/symfony/translation/Symfony/Component/Translation/Dumper/FileDumper.php new file mode 100644 index 00000000..63c1e6c3 --- /dev/null +++ b/vendor/symfony/translation/Symfony/Component/Translation/Dumper/FileDumper.php | |||
@@ -0,0 +1,65 @@ | |||
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 | * FileDumper is an implementation of DumperInterface that dump a message catalogue to file(s). | ||
18 | * Performs backup of already existing files. | ||
19 | * | ||
20 | * Options: | ||
21 | * - path (mandatory): the directory where the files should be saved | ||
22 | * | ||
23 | * @author Michel Salib <michelsalib@hotmail.com> | ||
24 | */ | ||
25 | abstract class FileDumper implements DumperInterface | ||
26 | { | ||
27 | /** | ||
28 | * {@inheritDoc} | ||
29 | */ | ||
30 | public function dump(MessageCatalogue $messages, $options = array()) | ||
31 | { | ||
32 | if (!array_key_exists('path', $options)) { | ||
33 | throw new \InvalidArgumentException('The file dumper need a path options.'); | ||
34 | } | ||
35 | |||
36 | // save a file for each domain | ||
37 | foreach ($messages->getDomains() as $domain) { | ||
38 | $file = $domain.'.'.$messages->getLocale().'.'.$this->getExtension(); | ||
39 | // backup | ||
40 | $fullpath = $options['path'].'/'.$file; | ||
41 | if (file_exists($fullpath)) { | ||
42 | copy($fullpath, $fullpath.'~'); | ||
43 | } | ||
44 | // save file | ||
45 | file_put_contents($fullpath, $this->format($messages, $domain)); | ||
46 | } | ||
47 | } | ||
48 | |||
49 | /** | ||
50 | * Transforms a domain of a message catalogue to its string representation. | ||
51 | * | ||
52 | * @param MessageCatalogue $messages | ||
53 | * @param string $domain | ||
54 | * | ||
55 | * @return string representation | ||
56 | */ | ||
57 | abstract protected function format(MessageCatalogue $messages, $domain); | ||
58 | |||
59 | /** | ||
60 | * Gets the file extension of the dumper. | ||
61 | * | ||
62 | * @return string file extension | ||
63 | */ | ||
64 | abstract protected function getExtension(); | ||
65 | } | ||