本文整理汇总了PHP中Webmozart\Expression\Expr::filter方法的典型用法代码示例。如果您正苦于以下问题:PHP Expr::filter方法的具体用法?PHP Expr::filter怎么用?PHP Expr::filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Webmozart\Expression\Expr
的用法示例。
在下文中一共展示了Expr::filter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDomainExpressions
public function testDomainExpressions()
{
$c1 = new Customer();
$c1->setPremium(true);
$c2 = new Customer();
$c2->setBookings(array('booking1', 'booking2'));
$c3 = new Customer();
$c3->setPremium(true);
$c3->setBookings(array('booking1'));
$customers = array($c1, $c2, $c3);
$this->assertEquals(array($c1, 2 => $c3), Expr::filter($customers, new IsPremium()));
$this->assertEquals(array(1 => $c2, 2 => $c3), Expr::filter($customers, new HasPreviousBookings()));
$this->assertEquals(array(2 => $c3), Expr::filter($customers, Expr::andX(array(new HasPreviousBookings(), new IsPremium()))));
}
示例2: findBindings
/**
* {@inheritdoc}
*/
public function findBindings($typeName, Expression $expr = null)
{
Assert::stringNotEmpty($typeName, 'The type class must be a non-empty string. Got: %s');
if (!isset($this->keysByTypeName[$typeName])) {
return array();
}
$key = $this->keysByTypeName[$typeName];
if (!isset($this->bindingsByKey[$key])) {
$this->loadBindingsForKey($key);
}
$bindings = $this->bindingsByKey[$key];
if (null !== $expr) {
$bindings = Expr::filter($bindings, $expr);
}
return $bindings;
}
示例3: testFilterCollection
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)));
}