QueryConditionTrait.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace Drupal\Core\Database\Query;
  3. use Drupal\Core\Database\Connection;
  4. /**
  5. * Provides an implementation of ConditionInterface.
  6. *
  7. * @see \Drupal\Core\Database\Query\ConditionInterface
  8. */
  9. trait QueryConditionTrait {
  10. /**
  11. * The condition object for this query.
  12. *
  13. * Condition handling is handled via composition.
  14. *
  15. * @var \Drupal\Core\Database\Query\Condition
  16. */
  17. protected $condition;
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public function condition($field, $value = NULL, $operator = '=') {
  22. $this->condition->condition($field, $value, $operator);
  23. return $this;
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function isNull($field) {
  29. $this->condition->isNull($field);
  30. return $this;
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function isNotNull($field) {
  36. $this->condition->isNotNull($field);
  37. return $this;
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function exists(SelectInterface $select) {
  43. $this->condition->exists($select);
  44. return $this;
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function notExists(SelectInterface $select) {
  50. $this->condition->notExists($select);
  51. return $this;
  52. }
  53. /**
  54. * {@inheritdoc}
  55. */
  56. public function &conditions() {
  57. return $this->condition->conditions();
  58. }
  59. /**
  60. * {@inheritdoc}
  61. */
  62. public function arguments() {
  63. return $this->condition->arguments();
  64. }
  65. /**
  66. * {@inheritdoc}
  67. */
  68. public function where($snippet, $args = []) {
  69. $this->condition->where($snippet, $args);
  70. return $this;
  71. }
  72. /**
  73. * {@inheritdoc}
  74. */
  75. public function compile(Connection $connection, PlaceholderInterface $queryPlaceholder) {
  76. $this->condition->compile($connection, $queryPlaceholder);
  77. }
  78. /**
  79. * {@inheritdoc}
  80. */
  81. public function compiled() {
  82. return $this->condition->compiled();
  83. }
  84. /**
  85. * {@inheritdoc}
  86. */
  87. public function conditionGroupFactory($conjunction = 'AND') {
  88. return new Condition($conjunction);
  89. }
  90. /**
  91. * {@inheritdoc}
  92. */
  93. public function andConditionGroup() {
  94. return $this->conditionGroupFactory('AND');
  95. }
  96. /**
  97. * {@inheritdoc}
  98. */
  99. public function orConditionGroup() {
  100. return $this->conditionGroupFactory('OR');
  101. }
  102. }