Giter Club home page Giter Club logo

rulerzbundle's Introduction

RulerZBundle Build Status

This bundle integrates RulerZ into Symfony.

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

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

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

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

See RulerZ's documentation for more information.

Custom operators

Custom operators can be added 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

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={">", "<", ">=", "<=", "=", "is", "!=", "and", "not", "or"}
     * )
     */
    private $rule;
}

Configuration reference

# app/config/config.yml

rulerz:
    cache: "%kernel.cache_dir%/rulerz"
    debug: "%kernel.debug%"

    targets:
        native: false
        doctrine: false
        doctrine_dbal: false
        eloquent: false
        pomm: false
        solarium: false
        elasticsearch: false

The targets section allows you to enable only the compilation targets needed by your application.

Licence

This bundle is under the MIT licence.

rulerzbundle's People

Contributors

k-phoen avatar j0k3r avatar iainmckay avatar hywan avatar jdeniau avatar marclenderink avatar nextima avatar cmnty-peterm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.