Added the Porter Stemmer module to improve searches. This doesn't deal with some...
[yaffs-website] / vendor / symfony / dependency-injection / ExpressionLanguageProvider.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\DependencyInjection;
13
14 use Symfony\Component\ExpressionLanguage\ExpressionFunction;
15 use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
16
17 /**
18  * Define some ExpressionLanguage functions.
19  *
20  * To get a service, use service('request').
21  * To get a parameter, use parameter('kernel.debug').
22  *
23  * @author Fabien Potencier <fabien@symfony.com>
24  */
25 class ExpressionLanguageProvider implements ExpressionFunctionProviderInterface
26 {
27     private $serviceCompiler;
28
29     public function __construct(callable $serviceCompiler = null)
30     {
31         $this->serviceCompiler = $serviceCompiler;
32     }
33
34     public function getFunctions()
35     {
36         return array(
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);
41             }),
42
43             new ExpressionFunction('parameter', function ($arg) {
44                 return sprintf('$this->getParameter(%s)', $arg);
45             }, function (array $variables, $value) {
46                 return $variables['container']->getParameter($value);
47             }),
48         );
49     }
50 }