diff options
Diffstat (limited to 'vendor/doctrine/orm/src/Persisters/Collection/AbstractCollectionPersister.php')
-rw-r--r-- | vendor/doctrine/orm/src/Persisters/Collection/AbstractCollectionPersister.php | 50 |
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 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\ORM\Persisters\Collection; | ||
6 | |||
7 | use Doctrine\DBAL\Connection; | ||
8 | use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
9 | use Doctrine\ORM\EntityManagerInterface; | ||
10 | use Doctrine\ORM\Mapping\QuoteStrategy; | ||
11 | use Doctrine\ORM\UnitOfWork; | ||
12 | |||
13 | /** | ||
14 | * Base class for all collection persisters. | ||
15 | */ | ||
16 | abstract 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 | } | ||