Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\DependencyInjection; Chris@0: Chris@0: use Symfony\Component\ExpressionLanguage\ExpressionFunction; Chris@0: use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; Chris@0: Chris@0: /** Chris@0: * Define some ExpressionLanguage functions. Chris@0: * Chris@0: * To get a service, use service('request'). Chris@0: * To get a parameter, use parameter('kernel.debug'). Chris@0: * Chris@0: * @author Fabien Potencier Chris@0: */ Chris@0: class ExpressionLanguageProvider implements ExpressionFunctionProviderInterface Chris@0: { Chris@12: private $serviceCompiler; Chris@12: Chris@12: public function __construct(callable $serviceCompiler = null) Chris@12: { Chris@12: $this->serviceCompiler = $serviceCompiler; Chris@12: } Chris@12: Chris@0: public function getFunctions() Chris@0: { Chris@17: return [ Chris@12: new ExpressionFunction('service', $this->serviceCompiler ?: function ($arg) { Chris@0: return sprintf('$this->get(%s)', $arg); Chris@0: }, function (array $variables, $value) { Chris@0: return $variables['container']->get($value); Chris@0: }), Chris@0: Chris@0: new ExpressionFunction('parameter', function ($arg) { Chris@0: return sprintf('$this->getParameter(%s)', $arg); Chris@0: }, function (array $variables, $value) { Chris@0: return $variables['container']->getParameter($value); Chris@0: }), Chris@17: ]; Chris@0: } Chris@0: }