drinks-it / rule-engine
Rule Engine Bundle is a (sub)system which allows end-user to run specified actions if they met specified criteria(conditions) on specified events.
Package info
github.com/drinks-it/rule-engine
Type:symfony-bundle
pkg:composer/drinks-it/rule-engine
Requires
- php: ^8.2
- doctrine/collections: ^2.3
- doctrine/dbal: ^4.3
- doctrine/doctrine-bundle: ^2.18
- doctrine/orm: ^3.3
- langleyfoxall/math_eval: ^2.0
- psr/cache: ^3.0
- psr/log: ^3.0
- symfony/cache: 7.4.*
- symfony/config: 7.4.*
- symfony/dependency-injection: 7.4.*
- symfony/doctrine-bridge: 7.4.*
- symfony/framework-bundle: 7.4.*
- symfony/http-kernel: 7.4.*
- symfony/serializer: 7.4.*
- symfony/validator: 7.4.*
Requires (Dev)
- api-platform/doctrine-orm: ^5.0
- api-platform/symfony: ^5.0
- friendsofphp/php-cs-fixer: ^3.95
- symfony/phpunit-bridge: 7.4.*
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-main
- 4.0.1
- 4.0.0
- 3.0.0
- 2.1.0
- 2.0.2
- 2.0.1
- 2.0
- 1.0
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.4
- 0.3.3
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.10
- 0.2.9
- 0.2.8
- 0.2.7
- 0.2.6
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- 0.0.4
- 0.0.3
- 0.0.2
- 0.0.1
- dev-codex/symfony-7.4-api-platform-4
- dev-support-symfony-64
- dev-action-logs
- dev-main-upgrade
- dev-dev
- dev-feat/php-attributes
- dev-feat/boolean-condition
This package is auto-updated.
Last update: 2026-11-24 09:28:30 UTC
README
A Symfony bundle for evaluating conditions and running actions on Doctrine entities when an application event occurs. It provides rule metadata, condition and action collections, Symfony Serializer and Validator integration, custom Doctrine types, and optional API Platform schema integration.
Requirements
The current composer.json declares:
| Dependency | Constraint |
|---|---|
| PHP | ^8.2 |
| Symfony components | 7.4.* |
| Doctrine ORM | ^3.3 |
| Doctrine DBAL | ^4.3 |
| DoctrineBundle | ^2.18 |
| Doctrine Collections | ^2.3 |
The development dependencies target API Platform ^5.0 (api-platform/symfony
and api-platform/doctrine-orm). API Platform is optional for applications using
the bundle. Rule mappings use native PHP attributes; doctrine/annotations is
not required and docblock mappings are no longer read.
Installation
composer require drinks-it/rule-engine
Register the bundle in config/bundles.php alongside FrameworkBundle and
DoctrineBundle:
return [ // Other application bundles... DrinksIt\RuleEngineBundle\RuleEngineBundle::class => ['all' => true], ];
Enable Symfony Serializer and Validator in the host application:
# config/packages/framework.yaml framework: serializer: { enabled: true } validation: { enabled: true }
Doctrine configuration
Register the types used to store rule conditions, actions, and trigger events:
# config/packages/doctrine.yaml doctrine: dbal: types: rule-engine-conditions: DrinksIt\RuleEngineBundle\Doctrine\Types\ConditionsType rule-engine-action: DrinksIt\RuleEngineBundle\Doctrine\Types\ActionType rule-engine-event: DrinksIt\RuleEngineBundle\Doctrine\Types\TriggerEventType
Use these same names in your entity column mappings. The application supplies its
rule entity implementing DrinksIt\RuleEngineBundle\Rule\RuleEntityInterface,
its Doctrine mappings, and database migrations. This bundle does not provide a
make:rule-engine command.
Entity mappings
Mark Doctrine entities with RuleEntityResource and expose their properties to
conditions and actions with RuleEntityProperty. For example, add these
attributes to an existing mapped entity and property:
use DrinksIt\RuleEngineBundle\Mapping\RuleEntityProperty; use DrinksIt\RuleEngineBundle\Mapping\RuleEntityResource; use DrinksIt\RuleEngineBundle\Rule\Action\Attribute\StringActionType; use DrinksIt\RuleEngineBundle\Rule\Condition\Attribute\StringConditionAttribute; #[RuleEntityResource] class Product { #[RuleEntityProperty( condition: StringConditionAttribute::class, action: StringActionType::class, )] private string $name = ''; public function getName(): string { return $this->name; } public function setName(string $name): void { $this->name = $name; } }
The example shows the rule attributes only; retain your Doctrine entity, ID, and
column attributes. RuleEntityResource accepts an events array to restrict
applicable events. RuleEntityProperty accepts condition, action,
onlyEvents, and relationObject arguments.
See entity mapping examples and accessing rule metadata.
Events and rules
Implement DrinksIt\RuleEngineBundle\Event\RuleEventInterface for an application
rule event. With Symfony service autoconfiguration enabled, these services receive
the rule_engine.tag.event tag automatically.
Dispatch an ObserverEntityEventInterface implementation through Symfony's event
dispatcher using RuleEvent::EVENT. The observer supplies the entities to process
and the rule event class. See the event workflow and
rule creation examples. The application provides
its own endpoints and persistence logic.
Optional API Platform integration
Install the packages targeted by the current development configuration:
composer require api-platform/symfony:^5.0 api-platform/doctrine-orm:^5.0
Register ApiPlatform\Symfony\Bundle\ApiPlatformBundle in the host application.
The rule engine loads its API Platform services when that bundle class is
available, adding property normalization and JSON schema decoration for rules.
See the condition schema and
action schema documentation.
Upgrading
Applications upgrading from Symfony 6, Doctrine ORM 2, or DBAL 3 must update their dependencies to the constraints above. Review generated Doctrine migrations, including changes to legacy SQL comment hints.
Convert @RuleEntityResource and @RuleEntityProperty docblocks to PHP attributes.
The legacy RuleEntityAnnotationExtractor and annotation reader integration have
been removed. Custom extractor integrations should use
RuleEntityExtractorInterface; the default implementation is
RuleEntityAttributeExtractor.
Development
composer install vendor/bin/simple-phpunit install composer test-unit composer php-cs
Use composer php-cs-fix to apply code style fixes. The integration tests require
pdo_sqlite; the coverage command requires a coverage driver such as Xdebug.
The suite covers mappings, conditions, actions, serialization, validation, and
bundle boot with API Platform, including schema generation and SQLite round trips
for custom Doctrine types.
License
MIT.