okeyaki/preport

This package is abandoned and no longer maintained. No replacement package was suggested.

A simple PHP rule engine.

0.1.0 2015-12-27 07:36 UTC

This package is not auto-updated.

Last update: 2020-01-24 16:04:03 UTC


README

A simple PHP rule engine.

Usage

1. Build reporter.

use Preport\Reporter;

$reporter = new Reporter;

$reporter->report('too_short_input')
    ->where(function () use ($input) {
        return strlen($input) < 4;
    });

$reporter->report('too_long_input')
    ->where(function () use ($input) {
        return strlen($input) > 8;
    })
    ->unless('too_short_input');

$reporter->report('no_input')
    ->where(function () use ($input) {
        return !$input;
    });
    ->when('too_short_input');

2. Get reports.

$reports = $reporter->walk();

foreach ($reports as $report) {
    echo $report->subject();
}
> $input = 'foo';
too_short_input

> $input = '';
too_short_input
no_input

> $input = 'foobarbaz';
too_long_input