Skip to content

Latest commit

 

History

History
37 lines (28 loc) · 1.06 KB

building_rules_without_the_dsl.md

File metadata and controls

37 lines (28 loc) · 1.06 KB

Building rules without using the DSL

If for some reason you do not want to use the built-in DSL, be it because you want to use your IDE's autocompletion or because you prefer object-oriented APIs, know that it's possible!

The K-Phoen/rulerz-spec-builder package provides an object-oriented API to build Specifications for RulerZ:

# no_execute

// gender = "F" and points > 3000 becomes:
$spec = Expr::andX(
    Expr::equals('gender', 'F'),
    Expr::moreThan('points', 3000)
);

// (gender = "F" and points > 3000) or (gender = 'M' and points < 3000) becomes:
$spec = Expr::orX(
    Expr::andX(
        Expr::equals('gender', 'F'),
        Expr::moreThan('points', 3000)
    ),
    Expr::andX(
        Expr::equals('gender', 'M'),
        Expr::lessThan('points', 3000)
    )
);

See the package's documentation for more details.

That was it!

Return to the index to explore the other possibilities of the library