summaryrefslogtreecommitdiff
path: root/vendor/doctrine/orm/src/Persisters/Collection/AbstractCollectionPersister.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/doctrine/orm/src/Persisters/Collection/AbstractCollectionPersister.php')
-rw-r--r--vendor/doctrine/orm/src/Persisters/Collection/AbstractCollectionPersister.php50
1 files changed, 50 insertions, 0 deletions
diff --git a/vendor/doctrine/orm/src/Persisters/Collection/AbstractCollectionPersister.php b/vendor/doctrine/orm/src/Persisters/Collection/AbstractCollectionPersister.php
new file mode 100644
index 0000000..26f0b9e
--- /dev/null
+++ b/vendor/doctrine/orm/src/Persisters/Collection/AbstractCollectionPersister.php
@@ -0,0 +1,50 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\ORM\Persisters\Collection;
6
7use Doctrine\DBAL\Connection;
8use Doctrine\DBAL\Platforms\AbstractPlatform;
9use Doctrine\ORM\EntityManagerInterface;
10use Doctrine\ORM\Mapping\QuoteStrategy;
11use Doctrine\ORM\UnitOfWork;
12
13/**
14 * Base class for all collection persisters.
15 */
16abstract class AbstractCollectionPersister implements CollectionPersister
17{
18 protected Connection $conn;
19 protected UnitOfWork $uow;
20 protected AbstractPlatform $platform;
21 protected QuoteStrategy $quoteStrategy;
22
23 /**
24 * Initializes a new instance of a class derived from AbstractCollectionPersister.
25 */
26 public function __construct(
27 protected EntityManagerInterface $em,
28 ) {
29 $this->uow = $em->getUnitOfWork();
30 $this->conn = $em->getConnection();
31 $this->platform = $this->conn->getDatabasePlatform();
32 $this->quoteStrategy = $em->getConfiguration()->getQuoteStrategy();
33 }
34
35 /**
36 * Check if entity is in a valid state for operations.
37 */
38 protected function isValidEntityState(object $entity): bool
39 {
40 $entityState = $this->uow->getEntityState($entity, UnitOfWork::STATE_NEW);
41
42 if ($entityState === UnitOfWork::STATE_NEW) {
43 return false;
44 }
45
46 // If Entity is scheduled for inclusion, it is not in this collection.
47 // We can assure that because it would have return true before on array check
48 return ! ($entityState === UnitOfWork::STATE_MANAGED && $this->uow->isScheduledForInsert($entity));
49 }
50}