4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Translation\Dumper
;
14 use Symfony\Component\Translation\MessageCatalogue
;
17 * FileDumper is an implementation of DumperInterface that dump a message catalogue to file(s).
18 * Performs backup of already existing files.
21 * - path (mandatory): the directory where the files should be saved
23 * @author Michel Salib <michelsalib@hotmail.com>
25 abstract class FileDumper
implements DumperInterface
30 public function dump(MessageCatalogue
$messages, $options = array())
32 if (!array_key_exists('path', $options)) {
33 throw new \
InvalidArgumentException('The file dumper need a path options.');
36 // save a file for each domain
37 foreach ($messages->getDomains() as $domain) {
38 $file = $domain.'.'.$messages->getLocale().'.'.$this->getExtension();
40 $fullpath = $options['path'].'/'.$file;
41 if (file_exists($fullpath)) {
42 copy($fullpath, $fullpath.'~');
45 file_put_contents($fullpath, $this->format($messages, $domain));
50 * Transforms a domain of a message catalogue to its string representation.
52 * @param MessageCatalogue $messages
53 * @param string $domain
55 * @return string representation
57 abstract protected function format(MessageCatalogue
$messages, $domain);
60 * Gets the file extension of the dumper.
62 * @return string file extension
64 abstract protected function getExtension();