PHPackages                             chocochaos/propel-rulable-behavior - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. chocochaos/propel-rulable-behavior

ActivePropel-behavior[Utility &amp; Helpers](/categories/utility)

chocochaos/propel-rulable-behavior
==================================

Allows defining buisiness rules in centralised classes and adding them to your models and query classes.

1.0(8y ago)030.5k↓48.1%MITPHPPHP &gt;=7.1.0

Since May 12Pushed 2y ago1 watchersCompare

[ Source](https://github.com/chocochaos/propel-rulable-behavior)[ Packagist](https://packagist.org/packages/chocochaos/propel-rulable-behavior)[ RSS](/packages/chocochaos-propel-rulable-behavior/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

Rulable behavior for Propel 2
=============================

[](#rulable-behavior-for-propel-2)

When writing real-world applications, you often have to deal with complex business rules. Maintaining these rules can be tedious and prone to errors, especially if they have to be checked in multiple places. It is easy to miss one implementation of a rule while making changes.

In propel you can already add your own methods to query and object classes. Even then, you are still defining the same logic in multiple places: in the query classes to filter your query results based on a rule, and in the models themselves, to check if a specific object meets a certain rule.

This behavior allows you to define business rules in centralised classes. Both your query filters and your model checks can be defined in one place. Upon building the schemas, convenient methods for checking these rules are added to the query and model classes, resulting in cleaner and more easily maintainable code.

Installation
------------

[](#installation)

```
composer require chocochaos/propel-rulable-behavior

```

Usage
-----

[](#usage)

### Defining a rule

[](#defining-a-rule)

To define a rule, first create a new directory in your models directory called `Rules`. This directory should be on the same level as the `Base` and `Map` directories generated by Propel.

[![Screenshot of the directory structure.](https://camo.githubusercontent.com/81cbe632ccf04cf37fe632838772ac897b50af4da382447f2273d8f313823987/68747470733a2f2f66696c6564756d702e63686f636f6368616f732e636f6d2f4769744875622f52756c61626c652f4469726563746f72795374727563747572652e706e67)](https://camo.githubusercontent.com/81cbe632ccf04cf37fe632838772ac897b50af4da382447f2273d8f313823987/68747470733a2f2f66696c6564756d702e63686f636f6368616f732e636f6d2f4769744875622f52756c61626c652f4469726563746f72795374727563747572652e706e67)

Next, create a new class for your rule in this directory (with proper namespacing of course). For example:

```
