PHPackages                             xdimedrolx/rulerz-bundle - 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. [Database &amp; ORM](/categories/database)
4. /
5. xdimedrolx/rulerz-bundle

ActiveSymfony-bundle[Database &amp; ORM](/categories/database)

xdimedrolx/rulerz-bundle
========================

Symfony2 Bundle for RulerZ

0.20.1(2y ago)0286MITPHPPHP &gt;=7.4

Since Sep 3Pushed 2y agoCompare

[ Source](https://github.com/xdimedrolx/RulerZBundle)[ Packagist](https://packagist.org/packages/xdimedrolx/rulerz-bundle)[ Docs](https://github.com/K-Phoen/RulerZBundle)[ RSS](/packages/xdimedrolx-rulerz-bundle/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (12)Versions (3)Used By (0)

RulerZBundle [![Build Status](https://camo.githubusercontent.com/ea18d3fbd79ecd5bed106ba39691abab4095cedc322cca0b3c2709023d139752/68747470733a2f2f7472617669732d63692e6f72672f4b2d50686f656e2f52756c65725a42756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/K-Phoen/RulerZBundle)
========================================================================================================================================================================================================================================================================================================

[](#rulerzbundle-)

This bundle integrates [RulerZ](https://github.com/K-Phoen/rulerz) into Symfony.

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

[](#installation)

Require the bundle:

```
composer require 'kphoen/rulerz-bundle'

```

And declare it into your `app/AppKernel.php` file:

```
public function registerBundles()
{
    return array(
        // ...
        new KPhoen\RulerZBundle\KPhoenRulerZBundle(),
    );
}
```

Usage
-----

[](#usage)

This bundle registers a `rulerz` service which is an instance of `RulerZ\RulerZ`.

```
$rulerz = $this->container->get('rulerz');

$rulerz->filter(/* ... */);
```

See [RulerZ's documentation](https://github.com/K-Phoen/rulerz/blob/master/doc/index.md)for more information.

### Custom operators

[](#custom-operators)

[Custom operators can be added](https://github.com/K-Phoen/rulerz/blob/master/doc/custom_operators.md)to RulerZ executors. The bundle provide a way to register new operators directly from the container, you just need to tag a service:

```
services:
    operator.array.like:
        class: RulerZ\Operator\ArrayExecutor\Like
        tags:
            - { name: rulerz.operator, target: native, operator: like }
```

In addition to the `rulerz.operator` tag, two other values are needed:

- `target`: the compilation target we want to register the operator for ;
- `operator`: the name that will be given to the operator in rules.

**Important**: Operators registered as classes must implement the `__invoke`magic method as RulerZ expects custom operators to be defined as callable.

### Validators

[](#validators)

A rule validator is provided by the bundle. In its simplest form, it will only validate the syntax of a given rule. Unknown variables or operators won't be detected unless you define a whitelist of accepted values.

```
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\RulerZ\Validator\Constraints as RulerZAssert;

class TaggingRule
{
    /**
     * @var string
     *
     * @Assert\NotBlank()
     * @RulerZAssert\ValidRule(
     *  allowed_variables={"title", "url", "isArchived", "isStared", "content", "language", "mimetype", "readingTime", "domainName"},
     *  allowed_operators={">", "=", "
