From f1469c6034fcf8d32901f72b4cbec20e59c25d0b Mon Sep 17 00:00:00 2001 From: Christoph Reiter <reiter.christoph@gmail.com> Date: Thu, 1 Dec 2022 13:48:26 +0100 Subject: [PATCH] ExpressionChecker: naming cleanup Avoid using "attributes" for both the user attributes and the attribute expressions. Instead call the "user attributes" and "attribute expressions". --- src/Authorization/AbstractAuthorizationService.php | 2 +- .../AuthorizationExpressionChecker.php | 14 +++++++------- src/Authorization/AuthorizationUser.php | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Authorization/AbstractAuthorizationService.php b/src/Authorization/AbstractAuthorizationService.php index 28cefd4..5daddb8 100644 --- a/src/Authorization/AbstractAuthorizationService.php +++ b/src/Authorization/AbstractAuthorizationService.php @@ -78,7 +78,7 @@ abstract class AbstractAuthorizationService { $this->userAuthorizationChecker->init(); - return $this->userAuthorizationChecker->getAttribute($this->currentAuthorizationUser, $attributeName, $defaultValue); + return $this->userAuthorizationChecker->evalAttributeExpression($this->currentAuthorizationUser, $attributeName, $defaultValue); } /** diff --git a/src/Authorization/AuthorizationExpressionChecker.php b/src/Authorization/AuthorizationExpressionChecker.php index c903ff8..9471bd8 100644 --- a/src/Authorization/AuthorizationExpressionChecker.php +++ b/src/Authorization/AuthorizationExpressionChecker.php @@ -56,19 +56,19 @@ class AuthorizationExpressionChecker * * @return mixed|null */ - public function getAttribute(AuthorizationUser $currentAuthorizationUser, string $attributeName, $defaultValue = null) + public function evalAttributeExpression(AuthorizationUser $currentAuthorizationUser, string $expressionName, $defaultValue = null) { - $this->tryIncreaseRecursionCounter($attributeName); + $this->tryIncreaseRecursionCounter($expressionName); - if (($attributeExpression = $this->attributeExpressions[$attributeName] ?? null) !== null) { - $attribute = $this->expressionLanguage->evaluate($attributeExpression, [ + if (($expression = $this->attributeExpressions[$expressionName] ?? null) !== null) { + $result = $this->expressionLanguage->evaluate($expression, [ 'user' => $currentAuthorizationUser, ]); } else { - throw new AuthorizationException(sprintf('attribute \'%s\' undefined', $attributeName), AuthorizationException::ATTRIBUTE_UNDEFINED); + throw new AuthorizationException(sprintf('expression \'%s\' undefined', $expressionName), AuthorizationException::ATTRIBUTE_UNDEFINED); } - return $attribute ?? $defaultValue; + return $result ?? $defaultValue; } /** @@ -78,7 +78,7 @@ class AuthorizationExpressionChecker * * @throws AuthorizationException */ - public function getCustomAttribute(AuthorizationUser $currentAuthorizationUser, string $attributeName, $defaultValue = null) + public function getUserAttribute(AuthorizationUser $currentAuthorizationUser, string $attributeName, $defaultValue = null) { return $this->dataMux->getAttribute($currentAuthorizationUser->getIdentifier(), $attributeName, $defaultValue); } diff --git a/src/Authorization/AuthorizationUser.php b/src/Authorization/AuthorizationUser.php index 2fafe5e..8a6a136 100644 --- a/src/Authorization/AuthorizationUser.php +++ b/src/Authorization/AuthorizationUser.php @@ -37,7 +37,7 @@ class AuthorizationUser */ public function getAttribute(string $attributeName, $defaultValue = null) { - return $this->authorizationChecker->getAttribute($this, $attributeName, $defaultValue); + return $this->authorizationChecker->evalAttributeExpression($this, $attributeName, $defaultValue); } /** @@ -59,6 +59,6 @@ class AuthorizationUser */ public function get(string $attributeName, $defaultValue = null) { - return $this->authorizationChecker->getCustomAttribute($this, $attributeName, $defaultValue); + return $this->authorizationChecker->getUserAttribute($this, $attributeName, $defaultValue); } } -- GitLab