greaterThan() public static method

Check that a value is greater than another value.
public static greaterThan ( mixed $value ) : GreaterThan
$value mixed The compared value.
return Webmozart\Expression\Constraint\GreaterThan The created expression.
<?php

use Webmozart\Expression\Expr;
use Webmozart\Expression\Logic\Disjunction;
$rulerz = (require __DIR__ . '/../bootstrap.php');
const REPETITIONS = 10000;
$dataset = [['name' => 'Joe', 'group' => 'guest', 'points' => 50], ['name' => 'Moe', 'group' => 'member', 'points' => 25], ['name' => 'Al', 'group' => 'guest', 'points' => 30], ['name' => 'Jane', 'group' => 'admin', 'points' => 75], ['name' => 'Jude', 'group' => 'vip', 'points' => 70], ['name' => 'Lucy', 'group' => 'vip', 'points' => 72]];
$rule = '(group = "guest" and points < 40) or (group = "vip" and points > 70)';
$bench = new Hoa\Bench\Bench();
$bench->rulerz->start();
foreach (range(0, REPETITIONS) as $i) {
    $rulerz->filter($dataset, $rule);
}
$bench->rulerz->stop();
// Expression
$firstPart = Expr::lessThan(40, 'points')->andEquals('guest', 'group');
$secondPart = Expr::greaterThan(70, 'points')->andEquals('vip', 'group');
$expr = new Disjunction([$firstPart, $secondPart]);
$bench->expression->start();
foreach (range(0, REPETITIONS) as $i) {
    $results = [];
    foreach ($dataset as $row) {
        if ($expr->evaluate($row)) {
            $results[] = $row;
        }
    }
}
$bench->expression->stop();
echo $bench;
Example #2
0
 public function orGreaterThan($value)
 {
     return $this->orX(Expr::greaterThan($value));
 }
 public function __construct()
 {
     parent::__construct('getBookings', array(), Expr::count(Expr::greaterThan(0)));
 }
<?php

use Webmozart\Expression\Expr;
$rulerz = (require __DIR__ . '/../bootstrap.php');
const DATASET_SIZE = 100000;
$dataset = [];
foreach (range(0, DATASET_SIZE) as $i) {
    $dataset[] = ['name' => 'not relevant', 'points' => mt_rand(0, DATASET_SIZE)];
}
$rule = 'points > :points';
$bench = new Hoa\Bench\Bench();
$bench->rulerz->start();
$rulerz->filter($dataset, $rule, ['points' => DATASET_SIZE / 2]);
$bench->rulerz->stop();
// Expression
$expr = Expr::greaterThan(DATASET_SIZE / 2, 'points');
$bench->expression->start();
$results = [];
foreach ($dataset as $row) {
    if ($expr->evaluate($row)) {
        $results[] = $row;
    }
}
$bench->expression->stop();
echo $bench;
Example #5
0
 public function andGreaterThan($value)
 {
     return $this->andX(Expr::greaterThan($value));
 }
Example #6
0
 public function testFilterCollection()
 {
     $input = new ArrayObject(range(1, 10));
     $output = new ArrayObject(array_filter(range(1, 10), function ($i) {
         return $i > 4;
     }));
     $this->assertEquals($output, Expr::filter($input, Expr::greaterThan(4)));
 }
<?php

use Webmozart\Expression\Expr;
$rulerz = (require __DIR__ . '/../bootstrap.php');
const REPETITIONS = 10000;
$dataset = [['name' => 'Joe', 'group' => 'guest', 'points' => 50], ['name' => 'Moe', 'group' => 'member', 'points' => 25], ['name' => 'Al', 'group' => 'guest', 'points' => 30], ['name' => 'Jane', 'group' => 'admin', 'points' => 75], ['name' => 'Jude', 'group' => 'vip', 'points' => 70], ['name' => 'Lucy', 'group' => 'vip', 'points' => 72]];
$rule = 'group = "guest" and points > 42';
$bench = new Hoa\Bench\Bench();
$bench->rulerz->start();
foreach (range(0, REPETITIONS) as $i) {
    $rulerz->filter($dataset, $rule);
}
$bench->rulerz->stop();
// Expression
$expr = Expr::greaterThan(42, 'points')->andEquals('guest', 'group');
$bench->expression->start();
foreach (range(0, REPETITIONS) as $i) {
    $results = [];
    foreach ($dataset as $row) {
        if ($expr->evaluate($row)) {
            $results[] = $row;
        }
    }
}
$bench->expression->stop();
echo $bench;