View source
<?php
namespace Drupal\Core\Database\Query;
use Drupal\Core\Database\Connection;
class SelectExtender implements SelectInterface {
protected $query;
protected $connection;
protected $uniqueIdentifier;
protected $placeholder = 0;
public function __construct(SelectInterface $query, Connection $connection) {
$this->uniqueIdentifier = uniqid('', TRUE);
$this->query = $query;
$this->connection = $connection;
}
public function uniqueIdentifier() {
return $this->uniqueIdentifier;
}
public function nextPlaceholder() {
return $this->placeholder++;
}
public function addTag($tag) {
$this->query
->addTag($tag);
return $this;
}
public function hasTag($tag) {
return $this->query
->hasTag($tag);
}
public function hasAllTags() {
return call_user_func_array([
$this->query,
'hasAllTags',
], func_get_args());
}
public function hasAnyTag() {
return call_user_func_array([
$this->query,
'hasAnyTag',
], func_get_args());
}
public function addMetaData($key, $object) {
$this->query
->addMetaData($key, $object);
return $this;
}
public function getMetaData($key) {
return $this->query
->getMetaData($key);
}
public function condition($field, $value = NULL, $operator = '=') {
$this->query
->condition($field, $value, $operator);
return $this;
}
public function &conditions() {
return $this->query
->conditions();
}
public function arguments() {
return $this->query
->arguments();
}
public function where($snippet, $args = []) {
$this->query
->where($snippet, $args);
return $this;
}
public function compile(Connection $connection, PlaceholderInterface $queryPlaceholder) {
return $this->query
->compile($connection, $queryPlaceholder);
}
public function compiled() {
return $this->query
->compiled();
}
public function havingCondition($field, $value = NULL, $operator = '=') {
$this->query
->havingCondition($field, $value, $operator);
return $this;
}
public function &havingConditions() {
return $this->query
->havingConditions();
}
public function havingArguments() {
return $this->query
->havingArguments();
}
public function having($snippet, $args = []) {
$this->query
->having($snippet, $args);
return $this;
}
public function havingCompile(Connection $connection) {
return $this->query
->havingCompile($connection);
}
public function havingIsNull($field) {
$this->query
->havingIsNull($field);
return $this;
}
public function havingIsNotNull($field) {
$this->query
->havingIsNotNull($field);
return $this;
}
public function havingExists(SelectInterface $select) {
$this->query
->havingExists($select);
return $this;
}
public function havingNotExists(SelectInterface $select) {
$this->query
->havingNotExists($select);
return $this;
}
public function extend($extender_name) {
$class = $this->connection
->getDriverClass($extender_name);
return new $class($this, $this->connection);
}
public function &getFields() {
return $this->query
->getFields();
}
public function &getExpressions() {
return $this->query
->getExpressions();
}
public function &getOrderBy() {
return $this->query
->getOrderBy();
}
public function &getGroupBy() {
return $this->query
->getGroupBy();
}
public function &getTables() {
return $this->query
->getTables();
}
public function &getUnion() {
return $this->query
->getUnion();
}
public function escapeLike($string) {
return $this->query
->escapeLike($string);
}
public function escapeField($string) {
$this->query
->escapeField($string);
return $this;
}
public function getArguments(PlaceholderInterface $queryPlaceholder = NULL) {
return $this->query
->getArguments($queryPlaceholder);
}
public function isPrepared() {
return $this->query
->isPrepared();
}
public function preExecute(SelectInterface $query = NULL) {
if (!isset($query)) {
$query = $this;
}
return $this->query
->preExecute($query);
}
public function execute() {
if (!$this
->preExecute($this)) {
return NULL;
}
return $this->query
->execute();
}
public function distinct($distinct = TRUE) {
$this->query
->distinct($distinct);
return $this;
}
public function addField($table_alias, $field, $alias = NULL) {
return $this->query
->addField($table_alias, $field, $alias);
}
public function fields($table_alias, array $fields = []) {
$this->query
->fields($table_alias, $fields);
return $this;
}
public function addExpression($expression, $alias = NULL, $arguments = []) {
return $this->query
->addExpression($expression, $alias, $arguments);
}
public function join($table, $alias = NULL, $condition = NULL, $arguments = []) {
return $this->query
->join($table, $alias, $condition, $arguments);
}
public function innerJoin($table, $alias = NULL, $condition = NULL, $arguments = []) {
return $this->query
->innerJoin($table, $alias, $condition, $arguments);
}
public function leftJoin($table, $alias = NULL, $condition = NULL, $arguments = []) {
return $this->query
->leftJoin($table, $alias, $condition, $arguments);
}
public function rightJoin($table, $alias = NULL, $condition = NULL, $arguments = []) {
return $this->query
->rightJoin($table, $alias, $condition, $arguments);
}
public function addJoin($type, $table, $alias = NULL, $condition = NULL, $arguments = []) {
return $this->query
->addJoin($type, $table, $alias, $condition, $arguments);
}
public function orderBy($field, $direction = 'ASC') {
$this->query
->orderBy($field, $direction);
return $this;
}
public function orderRandom() {
$this->query
->orderRandom();
return $this;
}
public function range($start = NULL, $length = NULL) {
$this->query
->range($start, $length);
return $this;
}
public function union(SelectInterface $query, $type = '') {
$this->query
->union($query, $type);
return $this;
}
public function groupBy($field) {
$this->query
->groupBy($field);
return $this;
}
public function forUpdate($set = TRUE) {
$this->query
->forUpdate($set);
return $this;
}
public function countQuery() {
return $this->query
->countQuery();
}
public function isNull($field) {
$this->query
->isNull($field);
return $this;
}
public function isNotNull($field) {
$this->query
->isNotNull($field);
return $this;
}
public function exists(SelectInterface $select) {
$this->query
->exists($select);
return $this;
}
public function notExists(SelectInterface $select) {
$this->query
->notExists($select);
return $this;
}
public function alwaysFalse() {
$this->query
->alwaysFalse();
return $this;
}
public function __toString() {
return (string) $this->query;
}
public function __clone() {
$this->uniqueIdentifier = uniqid('', TRUE);
$this->query = clone $this->query;
}
public function __call($method, $args) {
$return = call_user_func_array([
$this->query,
$method,
], $args);
if ($return instanceof SelectInterface) {
return $this;
}
else {
return $return;
}
}
public function conditionGroupFactory($conjunction = 'AND') {
return $this->connection
->condition($conjunction);
}
public function andConditionGroup() {
return $this
->conditionGroupFactory('AND');
}
public function orConditionGroup() {
return $this
->conditionGroupFactory('OR');
}
}