JsonFileDumper.php 990B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. /**
  13. * JsonFileDumper generates an json formatted string representation of a message catalogue.
  14. *
  15. * @author singles
  16. */
  17. class JsonFileDumper extends FileDumper
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
  23. {
  24. if (isset($options['json_encoding'])) {
  25. $flags = $options['json_encoding'];
  26. } else {
  27. $flags = JSON_PRETTY_PRINT;
  28. }
  29. return json_encode($messages->all($domain), $flags);
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. protected function getExtension()
  35. {
  36. return 'json';
  37. }
  38. }