Giter Site home page Giter Site 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

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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

rulerzbundle's Issues

Can not install Bundle for Symphony 4.1

My composer.json:

...
"require": {
"php": "^7.1.3",
"ext-ctype": "",
"ext-iconv": "
",
"friendsofsymfony/rest-bundle": "^2.3",
"happyr/doctrine-specification": "^0.7.2",
"jms/serializer-bundle": "^2.4",
"mark-gerarts/automapper-plus-bundle": "^1.1",
"sensio/framework-extra-bundle": "^5.2",
"symfony/console": "^4.1",
"symfony/debug": "^4.1",
"symfony/flex": "^1.0",
"symfony/framework-bundle": "^4.1",
"symfony/lts": "^4@dev",
"symfony/orm-pack": "^1.0",
"symfony/serializer": "^4.1",
"symfony/translation": "^4.1",
"symfony/twig-bundle": "^4.1",
"symfony/yaml": "^4.1"
}
...

Error:

Using version ^0.14.1 for kphoen/rulerz-bundle
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for kphoen/rulerz-bundle ^0.14.1 -> satisfiable by kphoen/rulerz-bundle[0.14.1].
- kphoen/rulerz-bundle 0.14.1 requires symfony/framework-bundle ^2.8|^3.0 -> satisfiable by symfony/framework-bundle[2.8.x-dev, 3.0.x-dev, 3.1.x-dev, 3.2.x-dev, 3.3.x-dev, 3.4.x-dev, v2.8.0, v2.8.0-BETA1, v2.8.1, v2.8.10, v2.8.11, v2.8.12, v2.8.13, v2.8.14,
v2.8.15, v2.8.16, v2.8.17, v2.8.18, v2.8.19, v2.8.2, v2.8.20, v2.8.21, v2.8.22, v2.8.23, v2.8.24, v2.8.25, v2.8.26, v2.8.27, v2.8.28, v2.8.29, v2.8.3, v2.8.30, v2.8.31, v2.8.32, v2.8.33, v2.8.34, v2.8.35, v2.8.36, v2.8.37, v2.8.38, v2.8.39, v2.8.4, v2.8.40, v2
.8.41, v2.8.42, v2.8.43, v2.8.44, v2.8.5, v2.8.6, v2.8.7, v2.8.8, v2.8.9, v3.0.0, v3.0.0-BETA1, v3.0.1, v3.0.2, v3.0.3, v3.0.4, v3.0.5, v3.0.6, v3.0.7, v3.0.8, v3.0.9, v3.1.0, v3.1.0-BETA1, v3.1.0-RC1, v3.1.1, v3.1.10, v3.1.2, v3.1.3, v3.1.4, v3.1.5, v3.1.6, v3
.1.7, v3.1.8, v3.1.9, v3.2.0, v3.2.0-BETA1, v3.2.0-RC1, v3.2.0-RC2, v3.2.1, v3.2.10, v3.2.11, v3.2.12, v3.2.13, v3.2.14, v3.2.2, v3.2.3, v3.2.4, v3.2.5, v3.2.6, v3.2.7, v3.2.8, v3.2.9, v3.3.0, v3.3.0-BETA1, v3.3.0-RC1, v3.3.1, v3.3.10, v3.3.11, v3.3.12, v3.3.13
, v3.3.14, v3.3.15, v3.3.16, v3.3.17, v3.3.18, v3.3.2, v3.3.3, v3.3.4, v3.3.5, v3.3.6, v3.3.7, v3.3.8, v3.3.9, v3.4.0, v3.4.0-BETA1, v3.4.0-BETA2, v3.4.0-BETA3, v3.4.0-BETA4, v3.4.0-RC1, v3.4.0-RC2, v3.4.1, v3.4.10, v3.4.11, v3.4.12, v3.4.13, v3.4.14, v3.4.2, v
3.4.3, v3.4.4, v3.4.5, v3.4.6, v3.4.7, v3.4.8, v3.4.9] but these conflict with your requirements or minimum-stability.

Why?

Unable to make a group specification with doctrine association

I'm trying to create a specification to get the users within a certain usergroup. User entity has an association to Usergroup entity. My group spec:

<?php

namespace MyApp\UserBundle\Service;

use RulerZ\Spec\AbstractSpecification;

class GroupsSpec extends AbstractSpecification
{
    private $groups;

    public function __construct($groups)
    {
        $this->groups = $groups;
    }

    public function getRule()
    {
        return 'groups IN (:groups)';
    }

    public function getParameters()
    {
        return [
            'groups' => $this->groups
        ];
    }
}

This is how I use it

<?php

$this->rulerz->filterSpec($qb, new GroupsSpec($usergroups));

The issue I'm getting is:

[Semantical Error] line 0, col 65 near 'groups IN (:': Error: Invalid PathExpression. StateFieldPathExpression or SingleValuedAssociationField expected.

SELECT u FROM MyApp\UserBundle\Entity\User u WHERE u.groups IN (:groups) 

Am I doing something wrong? It is a many-to-many relationship - does that change anything?

Incompatible with 0.19.3

Hi, I've just updated my project, in which I use this bundle, and it become broken due to the fact that rulerz has recently updated to 0.19.3.

The issue is in that the file RulerZ\Compiler\EvalCompiler, mentioned in Resources/config/debug.yml, does not exist anymore

Custom operator class generates invalid output

I'm trying to implement RulerZBundle in a Symfony+Doctrine project, but I'm facing some difficulties trying to define custom operators. Following the simple 'LIKE' example, the operator is defined as follows:

namespace MyProject\Infrastructure\Persistence\Doctrine\Operator;

class Like
{
    public function __invoke($a, $b)
    {
        return sprintf('%s LIKE %s', $a, $b);
    }
}

The operator is declared as service in services.yml and tagged as stated in the docs:

  operator.doctrine.like:
    class: MyProject\Infrastructure\Persistence\Doctrine\Operator\Like
    tags:
        - { name: rulerz.operator, executor: rulerz.executor.doctrine, operator: like }

The Specification using this custom operator:

namespace MyProject\Domain\Query\Item;

use MyProject\Domain\Query\Specification;

class HasNameLike implements Specification
{
    /**
     * @var
     */
    private $name;

    /**
     * HasNameLike constructor.
     * @param $name
     */
    public function __construct($name)
    {
        $this->name = $name;
    }

    /**
     * @return string
     */
    public function getRule()
    {
        return 'name like :name';
    }

    /**
     * @return array
     */
    public function getParameters()
    {
        return ['name' => $this->name];
    }
}

However, trying to run this spec through applyFilterSpec it generates the following Executor cache, that contains a Syntax Error:

<?php
namespace RulerZ\Compiled\Executor;

use RulerZ\Executor\Executor;

class Executor_a5fb7577 implements Executor
{
        use \RulerZ\Executor\DoctrineQueryBuilder\FilterTrait;
    use \RulerZ\Executor\DoctrineQueryBuilder\AutoJoinTrait;
    use \RulerZ\Executor\Polyfill\FilterBasedSatisfaction;

    private $detectedJoins = array (
);


    // name like :name
    protected function execute($target, array $operators, array $parameters)
    {
        return "call_user_func($operators["like"], @@_ROOT_ALIAS_@@.name, :name)";
    }
}

Am I correctly defining the custom operator class or is there anything else missing? I've been loking through the documentation for an example, but I have not found any.

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.