Download the PHP package vertilia/recif without Composer

On this page you can find all versions of the php package vertilia/recif. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package recif

recif: rule engine comme il faut

Rule engine parser that translates conditions from rule file in json or yaml format to native code.

Description

When businesses express new or updated rulesets, they may be either coded by programmers into the existing information system, or they may be declared in a special dialect that the system may parse and evaluate. In this case programmer's intervention is not needed, but the parsing and evaluation time may be significant. Each time the system needs to evaluate conditions from a ruleset for specific context (for example, define product segment) the system needs to parse the rule file, process conditions starting at the top level until the matching rule found, all this recursively calling methods for each operation mentioned in a ruleset.

With recif, when rulesets are updated in a rule file we call the converter that translates the rules into a native code. That code represents the ruleset conditions from the file. All operations are already translated to native constructs like OR, AND etc, so the execution of the full ruleset is optimal. To use that class inside your project instantiate the object and call its evaluate() method passing the context as its parameter. evaluate() will return true (or corresponding value) if match found, or false if passed context does not match any condition (yes, you may provide your own return value).

Example 1

Single condition. Input context is a literal numeric value that is evaluated and returns true if it is greater than 10:

Example 2

Multiple conditions combined with AND operator. Input context is a literal numeric value. Returns true if context value is in the range 0..100:

Example 3

Complex conditions: context is an associative array with country and currency entries which must match the following matrix:

country currency
DE EUR
ES EUR
FR EUR
IT EUR
US USD

If condition matches it will return continent name for the context (North America or Europe) instead of simple true value.

Note: to represent an array you need to use a special {"_": ...} inline operator.

Installation

Require with composer:

Command line usage

After installation with composer, recif binary is available as vendor/bin/recif.

Simplest ruleset: evaluate the true statement:

Same level: evaluate that 1 > 0:

Do something meaningful: check context, add namespace to generated class and specify return type of its evaluate() method:

Syntax of rule files

Rule file contains a tree of conditions starting with a root condition.

Each condition is an object with a single required entry containing operation name as key and arguments as value. An optional return entry may contain returned value for the case if operation matches, otherwise the default true will be returned.

Operators like or must contain an array of arguments. Unary operators like not operate on a single value, not an array. See [Operations reference]() for the full list of available operations.

Each argument may have one of the following forms:

Returned value represents the value that is returned to the outer operation when the corresponding condition evaluates to true. It may be declared as any type. If value is an object, it may represent context or one of its properties, like {"cx":""} or {"cx":"currency.iso_name"}. In this case the value of this element or property will be returned.

Operations reference

Examples below are given in json notation, meanings are given as php code.

Context operator

cx - context value (argument: empty string if context is literal, dot-separated list of keys if array)

Example: {"cx":""}, {"cx":"url.path"}

Meaning: $context, $context['url']['path']

Comparison operators

eq - equal

Example: {"eq": [{"cx":""}, 0]}

Meaning: $context == 0

=== - identical (equal and same type)

Example: {"===": [{"cx":""}, '15h']}

Meaning: $context === '15h'

ne - not equal

Example: {"ne": [{"cx":""}, 0]}

Meaning: $context != 0

!== - not identical (not equal or different type)

Example: {"!==": [{"cx":""}, '15h']}

Meaning: $context !== '15h'

lt - less than

Example: {"lt": [{"cx":""}, 0]}

Meaning: $context < 0

le - less or equal

Example: {"le": [{"cx":""}, 0]}

Meaning: $context <= 0

gt - greater than

Example: {"gt": [{"cx":""}, 0]}

Meaning: $context > 0

ge - greater or equal

Example: {"ge": [{"cx":""}, 0]}

Meaning: $context >= 0

Logical operators

or - or (two or more arguments)

Example: {"or": [{"eq": [{"cx":""}, 0]}, {"eq": [{"cx":""}, 10]}]}

Meaning: ($context == 0) or ($context == 10)

and - and (two or more arguments)

Example: {"and": [{"gt": [{"cx":""}, 0]}, {"lt": [{"cx":""}, 10]}]}

Meaning: ($context > 0) and ($context < 10)

not - not (unary operator, single argument)

Example: {"not": {"lt": [{"cx":""}, 0]}}

Meaning: ! ($context < 0)

Math operations

mod - modulo (arguments: value, modulo)

Example: {"mod": [{"cx":""}, 10]}

Meaning: $context % 10

rnd - random integer number within range (arguments: min, max)

Example: {"rnd": [1, 10]}

Meaning: rand(1, 10)

Array operations

in - element exists in array (arguments: element, array)

Example: {"in": [{"cx":""}, {"_": [1, 2, 3, 5, 8, 13]}]}

Meaning: in_array($context, [1, 2, 3, 5, 8, 13])

inx - get element from hash map by index (arguments: index, hash map)

Example: {"inx": [{"cx":""}, {"_": ["FR": "Europe", "US": "North America"]}]}, {"inx": [{"cx":""}, {"_": ["US": "North America", "default": "Europe"]}]}

Meaning: (["FR" => "Europe", "US" => "North America"])[$context], (["US" => "North America"])[$context] ?? "Europe"

String operations

sub - needle substring exists in haystack string (arguments: needle, haystack). Search in Unicode case-insensitive mode.

Example: {"sub": ["word", {"cx":""}]}

Meaning: mb_stripos($context, "word") !== false

re - string matches regular expression (arguments: regex, text).

Example: {"re": ["/^\w+$/u", {"cx":""}]}

Meaning: preg_match('/^\w+$/u', $context)

spf - formatted string a.k.a. sprintf (arguments: format string, zero or more values).

Example: {"spf": ["%.2f", {"cx":""}]}

Meaning: sprintf('%.2f', $context)

Inline operator

_ (underscore) - uses argument value as is (argument of any type).

Example: {"_": true}, {"_": ["a": "b"]}, {"_": [1, {"_": []}, 3]}

Meaning: true, ['a' => 'b'], [1, [], 3]

Native function call

fn - calls native function with provided params (arguments: function name, param1, ...).

Example: {"fn": ["Currencies::getRateForCountry", {"cx":"country"}]}

Meaning: Currencies::getRateForCountry($context['country'])

Code examples

Example 1

Rule file:

Generated code:

For the following examples the generated code will be created inside the Ruleset::evaluate() method, like in the example above, so only the corresponding // rules part will be presented.

Example 2

Rule file:

Generated code:

Example 3

Rule file:

Generated code:

REMARK In php-5 compatibility mode, the ($context['currency'] ?? null) and similar constructs will be replaced by isset($context['currency']) and $context['currency'] constructs.


All versions of recif with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package vertilia/recif contains the following files

Loading the files please wait ....