summaryrefslogtreecommitdiffstats
path: root/Aufgabe06/vendor/symfony/translation/Symfony/Component/Translation/Dumper/FileDumper.php
diff options
context:
space:
mode:
authorStefan Suhren <suhren.stefan@fh-swf.de>2015-05-02 15:54:22 +0200
committerStefan Suhren <suhren.stefan@fh-swf.de>2015-05-02 15:54:22 +0200
commitf6933b82bbdb767480abf4cf6818b2db56fae1cc (patch)
tree377440bff6bc52b83aed6b07273ee478424184f3 /Aufgabe06/vendor/symfony/translation/Symfony/Component/Translation/Dumper/FileDumper.php
parent14f4818cc4279de6e911189db718339381f03b8a (diff)
downloadInternetTechnologien-f6933b82bbdb767480abf4cf6818b2db56fae1cc.tar.gz
InternetTechnologien-f6933b82bbdb767480abf4cf6818b2db56fae1cc.zip
Use composer to pull in propel and set it up
Diffstat (limited to 'Aufgabe06/vendor/symfony/translation/Symfony/Component/Translation/Dumper/FileDumper.php')
-rw-r--r--Aufgabe06/vendor/symfony/translation/Symfony/Component/Translation/Dumper/FileDumper.php122
1 files changed, 122 insertions, 0 deletions
diff --git a/Aufgabe06/vendor/symfony/translation/Symfony/Component/Translation/Dumper/FileDumper.php b/Aufgabe06/vendor/symfony/translation/Symfony/Component/Translation/Dumper/FileDumper.php
new file mode 100644
index 0000000..f2f17d6
--- /dev/null
+++ b/Aufgabe06/vendor/symfony/translation/Symfony/Component/Translation/Dumper/FileDumper.php
@@ -0,0 +1,122 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * 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 <michelsalib@hotmail.com>
+ */
+abstract class FileDumper implements DumperInterface
+{
+ /**
+ * A template for the relative paths to files.
+ *
+ * @var string
+ */
+ protected $relativePathTemplate = '%domain%.%locale%.%extension%';
+
+ /**
+ * Make file backup before the dump.
+ *
+ * @var bool
+ */
+ private $backup = true;
+
+ /**
+ * Sets the template for the relative paths to files.
+ *
+ * @param string $relativePathTemplate A template for the relative paths to files
+ */
+ public function setRelativePathTemplate($relativePathTemplate)
+ {
+ $this->relativePathTemplate = $relativePathTemplate;
+ }
+
+ /**
+ * Sets backup flag.
+ *
+ * @param bool
+ */
+ public function setBackup($backup)
+ {
+ $this->backup = $backup;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function dump(MessageCatalogue $messages, $options = array())
+ {
+ if (!array_key_exists('path', $options)) {
+ throw new \InvalidArgumentException('The file dumper needs a path option.');
+ }
+
+ // save a file for each domain
+ foreach ($messages->getDomains() as $domain) {
+ // backup
+ $fullpath = $options['path'].'/'.$this->getRelativePath($domain, $messages->getLocale());
+ if (file_exists($fullpath)) {
+ if ($this->backup) {
+ copy($fullpath, $fullpath.'~');
+ }
+ } else {
+ $directory = dirname($fullpath);
+ if (!file_exists($directory) && !@mkdir($directory, 0777, true)) {
+ throw new \RuntimeException(sprintf('Unable to create directory "%s".', $directory));
+ }
+ }
+ // 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();
+
+ /**
+ * Gets the relative file path using the template.
+ *
+ * @param string $domain The domain
+ * @param string $locale The locale
+ *
+ * @return string The relative file path
+ */
+ private function getRelativePath($domain, $locale)
+ {
+ return strtr($this->relativePathTemplate, array(
+ '%domain%' => $domain,
+ '%locale%' => $locale,
+ '%extension%' => $this->getExtension(),
+ ));
+ }
+}