Condition.php in Entity API 8
File
src/QueryAccess/Condition.php
View source
<?php
namespace Drupal\entity\QueryAccess;
final class Condition {
protected static $supportedOperators = [
'=',
'<>',
'<',
'<=',
'>',
'>=',
'BETWEEN',
'NOT BETWEEN',
'IN',
'NOT IN',
'IS NULL',
'IS NOT NULL',
];
protected $field;
protected $value;
protected $operator;
public function __construct($field, $value, $operator = NULL) {
if (!isset($operator)) {
$operator = is_array($value) ? 'IN' : '=';
}
if (!in_array($operator, self::$supportedOperators)) {
throw new \InvalidArgumentException(sprintf('Unrecognized operator "%s".', $operator));
}
$this->field = $field;
$this->value = $value;
$this->operator = $operator;
}
public function getField() {
return $this->field;
}
public function getValue() {
return $this->value;
}
public function getOperator() {
return $this->operator;
}
public function __toString() {
if (in_array($this->operator, [
'IS NULL',
'IS NOT NULL',
])) {
return "{$this->field} {$this->operator}";
}
else {
if (is_array($this->value)) {
$value = "['" . implode("', '", $this->value) . "']";
}
else {
$value = "'" . $this->value . "'";
}
return "{$this->field} {$this->operator} {$value}";
}
}
}
Classes
Name |
Description |
Condition |
Represents a single query access condition. |