YamlFileDumper.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Translation\Dumper;
  11. use Symfony\Component\Translation\MessageCatalogue;
  12. use Symfony\Component\Translation\Util\ArrayConverter;
  13. use Symfony\Component\Yaml\Yaml;
  14. use Symfony\Component\Translation\Exception\LogicException;
  15. /**
  16. * YamlFileDumper generates yaml files from a message catalogue.
  17. *
  18. * @author Michel Salib <michelsalib@hotmail.com>
  19. */
  20. class YamlFileDumper extends FileDumper
  21. {
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
  26. {
  27. if (!class_exists('Symfony\Component\Yaml\Yaml')) {
  28. throw new LogicException('Dumping translations in the YAML format requires the Symfony Yaml component.');
  29. }
  30. $data = $messages->all($domain);
  31. if (isset($options['as_tree']) && $options['as_tree']) {
  32. $data = ArrayConverter::expandToTree($data);
  33. }
  34. if (isset($options['inline']) && ($inline = (int) $options['inline']) > 0) {
  35. return Yaml::dump($data, $inline);
  36. }
  37. return Yaml::dump($data);
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. protected function getExtension()
  43. {
  44. return 'yml';
  45. }
  46. }