ExpressionExtension.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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\Bridge\Twig\Extension;
  11. use Symfony\Component\ExpressionLanguage\Expression;
  12. use Twig\Extension\AbstractExtension;
  13. use Twig\TwigFunction;
  14. /**
  15. * ExpressionExtension gives a way to create Expressions from a template.
  16. *
  17. * @author Fabien Potencier <fabien@symfony.com>
  18. */
  19. class ExpressionExtension extends AbstractExtension
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public function getFunctions()
  25. {
  26. return array(
  27. new TwigFunction('expression', array($this, 'createExpression')),
  28. );
  29. }
  30. public function createExpression($expression)
  31. {
  32. return new Expression($expression);
  33. }
  34. /**
  35. * Returns the name of the extension.
  36. *
  37. * @return string The extension name
  38. */
  39. public function getName()
  40. {
  41. return 'expression';
  42. }
  43. }