TwigThemeFactory.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.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\Form\Renderer\Theme;
  11. use Symfony\Component\Form\Exception\FormException;
  12. /**
  13. * Creates TwigTheme instances
  14. *
  15. * @author Bernhard Schussek <bernhard.schussek@symfony.com>
  16. */
  17. class TwigThemeFactory implements FormThemeFactoryInterface
  18. {
  19. /**
  20. * @var Twig_Environment
  21. */
  22. private $environment;
  23. public function __construct(\Twig_Environment $environment)
  24. {
  25. $this->environment = $environment;
  26. }
  27. /**
  28. * @see Symfony\Component\Form\Renderer\Theme\FormThemeFactoryInterface::create()
  29. */
  30. public function create($template = null)
  31. {
  32. if ($template === null) {
  33. throw new FormException('Twig themes expect a template');
  34. }
  35. return new TwigTheme($this->environment, $template);
  36. }
  37. }