mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-07-28 00:09:56 -07:00
Finally fix often reported enum issue in rule engine
This commit is contained in:
@@ -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.');
|
||||
|
||||
@@ -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'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user