Finally fix often reported enum issue in rule engine

This commit is contained in:
Sander Dorigo
2026-03-12 08:41:15 +01:00
parent 133449640d
commit 51e005f305
4 changed files with 20 additions and 5 deletions
+1
View File
@@ -122,6 +122,7 @@ final class HomeController extends Controller
*/
public function index(AccountRepositoryInterface $repository): mixed
{
$types = config('firefly.accountTypesByIdentifier.asset');
$count = $repository->count($types);
Log::channel('audit')->info('User visits homepage.');
+2 -1
View File
@@ -70,6 +70,7 @@ use FireflyIII\Support\Form\RuleForm;
use FireflyIII\Support\Navigation;
use FireflyIII\Support\Preferences;
use FireflyIII\Support\Steam;
use FireflyIII\TransactionRules\Engine\CustomExpressionLanguage;
use FireflyIII\TransactionRules\Engine\RuleEngineInterface;
use FireflyIII\TransactionRules\Engine\SearchRuleEngine;
use FireflyIII\TransactionRules\Expressions\ActionExpressionLanguageProvider;
@@ -161,7 +162,7 @@ class FireflyServiceProvider extends ServiceProvider
// rule expression language
$this->app->singleton(static function (): ExpressionLanguage {
$expressionLanguage = new ExpressionLanguage();
$expressionLanguage = new CustomExpressionLanguage();
$expressionLanguage->registerProvider(new ActionExpressionLanguageProvider());
return $expressionLanguage;
@@ -0,0 +1,17 @@
<?php
namespace FireflyIII\TransactionRules\Engine;
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
class CustomExpressionLanguage extends ExpressionLanguage
{
protected function registerFunctions(): void
{
$basicPhpFunctions = ['min', 'max','substr','strlen','strpos'];
foreach ($basicPhpFunctions as $function) {
$this->addFunction(ExpressionFunction::fromPhp($function));
}
}
}
@@ -45,10 +45,6 @@ class ActionExpressionLanguageProvider implements ExpressionFunctionProviderInte
return [
new ExpressionFunction('constant2', static fn ($str): string => sprintf('(is_string(%1$s) ? strtolower(%1$s) : %1$s)', $str.'!'), $function),
new ExpressionFunction('constant', static fn ($str): string => sprintf('(is_string(%1$s) ? strtolower(%1$s) : %1$s)', $str.'!'), $function),
ExpressionFunction::fromPhp('substr'),
ExpressionFunction::fromPhp('strlen'),
ExpressionFunction::fromPhp('strpos'),
];
}
}