added a Twig extension to create Expression instances
This commit is contained in:
parent
38b7fde8ed
commit
e369d14a2c
47
src/Symfony/Bridge/Twig/Extension/ExpressionExtension.php
Normal file
47
src/Symfony/Bridge/Twig/Extension/ExpressionExtension.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\Twig\Extension;
|
||||
|
||||
use Symfony\Component\ExpressionLanguage\Expression;
|
||||
|
||||
/**
|
||||
* ExpressionExtension gives a way to create Expressions from a template.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class ExpressionExtension extends \Twig_Extension
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFunctions()
|
||||
{
|
||||
return array(
|
||||
new \Twig_SimpleFunction('expression', array($this, 'createExpression')),
|
||||
);
|
||||
}
|
||||
|
||||
private function createExpression($expression)
|
||||
{
|
||||
return new Expression($expression);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the extension.
|
||||
*
|
||||
* @return string The extension name
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'expression';
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@
|
||||
<parameter key="twig.extension.form.class">Symfony\Bridge\Twig\Extension\FormExtension</parameter>
|
||||
<parameter key="twig.extension.httpkernel.class">Symfony\Bridge\Twig\Extension\HttpKernelExtension</parameter>
|
||||
<parameter key="twig.extension.debug.stopwatch.class">Symfony\Bridge\Twig\Extension\StopwatchExtension</parameter>
|
||||
<parameter key="twig.extension.expression.class">Symfony\Bridge\Twig\Extension\ExpressionExtension</parameter>
|
||||
<parameter key="twig.form.engine.class">Symfony\Bridge\Twig\Form\TwigRendererEngine</parameter>
|
||||
<parameter key="twig.form.renderer.class">Symfony\Bridge\Twig\Form\TwigRenderer</parameter>
|
||||
<parameter key="twig.translation.extractor.class">Symfony\Bridge\Twig\Translation\TwigExtractor</parameter>
|
||||
@ -92,6 +93,10 @@
|
||||
<argument type="service" id="debug.stopwatch" on-invalid="ignore" />
|
||||
</service>
|
||||
|
||||
<service id="twig.extension.expression" class="%twig.extension.expression.class%" public="false">
|
||||
<tag name="twig.extension" />
|
||||
</service>
|
||||
|
||||
<service id="twig.extension.httpkernel" class="%twig.extension.httpkernel.class%" public="false">
|
||||
<argument type="service" id="fragment.handler" />
|
||||
</service>
|
||||
|
Reference in New Issue
Block a user