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
;
26 * Base class for all collection persisters.
29 * @author Roman Borschel <roman@code-factory.org>
31 abstract class AbstractCollectionPersister
implements CollectionPersister
34 * @var EntityManagerInterface
39 * @var \Doctrine\DBAL\Connection
49 * The database platform.
51 * @var \Doctrine\DBAL\Platforms\AbstractPlatform
58 * @var \Doctrine\ORM\Mapping\QuoteStrategy
60 protected $quoteStrategy;
63 * Initializes a new instance of a class derived from AbstractCollectionPersister.
65 * @param EntityManagerInterface $em
67 public function __construct(EntityManagerInterface
$em)
70 $this->uow
= $em->getUnitOfWork();
71 $this->conn
= $em->getConnection();
72 $this->platform
= $this->conn
->getDatabasePlatform();
73 $this->quoteStrategy
= $em->getConfiguration()->getQuoteStrategy();
77 * Check if entity is in a valid state for operations.
79 * @param object $entity
83 protected function isValidEntityState($entity)
85 $entityState = $this->uow
->getEntityState($entity, UnitOfWork
::STATE_NEW
);
87 if ($entityState === UnitOfWork
::STATE_NEW
) {
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));