Webmozart\Expression\Selector\Key::evaluate PHP Method

evaluate() public method

public evaluate ( $value )
    public function evaluate($value)
    {
        if (!is_array($value)) {
            return false;
        }
        if (!array_key_exists($this->key, $value)) {
            return false;
        }
        return $this->expr->evaluate($value[$this->key]);
    }

Usage Example

Example #1
0
 public function testEvaluate()
 {
     $expr = new Key('key', new GreaterThan(10));
     $this->assertTrue($expr->evaluate(array('key' => 11)));
     $this->assertFalse($expr->evaluate(array('key' => 9)));
     $this->assertFalse($expr->evaluate(array()));
     $this->assertFalse($expr->evaluate('foobar'));
 }