Download the PHP package superruzafa/rules without Composer
On this page you can find all versions of the php package superruzafa/rules. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download superruzafa/rules
More information about superruzafa/rules
Files in superruzafa/rules
Package rules
Short Description A rule engine following the condition -> action paradigm
License MIT
Informations about the package rules
Rules
A rule engine following the condition -> action paradigm
What a rule is?
A rule is build up by three elements:
One condition
Every rule has a boolean condition. If the condition is satisfied (i.e, its value is not false) then the rule is processed.
Some actions
Every rule has some associated actions. The actions could be performed at different rule's stages:
- Before the rule's condition being evaluated (regardless being satisfied or not)
- After its condition has been satisfied but before its subrules have been executed
- After both its condition has been satisfied and its subrules have been executed.
- Before leave the rule's, regardless the condition has been satisfied or not.
Zero or more subrules
Each rule could contain subrules. Each subrule is executed only if the parent rule's condition has been satisfied.
When executes, the flow a rule follows could be described as:
Quick example
Conditions
Conditions use boolean expressions to check whether the rule must be processed. By default, a rule has a as a condition.
Primitives
There are four predefined primitives:
- String
- Integer
- Float
- Boolean
Operators
Operators take one, two or more values (primitives or other operator's output) and return some other value
Logical operators
operator takes one or more arguments and returns if all of its arguments are evaluated as :
operator takes one or more arguments and returns if any of its arguments are evaluated as :
operator takes one or more arguments and returns if all of its arguments are evaluated as . This is indeed a Nand operation.
Comparison conditions
operator takes two or more arguments and returns if all of its arguments are the same:
operator takes two or more arguments and returns if any of its arguments is different from aonther one:
Actions
Override context
This action updates/extends the current context:
Interpolate context
This action allows to render the current context as a template by feeding itself as the variable replacements:
Filter context
This action filter (either by preserving or discarding) entries in a context:
Run callback
This actions calls a custom user function passing the current context as argument:
No action
This actions does nothing :)
Sequence
This actions allows to define a list of actions to be performed sequentially: