12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace Symfony\Component\Translation\Writer;
- use Symfony\Component\Translation\Dumper\DumperInterface;
- use Symfony\Component\Translation\Exception\InvalidArgumentException;
- use Symfony\Component\Translation\Exception\RuntimeException;
- use Symfony\Component\Translation\MessageCatalogue;
- class TranslationWriter implements TranslationWriterInterface
- {
-
- private $dumpers = [];
-
- public function addDumper(string $format, DumperInterface $dumper)
- {
- $this->dumpers[$format] = $dumper;
- }
-
- public function getFormats()
- {
- return array_keys($this->dumpers);
- }
-
- public function write(MessageCatalogue $catalogue, string $format, array $options = [])
- {
- if (!isset($this->dumpers[$format])) {
- throw new InvalidArgumentException(sprintf('There is no dumper associated with format "%s".', $format));
- }
-
- $dumper = $this->dumpers[$format];
- if (isset($options['path']) && !is_dir($options['path']) && !@mkdir($options['path'], 0777, true) && !is_dir($options['path'])) {
- throw new RuntimeException(sprintf('Translation Writer was not able to create directory "%s".', $options['path']));
- }
-
- $dumper->dump($catalogue, $options);
- }
- }
|