Drupal investigation

CsvFileDumper.php 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. * CsvFileDumper generates a csv formatted string representation of a message catalogue.
  14. *
  15. * @author Stealth35
  16. */
  17. class CsvFileDumper extends FileDumper
  18. {
  19. private $delimiter = ';';
  20. private $enclosure = '"';
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public function format(MessageCatalogue $messages, $domain = 'messages')
  25. {
  26. @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);
  27. return $this->formatCatalogue($messages, $domain);
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
  33. {
  34. $handle = fopen('php://memory', 'rb+');
  35. foreach ($messages->all($domain) as $source => $target) {
  36. fputcsv($handle, array($source, $target), $this->delimiter, $this->enclosure);
  37. }
  38. rewind($handle);
  39. $output = stream_get_contents($handle);
  40. fclose($handle);
  41. return $output;
  42. }
  43. /**
  44. * Sets the delimiter and escape character for CSV.
  45. *
  46. * @param string $delimiter delimiter character
  47. * @param string $enclosure enclosure character
  48. */
  49. public function setCsvControl($delimiter = ';', $enclosure = '"')
  50. {
  51. $this->delimiter = $delimiter;
  52. $this->enclosure = $enclosure;
  53. }
  54. /**
  55. * {@inheritdoc}
  56. */
  57. protected function getExtension()
  58. {
  59. return 'csv';
  60. }
  61. }