protected function DataComparison::doEvaluate in Rules 8.3
Evaluate the data comparison.
Parameters
mixed $data: Supplied data to test.
string $operation: Data comparison operation. Typically one of:
- "=="
- "<"
- ">"
- "contains" (for strings or arrays)
- "IN" (for arrays or lists).
mixed $value: The value to be compared against $data.
Return value
bool The evaluation of the condition.
File
- src/
Plugin/ Condition/ DataComparison.php, line 57
Class
- DataComparison
- Provides a 'Data comparison' condition.
Namespace
Drupal\rules\Plugin\ConditionCode
protected function doEvaluate($data, $operation, $value) {
$operation = $operation ? strtolower($operation) : '==';
switch ($operation) {
case '<':
return $data < $value;
case '>':
return $data > $value;
case 'contains':
return is_string($data) && strpos($data, $value) !== FALSE || is_array($data) && in_array($value, $data);
case 'in':
return is_array($value) && in_array($data, $value);
case '==':
default:
// In case both values evaluate to FALSE, further differentiate between
// NULL values and values evaluating to FALSE.
if (!$data && !$value) {
return isset($data) && isset($value) || !isset($data) && !isset($value);
}
return $data == $value;
}
}