Security update for Core, with self-updated composer
[yaffs-website] / web / core / lib / Drupal / Core / Entity / Query / QueryFactory.php
1 <?php
2
3 namespace Drupal\Core\Entity\Query;
4
5 use Drupal\Core\Entity\EntityManagerInterface;
6 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
7 use Symfony\Component\DependencyInjection\ContainerAwareTrait;
8
9 /**
10  * Factory class Creating entity query objects.
11  *
12  * Any implementation of this service must call getQuery()/getAggregateQuery()
13  * of the corresponding entity storage.
14  *
15  * @see \Drupal\Core\Entity\EntityStorageBase::getQuery()
16  *
17  * @deprecated in Drupal 8.3.0, will be removed before Drupal 9.0.0. Use
18  *   \Drupal\Core\Entity\EntityStorageInterface::getQuery() or
19  *   \Drupal\Core\Entity\EntityStorageInterface::getAggregateQuery() instead.
20  */
21 class QueryFactory implements ContainerAwareInterface {
22
23   use ContainerAwareTrait;
24
25   /**
26    * Stores the entity manager used by the query.
27    *
28    * @var \Drupal\Core\Entity\EntityManagerInterface
29    */
30   protected $entityManager;
31
32   /**
33    * Constructs a QueryFactory object.
34    *
35    * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
36    *   The entity manager used by the query.
37    */
38   public function __construct(EntityManagerInterface $entity_manager) {
39     $this->entityManager = $entity_manager;
40   }
41
42   /**
43    * Returns a query object for a given entity type.
44    *
45    * @param string $entity_type_id
46    *   The entity type ID.
47    * @param string $conjunction
48    *   - AND: all of the conditions on the query need to match.
49    *   - OR: at least one of the conditions on the query need to match.
50    *
51    * @return \Drupal\Core\Entity\Query\QueryInterface
52    *   The query object that can query the given entity type.
53    */
54   public function get($entity_type_id, $conjunction = 'AND') {
55     return $this->entityManager->getStorage($entity_type_id)->getQuery($conjunction);
56   }
57
58   /**
59    * Returns an aggregated query object for a given entity type.
60    *
61    * @param string $entity_type_id
62    *   The entity type ID.
63    * @param string $conjunction
64    *   - AND: all of the conditions on the query need to match.
65    *   - OR: at least one of the conditions on the query need to match.
66    *
67    * @return \Drupal\Core\Entity\Query\QueryAggregateInterface
68    *   The aggregated query object that can query the given entity type.
69    */
70   public function getAggregate($entity_type_id, $conjunction = 'AND') {
71     return $this->entityManager->getStorage($entity_type_id)->getAggregateQuery($conjunction);
72   }
73
74 }