annotate vendor/symfony/dependency-injection/ExpressionLanguageProvider.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /*
Chris@0 4 * This file is part of the Symfony package.
Chris@0 5 *
Chris@0 6 * (c) Fabien Potencier <fabien@symfony.com>
Chris@0 7 *
Chris@0 8 * For the full copyright and license information, please view the LICENSE
Chris@0 9 * file that was distributed with this source code.
Chris@0 10 */
Chris@0 11
Chris@0 12 namespace Symfony\Component\DependencyInjection;
Chris@0 13
Chris@0 14 use Symfony\Component\ExpressionLanguage\ExpressionFunction;
Chris@0 15 use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
Chris@0 16
Chris@0 17 /**
Chris@0 18 * Define some ExpressionLanguage functions.
Chris@0 19 *
Chris@0 20 * To get a service, use service('request').
Chris@0 21 * To get a parameter, use parameter('kernel.debug').
Chris@0 22 *
Chris@0 23 * @author Fabien Potencier <fabien@symfony.com>
Chris@0 24 */
Chris@0 25 class ExpressionLanguageProvider implements ExpressionFunctionProviderInterface
Chris@0 26 {
Chris@12 27 private $serviceCompiler;
Chris@12 28
Chris@12 29 public function __construct(callable $serviceCompiler = null)
Chris@12 30 {
Chris@12 31 $this->serviceCompiler = $serviceCompiler;
Chris@12 32 }
Chris@12 33
Chris@0 34 public function getFunctions()
Chris@0 35 {
Chris@17 36 return [
Chris@12 37 new ExpressionFunction('service', $this->serviceCompiler ?: function ($arg) {
Chris@0 38 return sprintf('$this->get(%s)', $arg);
Chris@0 39 }, function (array $variables, $value) {
Chris@0 40 return $variables['container']->get($value);
Chris@0 41 }),
Chris@0 42
Chris@0 43 new ExpressionFunction('parameter', function ($arg) {
Chris@0 44 return sprintf('$this->getParameter(%s)', $arg);
Chris@0 45 }, function (array $variables, $value) {
Chris@0 46 return $variables['container']->getParameter($value);
Chris@0 47 }),
Chris@17 48 ];
Chris@0 49 }
Chris@0 50 }