Security update for Core, with self-updated composer
[yaffs-website] / web / core / lib / Drupal / Core / Entity / Query / ConditionFundamentals.php
1 <?php
2
3 namespace Drupal\Core\Entity\Query;
4
5 /**
6  * Common code for all implementations of the entity query condition interfaces.
7  */
8 abstract class ConditionFundamentals {
9
10   /**
11    * Array of conditions.
12    *
13    * @var array
14    */
15   protected $conditions = [];
16
17   /**
18    * The conjunction of this condition group. The value is one of the following:
19    *
20    * - AND (default)
21    * - OR
22    *
23    * @var string
24    */
25   protected $conjunction;
26
27   /**
28    * The query this condition belongs to.
29    *
30    * @var \Drupal\Core\Entity\Query\QueryInterface
31    */
32   protected $query;
33
34   /**
35    * List of potential namespaces of the classes belonging to this condition.
36    *
37    * @var array
38    */
39   protected $namespaces = [];
40
41   /**
42    * Constructs a Condition object.
43    *
44    * @param string $conjunction
45    *   The operator to use to combine conditions: 'AND' or 'OR'.
46    * @param QueryInterface $query
47    *   The entity query this condition belongs to.
48    * @param array $namespaces
49    *   List of potential namespaces of the classes belonging to this condition.
50    */
51   public function __construct($conjunction, QueryInterface $query, $namespaces = []) {
52     $this->conjunction = $conjunction;
53     $this->query = $query;
54     $this->namespaces = $namespaces;
55   }
56
57   /**
58    * {@inheritdoc}
59    */
60   public function getConjunction() {
61     return $this->conjunction;
62   }
63
64   /**
65    * {@inheritdoc}
66    */
67   public function count() {
68     return count($this->conditions) - 1;
69   }
70
71   /**
72    * {@inheritdoc}
73    */
74   public function &conditions() {
75     return $this->conditions;
76   }
77
78   /**
79    * Implements the magic __clone function.
80    *
81    * Makes sure condition groups are cloned as well.
82    */
83   public function __clone() {
84     foreach ($this->conditions as $key => $condition) {
85       if ($condition['field'] instanceof ConditionInterface) {
86         $this->conditions[$key]['field'] = clone($condition['field']);
87       }
88     }
89   }
90
91 }