4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\DependencyInjection;
14 use Symfony\Component\ExpressionLanguage\ExpressionFunction;
15 use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
18 * Define some ExpressionLanguage functions.
20 * To get a service, use service('request').
21 * To get a parameter, use parameter('kernel.debug').
23 * @author Fabien Potencier <fabien@symfony.com>
25 class ExpressionLanguageProvider implements ExpressionFunctionProviderInterface
27 private $serviceCompiler;
29 public function __construct(callable $serviceCompiler = null)
31 $this->serviceCompiler = $serviceCompiler;
34 public function getFunctions()
37 new ExpressionFunction('service', $this->serviceCompiler ?: function ($arg) {
38 return sprintf('$this->get(%s)', $arg);
39 }, function (array $variables, $value) {
40 return $variables['container']->get($value);
43 new ExpressionFunction('parameter', function ($arg) {
44 return sprintf('$this->getParameter(%s)', $arg);
45 }, function (array $variables, $value) {
46 return $variables['container']->getParameter($value);