public function ClosureExpressionVisitor::walkComparison in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/doctrine/collections/lib/Doctrine/Common/Collections/Expr/ClosureExpressionVisitor.php \Doctrine\Common\Collections\Expr\ClosureExpressionVisitor::walkComparison()
Converts a comparison expression into the target query language output.
Parameters
Comparison $comparison:
Return value
mixed
Overrides ExpressionVisitor::walkComparison
File
- vendor/
doctrine/ collections/ lib/ Doctrine/ Common/ Collections/ Expr/ ClosureExpressionVisitor.php, line 107
Class
- ClosureExpressionVisitor
- Walks an expression graph and turns it into a PHP closure.
Namespace
Doctrine\Common\Collections\ExprCode
public function walkComparison(Comparison $comparison) {
$field = $comparison
->getField();
$value = $comparison
->getValue()
->getValue();
// shortcut for walkValue()
switch ($comparison
->getOperator()) {
case Comparison::EQ:
return function ($object) use ($field, $value) {
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) === $value;
};
case Comparison::NEQ:
return function ($object) use ($field, $value) {
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) !== $value;
};
case Comparison::LT:
return function ($object) use ($field, $value) {
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) < $value;
};
case Comparison::LTE:
return function ($object) use ($field, $value) {
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) <= $value;
};
case Comparison::GT:
return function ($object) use ($field, $value) {
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) > $value;
};
case Comparison::GTE:
return function ($object) use ($field, $value) {
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) >= $value;
};
case Comparison::IN:
return function ($object) use ($field, $value) {
return in_array(ClosureExpressionVisitor::getObjectFieldValue($object, $field), $value);
};
case Comparison::NIN:
return function ($object) use ($field, $value) {
return !in_array(ClosureExpressionVisitor::getObjectFieldValue($object, $field), $value);
};
case Comparison::CONTAINS:
return function ($object) use ($field, $value) {
return false !== strpos(ClosureExpressionVisitor::getObjectFieldValue($object, $field), $value);
};
default:
throw new \RuntimeException("Unknown comparison operator: " . $comparison
->getOperator());
}
}