From e8691366ce87db4705ec7c809cd963c981b909e7 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 20 Sep 2013 16:16:44 +0200 Subject: [PATCH] [ExpressionLanguage] renamed addFunction() to register() --- .../DependencyInjection/ExpressionLanguage.php | 4 ++-- .../ExpressionLanguage/ExpressionLanguage.php | 11 +++++++++-- src/Symfony/Component/ExpressionLanguage/README.md | 2 +- .../Core/Authorization/ExpressionLanguage.php | 10 +++++----- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/ExpressionLanguage.php b/src/Symfony/Component/DependencyInjection/ExpressionLanguage.php index 5b97b202b7..2e7edcd32f 100644 --- a/src/Symfony/Component/DependencyInjection/ExpressionLanguage.php +++ b/src/Symfony/Component/DependencyInjection/ExpressionLanguage.php @@ -27,13 +27,13 @@ class ExpressionLanguage extends BaseExpressionLanguage { parent::registerFunctions(); - $this->addFunction('service', function ($arg) { + $this->register('service', function ($arg) { return sprintf('$this->get(%s)', $arg); }, function (array $variables, $value) { return $variables['container']->get($value); }); - $this->addFunction('parameter', function ($arg) { + $this->register('parameter', function ($arg) { return sprintf('$this->getParameter(%s)', $arg); }, function (array $variables, $value) { return $variables['container']->getParameter($value); diff --git a/src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php b/src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php index 1db479cd87..b5cd15e0de 100644 --- a/src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php +++ b/src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php @@ -82,14 +82,21 @@ class ExpressionLanguage return $this->cache[$key]; } - public function addFunction($name, $compiler, $evaluator) + /** + * Registers a function. + * + * @param string $name The function name + * @param callable $compiler A callable able to compile the function + * @param callable $evaluator A callable able to evaluate the function + */ + public function register($name, $compiler, $evaluator) { $this->functions[$name] = array('compiler' => $compiler, 'evaluator' => $evaluator); } protected function registerFunctions() { - $this->addFunction('constant', function ($constant) { + $this->register('constant', function ($constant) { return sprintf('constant(%s)', $constant); }, function (array $values, $constant) { return constant($constant); diff --git a/src/Symfony/Component/ExpressionLanguage/README.md b/src/Symfony/Component/ExpressionLanguage/README.md index 648dedcbcf..3d53d2ac1b 100644 --- a/src/Symfony/Component/ExpressionLanguage/README.md +++ b/src/Symfony/Component/ExpressionLanguage/README.md @@ -25,7 +25,7 @@ You can extend your DSL with functions: $evaluator = function (array $variables, $value) { return strtoupper($value); }; - $language->addFunction('upper', $compiler, $evaluator); + $language->register('upper', $compiler, $evaluator); echo $language->evaluate('"foo" ~ upper(foo)', array('foo' => 'bar')); // would output fooBAR diff --git a/src/Symfony/Component/Security/Core/Authorization/ExpressionLanguage.php b/src/Symfony/Component/Security/Core/Authorization/ExpressionLanguage.php index bdb3371c01..524342ef6c 100644 --- a/src/Symfony/Component/Security/Core/Authorization/ExpressionLanguage.php +++ b/src/Symfony/Component/Security/Core/Authorization/ExpressionLanguage.php @@ -24,31 +24,31 @@ class ExpressionLanguage extends BaseExpressionLanguage { parent::registerFunctions(); - $this->addFunction('is_anonymous', function () { + $this->register('is_anonymous', function () { return '$trust_resolver->isAnonymous($token)'; }, function (array $variables) { return $variables['trust_resolver']->isAnonymous($variables['token']); }); - $this->addFunction('is_authenticated', function () { + $this->register('is_authenticated', function () { return '!$trust_resolver->isAnonymous($token)'; }, function (array $variables) { return !$variables['trust_resolver']->isAnonymous($variables['token']); }); - $this->addFunction('is_fully_authenticated', function () { + $this->register('is_fully_authenticated', function () { return '!$trust_resolver->isFullFledge($token)'; }, function (array $variables) { return !$variables['trust_resolver']->isFullFledge($variables['token']); }); - $this->addFunction('is_remember_me', function () { + $this->register('is_remember_me', function () { return '!$trust_resolver->isRememberMe($token)'; }, function (array $variables) { return !$variables['trust_resolver']->isRememberMe($variables['token']); }); - $this->addFunction('has_role', function ($role) { + $this->register('has_role', function ($role) { return sprintf('in_array(%s, $roles)', $role); }, function (array $variables, $role) { return in_array($role, $variables['roles']);