EnvironmentConfigurator.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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\Bundle\TwigBundle\DependencyInjection\Configurator;
  11. /**
  12. * Twig environment configurator.
  13. *
  14. * @author Christian Flothmann <christian.flothmann@xabbuh.de>
  15. */
  16. class EnvironmentConfigurator
  17. {
  18. private $dateFormat;
  19. private $intervalFormat;
  20. private $timezone;
  21. private $decimals;
  22. private $decimalPoint;
  23. private $thousandsSeparator;
  24. public function __construct($dateFormat, $intervalFormat, $timezone, $decimals, $decimalPoint, $thousandsSeparator)
  25. {
  26. $this->dateFormat = $dateFormat;
  27. $this->intervalFormat = $intervalFormat;
  28. $this->timezone = $timezone;
  29. $this->decimals = $decimals;
  30. $this->decimalPoint = $decimalPoint;
  31. $this->thousandsSeparator = $thousandsSeparator;
  32. }
  33. public function configure(\Twig_Environment $environment)
  34. {
  35. $environment->getExtension('Twig_Extension_Core')->setDateFormat($this->dateFormat, $this->intervalFormat);
  36. if (null !== $this->timezone) {
  37. $environment->getExtension('Twig_Extension_Core')->setTimezone($this->timezone);
  38. }
  39. $environment->getExtension('Twig_Extension_Core')->setNumberFormat($this->decimals, $this->decimalPoint, $this->thousandsSeparator);
  40. }
  41. }