Use one expression language instance for all extra fields

This commit is contained in:
Yassine Guedidi 2024-12-23 00:09:03 +01:00
parent 1e1d58da7f
commit 01f42d52ef

View file

@ -10,11 +10,11 @@ use Wallabag\ExpressionLanguage\AuthenticatorProvider;
class LoginFormAuthenticator
{
private AuthenticatorProvider $authenticatorProvider;
private ExpressionLanguage $expressionLanguage;
public function __construct(AuthenticatorProvider $authenticatorProvider)
{
$this->authenticatorProvider = $authenticatorProvider;
$this->expressionLanguage = new ExpressionLanguage(null, [$authenticatorProvider]);
}
/**
@ -90,8 +90,7 @@ class LoginFormAuthenticator
foreach ($siteConfig->getExtraFields() as $fieldName => $fieldValue) {
if ('@=' === substr($fieldValue, 0, 2)) {
$expressionLanguage = $this->getExpressionLanguage();
$fieldValue = $expressionLanguage->evaluate(
$fieldValue = $this->expressionLanguage->evaluate(
substr($fieldValue, 2),
[
'config' => $siteConfig,
@ -104,15 +103,4 @@ class LoginFormAuthenticator
return $extraFields;
}
/**
* @return ExpressionLanguage
*/
private function getExpressionLanguage()
{
return new ExpressionLanguage(
null,
[$this->authenticatorProvider]
);
}
}