PHP code example of fivelab / ruler

1. Go to this page and download the library: Download fivelab/ruler library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fivelab / ruler example snippets




use FiveLab\Component\Ruler\Ruler;
use FiveLab\Component\Ruler\Target\Targets;
use FiveLab\Component\Ruler\Target\DoctrineOrmTarget;
use FiveLab\Component\Ruler\Target\ElasticaTarget;

$targets = new Targets(
    new DoctrineOrmTarget(),
    new ElasticaTarget() 
);

$ruler = new Ruler($targets);

// Apply rules
$qb = $entityManager->createQueryBuilder()
    ->from('Product', 'products')
    ->select('products');

$ruler->apply($qb, 'category.key in (:categories) and enabled = :enabled and price > :price', [
    'categories' => ['cat1', 'cat2'], 
    'enabled' => true,
    'price' => 100
]);