Search by

phil / rules-bundle

phil

Store named business rules and check them anywhere in Symfony: conditions as tagged services, evaluated with the facts of the request or the user.

Package info

github.com/parler-haut-interagir-librement/rules-bundle

Homepage

Type:symfony-bundle

pkg:composer/phil/rules-bundle

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.0-alpha 2026-11-29 22:00 UTC

This package is auto-updated.

Last update: 2026-11-30 02:53:56 UTC


README

Symfony integration of rules: named stored rules with conditions as tagged services.

phil/rules-bundle brings the rules of phil/rules into a Symfony application. A rule is stored once under a stable name — course:intro/prerequisites, members-only, free-shipping — and every part of the application asks for it by that name: a voter, a price book, a list of lessons. The library alone suits an application without Symfony.

  • Scopes: each scope accepts its own condition types, so that a price rule cannot name a condition of access. The generic comparisons of phil/rules serve every scope; a package or the application adds its types with #[AsConditionType] or a tag.
  • Stored by name, safely edited: rules are checked against their scope before they are kept in Doctrine, in their canonical JSON form with a fingerprint. Each change is made on the revision its editor read; one made on an older revision is refused rather than written over another.
  • Fast in a worker: a rule is read and compiled once per request, kept for the rest of it, and forgotten between two requests, so that a revision stored elsewhere is read on the next one.
  • In Symfony Security: is_granted('rule:<name>', subject) evaluates the rule with the facts the application's providers give about the subject and the person signed in. A missing, broken or failing rule refuses.
  • Checked from the command line: phil:rules:lint checks rule files against a scope, phil:rules:list finds the stored rules a scope no longer accepts, and phil:rules:types describes the types for a rule builder.

Status

Part State
PhilRulesBundle and its configuration phil_rules Implemented and tested
Scopes and their condition types, #[AsConditionType] Implemented and tested
Named rules stored with Doctrine, revisions, events Implemented and tested
Fact providers and the voter rule:<name> Implemented and tested
The commands phil:rules:lint, phil:rules:list, phil:rules:types Implemented and tested

Documentation

Document What it covers
Installation Requirements, installing, the table, a first rule.
Configuration Every option, with an example.
Named rules Scopes, condition types, storing and revising, facts, the voter, the commands.
Extension points The services to replace, the tags to add to, and when they are stable.
Testing The bundle's tests and its benchmark.
Reference Every class and service of the bundle.

Quick start

// config/bundles.php
Phil\RulesBundle\PhilRulesBundle::class => ['all' => true],
# config/packages/phil_rules.yaml
phil_rules:
    scopes: [course.access]
$rules->define('course:intro/prerequisites', 'course.access', '{"version": 1, "condition": {"all": [
    {"type": "lesson.completed", "operands": {"lesson": "welcome"}},
    {"type": "fact.equals", "operands": {"fact": "role", "value": "student"}}
]}}');
{% if is_granted('rule:course:intro/prerequisites', course) %}

Requirements

PHP 8.5 or later with the extension mbstring, Symfony 8.2 or later, and Doctrine ORM 3 for the stored rules.

Contributing

Contributions are welcome on the PHIL monorepo: read the contribution guide and the code of conduct. Report a vulnerability privately, as the security policy explains, never in a public issue.

License

MIT, © Philippe Gamache, doing business as Le Gnome Archiviste; a Parler Haut Interagir Librement project. See LICENSE.