composer package updates
[openemr.git] / vendor / doctrine / orm / lib / Doctrine / ORM / Persisters / Collection / AbstractCollectionPersister.php
blob2e85b67f3b2f46afaaea5a002f879fd2797810c9
1 <?php
2 /*
3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 * This software consists of voluntary contributions made by many individuals
16 * and is licensed under the MIT license. For more information, see
17 * <http://www.doctrine-project.org>.
20 namespace Doctrine\ORM\Persisters\Collection;
22 use Doctrine\ORM\EntityManagerInterface;
23 use Doctrine\ORM\UnitOfWork;
25 /**
26 * Base class for all collection persisters.
28 * @since 2.0
29 * @author Roman Borschel <roman@code-factory.org>
31 abstract class AbstractCollectionPersister implements CollectionPersister
33 /**
34 * @var EntityManagerInterface
36 protected $em;
38 /**
39 * @var \Doctrine\DBAL\Connection
41 protected $conn;
43 /**
44 * @var UnitOfWork
46 protected $uow;
48 /**
49 * The database platform.
51 * @var \Doctrine\DBAL\Platforms\AbstractPlatform
53 protected $platform;
55 /**
56 * The quote strategy.
58 * @var \Doctrine\ORM\Mapping\QuoteStrategy
60 protected $quoteStrategy;
62 /**
63 * Initializes a new instance of a class derived from AbstractCollectionPersister.
65 * @param EntityManagerInterface $em
67 public function __construct(EntityManagerInterface $em)
69 $this->em = $em;
70 $this->uow = $em->getUnitOfWork();
71 $this->conn = $em->getConnection();
72 $this->platform = $this->conn->getDatabasePlatform();
73 $this->quoteStrategy = $em->getConfiguration()->getQuoteStrategy();
76 /**
77 * Check if entity is in a valid state for operations.
79 * @param object $entity
81 * @return bool
83 protected function isValidEntityState($entity)
85 $entityState = $this->uow->getEntityState($entity, UnitOfWork::STATE_NEW);
87 if ($entityState === UnitOfWork::STATE_NEW) {
88 return false;
91 // If Entity is scheduled for inclusion, it is not in this collection.
92 // We can assure that because it would have return true before on array check
93 return ! ($entityState === UnitOfWork::STATE_MANAGED && $this->uow->isScheduledForInsert($entity));