From 4f5b44bd3bd490309eb2ba7b44df4769816ba729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sat, 3 Aug 2013 19:26:54 +0200 Subject: twig implementation --- .../Component/Translation/Dumper/FileDumper.php | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 vendor/symfony/translation/Symfony/Component/Translation/Dumper/FileDumper.php (limited to 'vendor/symfony/translation/Symfony/Component/Translation/Dumper/FileDumper.php') 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 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Dumper; + +use Symfony\Component\Translation\MessageCatalogue; + +/** + * FileDumper is an implementation of DumperInterface that dump a message catalogue to file(s). + * Performs backup of already existing files. + * + * Options: + * - path (mandatory): the directory where the files should be saved + * + * @author Michel Salib + */ +abstract class FileDumper implements DumperInterface +{ + /** + * {@inheritDoc} + */ + public function dump(MessageCatalogue $messages, $options = array()) + { + if (!array_key_exists('path', $options)) { + throw new \InvalidArgumentException('The file dumper need a path options.'); + } + + // save a file for each domain + foreach ($messages->getDomains() as $domain) { + $file = $domain.'.'.$messages->getLocale().'.'.$this->getExtension(); + // backup + $fullpath = $options['path'].'/'.$file; + if (file_exists($fullpath)) { + copy($fullpath, $fullpath.'~'); + } + // save file + file_put_contents($fullpath, $this->format($messages, $domain)); + } + } + + /** + * Transforms a domain of a message catalogue to its string representation. + * + * @param MessageCatalogue $messages + * @param string $domain + * + * @return string representation + */ + abstract protected function format(MessageCatalogue $messages, $domain); + + /** + * Gets the file extension of the dumper. + * + * @return string file extension + */ + abstract protected function getExtension(); +} -- cgit v1.2.3