PhpBundleWriter.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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\Intl\ResourceBundle\Writer;
  11. /**
  12. * Writes .php resource bundles.
  13. *
  14. * @author Bernhard Schussek <bschussek@gmail.com>
  15. */
  16. class PhpBundleWriter implements BundleWriterInterface
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public function write($path, $locale, $data)
  22. {
  23. $template = <<<TEMPLATE
  24. <?php
  25. /*
  26. * This file is part of the Symfony package.
  27. *
  28. * (c) Fabien Potencier <fabien@symfony.com>
  29. *
  30. * For the full copyright and license information, please view the LICENSE
  31. * file that was distributed with this source code.
  32. */
  33. return %s;
  34. TEMPLATE;
  35. $data = var_export($data, true);
  36. $data = preg_replace('/array \(/', 'array(', $data);
  37. $data = preg_replace('/\n {1,10}array\(/', 'array(', $data);
  38. $data = preg_replace('/ /', ' ', $data);
  39. $data = sprintf($template, $data);
  40. file_put_contents($path.'/'.$locale.'.php', $data);
  41. }
  42. }