Skip to content

Latest commit

 

History

History
60 lines (44 loc) · 1.39 KB

satisfies.md

File metadata and controls

60 lines (44 loc) · 1.39 KB

Checking if a target satisfies a rule

This guide will show you how to filter any kind of collection using a simple language.

Here is a summary of what you will have to do:

Context

In the following examples, we'll try to check if the following "player" satisfies a rule:

$player = [
    'pseudo' => 'Joe',
    'gender' => 'M',
    'points' => 40,
];

Check if the target satisfies the rule

Let's say that we want to check if the given player is a male and has at least 30 points (don't ask why). The rule describing these constraints would look like this:

$rule  = 'gender = :gender and points > :min_points';

Where :gender and :min_points are parameters that we'll need to define as an array:

$parameters = [
    'min_points' => 30,
    'gender'     => 'M',
];

Once the rule is written and the parameters are defined, only the easiest part remains:

var_dump($rulerz->satisfies($player, $rule, $parameters)); // the parameters can be omitted if empty

// will return:
/*
bool(true)
*/

That was it!

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