apility/rule-builder
5,635
1
| Install | |
|---|---|
composer require apility/rule-builder |
|
| Latest Version: | v1.5.2 |
| License: | MIT |
| Last Updated: | Aug 25, 2025 |
| Links: | GitHub · Packagist |
Maintainer: thomas-alrek
Rule Builder PHP
Installation
composer require apility/rule-builder
Example usage
<?php
use Carbon\Carbon;
use Netflex\RuleBuilder\DateRules\DateRule;
// Example of a rule that matches any dates in the year 2021 except the 17th of May, 24th of December and the month of June.
$rule = DateRule::parse([
'type' => 'group',
'count' => 'all',
'children' => [
[
'type' => 'group',
'count' => 'any',
'children' => [
[
'type' => 'dateRange',
'from' => '2021-01-01',
'to' => '2022-01-01'
]
]
],
[
'type' => 'not',
'child' => [
'type' => 'group',
'count' => 'any',
'children' => [
[
'name' => '17th of May',
'type' => 'dateRange',
'from' => '2021-05-17',
'to' => '2021-05-18'
]
[
'name' => 'Christmas',
'type' => 'dateRange',
'from' => '2021-12-24',
'to' => '2021-12-25'
],
[
'name' => 'Closed for the summer',
'type' => 'dateRange',
'from' => '2021-06-01',
'to' => '2021-07-01'
]
]
]
]
]
]);
$validated = $rule->validate(Carbon::parse('2021-11-20'));
if ($validated) {
// The rule matched the given date
}
<?php
use Carbon\Carbon;
use Netflex\RuleBuilder\DateRules\DateRule;
// Example of a rule that matches every saturday and sunday in the month of September in the year 2021.
$rule = DateRule::parse([
'type' => 'group',
'count' => 'all',
'children' => [
[
'type' => 'dateRange',
'from' => '2021-09-01',
'to' => '2022-10-01'
],
[
'type' => 'dayOfWeek',
'days' => [6, 0]
]
]
]);
$validated = $rule->validate(Carbon::parse('2021-09-22'));
if ($validated) {
// The rule matched the given date
}
Related Packages
doctrine/dbal
Powerful PHP database abstraction layer (DBAL) with many features for database s...
641,106,524
9,700
laravel/serializable-closure
Laravel Serializable Closure provides an easy and secure way to serialize closur...
418,291,778
609
nunomaduro/collision
Cli error handling for console/command-line PHP applications.
394,964,158
4,660
Version History
| Version | Released | Laravel | License |
|---|---|---|---|
| v1.5.2 | ^7.0| | MIT | |
| v1.5.1 | ^7.0 | | MIT | |
| v1.5.0 | ^7.0 | | MIT | |
| v1.4.1 | ^7.0 | | MIT | |
| v1.4.0 | ^8.0 | | MIT | |
| v1.3.2 | ^8.60 | MIT | |
| v1.3.1 | ^8.60 | MIT | |
| v1.3.0 | ^8.60 | MIT | |
| v1.2.1 | ^8.60 | MIT | |
| v1.2.0 | ^8.60 | MIT | |
| v1.1.1 | ^8.60 | MIT | |
| v1.1.0 | ^8.60 | MIT | |
| v1.0.0 | ^8.60 | MIT |