Cache
9 months ago
Decorator
9 months ago
Event
9 months ago
Exception
9 months ago
Id
9 months ago
Internal
9 months ago
Mapping
9 months ago
Persisters
8 months ago
Proxy
9 months ago
Query
9 months ago
Repository
9 months ago
Tools
9 months ago
Utility
9 months ago
AbstractQuery.php
9 months ago
Cache.php
9 months ago
Configuration.php
9 months ago
EntityManager.php
9 months ago
EntityManagerInterface.php
9 months ago
EntityNotFoundException.php
9 months ago
EntityRepository.php
9 months ago
Events.php
9 months ago
LazyCriteriaCollection.php
9 months ago
NativeQuery.php
9 months ago
NoResultException.php
9 months ago
NonUniqueResultException.php
9 months ago
ORMException.php
9 months ago
ORMInvalidArgumentException.php
9 months ago
ORMSetup.php
9 months ago
OptimisticLockException.php
9 months ago
PersistentCollection.php
9 months ago
PessimisticLockException.php
9 months ago
Query.php
9 months ago
QueryBuilder.php
9 months ago
TransactionRequiredException.php
9 months ago
UnexpectedResultException.php
9 months ago
UnitOfWork.php
9 months ago
Version.php
9 months ago
index.php
9 months ago
LazyCriteriaCollection.php
60 lines
| 1 | <?php |
| 2 | declare (strict_types=1); |
| 3 | namespace MailPoetVendor\Doctrine\ORM; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use MailPoetVendor\Doctrine\Common\Collections\AbstractLazyCollection; |
| 6 | use MailPoetVendor\Doctrine\Common\Collections\ArrayCollection; |
| 7 | use MailPoetVendor\Doctrine\Common\Collections\Criteria; |
| 8 | use MailPoetVendor\Doctrine\Common\Collections\Selectable; |
| 9 | use MailPoetVendor\Doctrine\ORM\Persisters\Entity\EntityPersister; |
| 10 | use ReturnTypeWillChange; |
| 11 | use function assert; |
| 12 | class LazyCriteriaCollection extends AbstractLazyCollection implements Selectable |
| 13 | { |
| 14 | protected $entityPersister; |
| 15 | protected $criteria; |
| 16 | private $count; |
| 17 | public function __construct(EntityPersister $entityPersister, Criteria $criteria) |
| 18 | { |
| 19 | $this->entityPersister = $entityPersister; |
| 20 | $this->criteria = $criteria; |
| 21 | } |
| 22 | #[\ReturnTypeWillChange] |
| 23 | public function count() |
| 24 | { |
| 25 | if ($this->isInitialized()) { |
| 26 | return $this->collection->count(); |
| 27 | } |
| 28 | // Return cached result in case count query was already executed |
| 29 | if ($this->count !== null) { |
| 30 | return $this->count; |
| 31 | } |
| 32 | return $this->count = $this->entityPersister->count($this->criteria); |
| 33 | } |
| 34 | public function isEmpty() |
| 35 | { |
| 36 | if ($this->isInitialized()) { |
| 37 | return $this->collection->isEmpty(); |
| 38 | } |
| 39 | return !$this->count(); |
| 40 | } |
| 41 | public function contains($element) |
| 42 | { |
| 43 | if ($this->isInitialized()) { |
| 44 | return $this->collection->contains($element); |
| 45 | } |
| 46 | return $this->entityPersister->exists($element, $this->criteria); |
| 47 | } |
| 48 | public function matching(Criteria $criteria) |
| 49 | { |
| 50 | $this->initialize(); |
| 51 | assert($this->collection instanceof Selectable); |
| 52 | return $this->collection->matching($criteria); |
| 53 | } |
| 54 | protected function doInitialize() |
| 55 | { |
| 56 | $elements = $this->entityPersister->loadCriteria($this->criteria); |
| 57 | $this->collection = new ArrayCollection($elements); |
| 58 | } |
| 59 | } |
| 60 |