function Condition::match
Same name in other branches
- 9 core/lib/Drupal/Core/Config/Entity/Query/Condition.php \Drupal\Core\Config\Entity\Query\Condition::match()
- 8.9.x core/lib/Drupal/Core/Config/Entity/Query/Condition.php \Drupal\Core\Config\Entity\Query\Condition::match()
- 11.x core/lib/Drupal/Core/Config/Entity/Query/Condition.php \Drupal\Core\Config\Entity\Query\Condition::match()
Perform the actual matching.
Parameters
array $condition: The condition array as created by the condition() method.
string $value: The value to match against.
Return value
bool TRUE when matches else FALSE.
1 call to Condition::match()
- Condition::matchArray in core/
lib/ Drupal/ Core/ Config/ Entity/ Query/ Condition.php - Matches for an array representing one or more config paths.
File
-
core/
lib/ Drupal/ Core/ Config/ Entity/ Query/ Condition.php, line 163
Class
- Condition
- Defines the condition class for the config entity query.
Namespace
Drupal\Core\Config\Entity\QueryCode
protected function match(array $condition, $value) {
// "IS NULL" and "IS NOT NULL" conditions can also deal with array values,
// so we return early for them to avoid problems.
if (in_array($condition['operator'], [
'IS NULL',
'IS NOT NULL',
], TRUE)) {
$should_be_set = $condition['operator'] === 'IS NOT NULL';
return $should_be_set === isset($value);
}
if (isset($value)) {
// We always want a case-insensitive match.
if (!is_bool($value)) {
$value = mb_strtolower($value);
}
switch ($condition['operator']) {
case '=':
return $value == $condition['value'];
case '>':
return $value > $condition['value'];
case '<':
return $value < $condition['value'];
case '>=':
return $value >= $condition['value'];
case '<=':
return $value <= $condition['value'];
case '<>':
return $value != $condition['value'];
case 'IN':
return array_search($value, $condition['value']) !== FALSE;
case 'NOT IN':
return array_search($value, $condition['value']) === FALSE;
case 'STARTS_WITH':
return str_starts_with($value, $condition['value']);
case 'CONTAINS':
return str_contains($value, $condition['value']);
case 'ENDS_WITH':
return str_ends_with($value, $condition['value']);
default:
throw new QueryException('Invalid condition operator.');
}
}
return FALSE;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.