Drupal investigation

ExpressionLanguageProvider.php 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\DependencyInjection;
  11. use Symfony\Component\ExpressionLanguage\ExpressionFunction;
  12. use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
  13. /**
  14. * Define some ExpressionLanguage functions.
  15. *
  16. * To get a service, use service('request').
  17. * To get a parameter, use parameter('kernel.debug').
  18. *
  19. * @author Fabien Potencier <fabien@symfony.com>
  20. */
  21. class ExpressionLanguageProvider implements ExpressionFunctionProviderInterface
  22. {
  23. public function getFunctions()
  24. {
  25. return array(
  26. new ExpressionFunction('service', function ($arg) {
  27. return sprintf('$this->get(%s)', $arg);
  28. }, function (array $variables, $value) {
  29. return $variables['container']->get($value);
  30. }),
  31. new ExpressionFunction('parameter', function ($arg) {
  32. return sprintf('$this->getParameter(%s)', $arg);
  33. }, function (array $variables, $value) {
  34. return $variables['container']->getParameter($value);
  35. }),
  36. );
  37. }
  38. }