Drupal investigation

YamlFileDumper.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. /**
  15. * YamlFileDumper generates yaml files from a message catalogue.
  16. *
  17. * @author Michel Salib <michelsalib@hotmail.com>
  18. */
  19. class YamlFileDumper extends FileDumper
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
  25. {
  26. if (!class_exists('Symfony\Component\Yaml\Yaml')) {
  27. throw new \LogicException('Dumping translations in the YAML format requires the Symfony Yaml component.');
  28. }
  29. $data = $messages->all($domain);
  30. if (isset($options['as_tree']) && $options['as_tree']) {
  31. $data = ArrayConverter::expandToTree($data);
  32. }
  33. if (isset($options['inline']) && ($inline = (int) $options['inline']) > 0) {
  34. return Yaml::dump($data, $inline);
  35. }
  36. return Yaml::dump($data);
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. protected function format(MessageCatalogue $messages, $domain)
  42. {
  43. @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the formatCatalogue() method instead.', E_USER_DEPRECATED);
  44. return $this->formatCatalogue($messages, $domain);
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. protected function getExtension()
  50. {
  51. return 'yml';
  52. }
  53. }