When this, then that.­ The PHP Rules Engine

Define complex logic using a fluent, chainable API. Framework-agnostic core with platform-specific extensions.

Fluent Syntax

Chain conditions and actions with expressive, readable syntax that mirrors how you think about rules.

Framework Agnostic

Core engine works with any PHP application. No framework lock-in, just clean PHP.

Extensible

Add custom conditions, actions, and packages to fit your unique requirements.

PHP 7.4+
Open Source
Powers MilliCache

Complex Logic, Simple Code

Define rules declaratively. No nested conditionals, no callback spaghetti — just clean, reusable logic that keeps your codebase DRY.

Built to Extend

A minimal core that does one thing well. Framework packages add the rest.

Core Package

Pure PHP — No Dependencies

The rules engine itself: define, register, collect, and execute rules. Works with any PHP application — Laravel, Symfony, or vanilla PHP.

Provides

  • Fluent rule builder ( Rules::create() , ->when() , ->then() )
  • HTTP-focused conditions (URL, method, headers, cookies)
  • Lazy-loaded Context object for request data
  • Package loading and auto-discovery

You call the shots: Without a framework package, you decide when to execute rules via MilliRules::execute_rules() .

WordPress Package

Bundled & Ready to Use

Extends the core with WordPress integration. Includes useful conditions like user_can() and supports all WordPress is_*() and has_*() conditionals out of the box.

Adds

  • Hook binding->on('init') attaches rules to WP hooks automatically
  • WP conditionsis_singular() , user_can() , and many more
  • Context providers — user, post, query data via $ctx->get('user.id')
  • Placeholder resolvers — use {user.login} in action arguments

Zero setup: The WP package is bundled and only loads when WordPress is detected. Use ->on() or any WP condition — MilliRules registers it automatically.

Create Your Own Packages

The same architecture powers both the core and WP packages. Build a WooCommerce package, a Laravel package, or anything else.

Powers MilliCache

See Rules in Action

MilliRules is the rule engine behind MilliCache, our Redis-powered full-page cache for WordPress. Every cache rule, TTL setting, and flag assignment uses the same fluent API.

  • Define cache rules with WordPress conditionals
  • Tag content with flags for surgical cache invalidation
  • Control TTL per page type, user role, or any condition
millicache-rule.php
 1use MilliPress\MilliRules\Rules;
 2
 3// MilliCache uses MilliRules under the hood
 4Rules::create('cache-blog-posts')
 5    ->on('template_redirect')
 6    ->when()
 7        ->is_singular('post')
 8        ->is_user_logged_in(false)
 9    ->then()
10        ->set_ttl(3600)
11        ->add_flag('post:{post.id}')
12        ->add_flag('blog')
13    ->register();
14
15// Invalidate when post is updated
16Rules::create('clear-post-cache')
17    ->on('save_post')
18    ->then()
19        ->clear_flag('post:{post.id}')
20    ->register();