Skip to content

Releases: nicoSWD/php-rule-parser

Major refactor — recursive descent parser, arithmetic, unary operators, and token system overhaul

29 Apr 22:05
0bf4368

Choose a tag to compare

New Features

  • Arithmetic operations — Full support for math expressions with proper operator precedence: +, -, *, /, %. Parentheses can be used to override precedence. (2 + 3 * 4 == 14)
  • String concatenation — The + operator now performs string concatenation when either operand is a string, and numeric addition otherwise. ("hello " + "world")
  • Unary minus and logical NOT operators — Support for negation (-5), double negation (--5), and logical NOT (!false, !(1 == 2), !foo).
  • Expression result APIRule::result() returns the actual computed value of an expression (e.g., int(15) for 5 * 3), not just true/false.
  • Syntax highlighter — A built-in custom syntax highlighter with customizable styles for token types.
  • Duplicate regex modifier validation — Invalid or duplicate regex modifiers now throw an error.

Major Refactors & Improvements

  • Recursive descent parser — Replaced the old parser with a proper recursive descent parser, improving correctness and maintainability.
  • Token system simplification — Consolidated 27 token classes into a single GenericToken + TokenKind enum, drastically reducing complexity.
  • Lexer streamingLexer::tokenize() converted from array-based to generator-based streaming for better memory efficiency.
  • Eliminated TokenStream God object — Cleaned up the dependency tree by removing the monolithic TokenStream class.
  • RuleEngineBuilder — Extracted dependency wiring from the God constructor in RuleEngine into a dedicated builder.
  • Interpreter pattern in AstEvaluator — Replaced fragile match expressions with the Interpreter pattern for cleaner node evaluation.
  • Consolidated InternalFunction/InternalMethod — Merged into a single InternalCallable DTO.
  • Consolidated Token/TokenKind enums — Reduced duplication across token enums.
  • Removed dead code — Cleaned up the Expression directory, EvaluableExpression, unused TokenIterator methods, and more.
  • PSR-12 coding standard — Migrated from PSR-2 to PSR-12.

Bug Fixes

  • Division by zero — Now properly handled in the evaluator instead of causing errors.
  • String escape sequences — Fixed unescaping of escape sequences in TokenEncapsedString.
  • AST cache not used — Fixed double parsing in Rule.php where the AST cache was never utilized.
  • Infinite recursion — Fixed infinite recursion in Rule.php property hook.
  • Lexer reentrancy — Fixed mutable state / reentrancy issue in the Lexer.
  • FunctionRegistry performance — Eliminated unnecessary new instance creation on every function call.
  • TokenCollection data structure — Replaced SplObjectStorage with ArrayObject to fix wrong data structure usage.
  • Fragile method prefix fallback — Refactored fragile method prefix fallback loop in ObjectMethodCaller.
  • Double evaluation — Eliminated double evaluation in isValid()/getError().
  • Duplicated node evaluation — Fixed duplicated node evaluation logic in AstEvaluator.
  • Stack-based token inspection — Replaced fragile $afterValue boolean with stack-based token inspection.

Dependency Updates

  • Updated PHP requirement to >=8.5
  • Updated phpunit/phpunit to ^13.1
  • Updated mockery/mockery to ^1.6
  • Updated squizlabs/php_codesniffer to ^4.0

Update for PHP 8.4

09 Oct 20:47
4b30b3d

Choose a tag to compare

No new features, just prettier code

Release for PHP 8

05 Feb 22:31

Choose a tag to compare

Minor improvements

Release for PHP 8

05 Feb 21:51
89b6545

Choose a tag to compare

This release doesn't add any new features, it just uses some of the new PHP 8 syntax.

Use version 0.6 if you're using PHP 7.

Add "not in" operator

24 Jan 16:25

Choose a tag to compare

Support for custom objects

13 Jun 08:50
a023a94

Choose a tag to compare

This release adds the ability to call methods on objects, and use the result as part of the rule.

class User
{
    // ...

    public function points(): int
    {
        return 1337;    
    }
}

$variables = [
    'user' => new User(),
];

$rule = new Rule('user.points() > 300', $variables);
var_dump($rule->isTrue()); // bool(true)

Add support for custom objects

28 Nov 00:06

Choose a tag to compare

0.6.0-alpha

Add support for custom object calls

Require PHPUnit ^5.4|^6.0

13 Oct 19:48

Choose a tag to compare

0.5.7

Require phpunit 5.4|6.0

Evaluator is no longer final

13 Oct 19:36

Choose a tag to compare

0.5.6

Merge branch 'master' of github.com:nicoSWD/php-rule-parser

Evaluator is no longer final

13 Oct 19:28

Choose a tag to compare

0.5.5

Update .travis.yml