"Fossies" - the Fresh Open Source Software Archive

Member "Symfony/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Collection/AbstractCollectionPersister.php" (17 Dec 2017, 2948 Bytes) of package /linux/www/Symfony_Standard_Vendors_3.4.39.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AbstractCollectionPersister.php" see the Fossies "Dox" file reference documentation.

    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.
   14  *
   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>.
   18  */
   19 
   20 namespace Doctrine\ORM\Persisters\Collection;
   21 
   22 use Doctrine\ORM\EntityManagerInterface;
   23 use Doctrine\ORM\UnitOfWork;
   24 
   25 /**
   26  * Base class for all collection persisters.
   27  *
   28  * @since 2.0
   29  * @author Roman Borschel <roman@code-factory.org>
   30  */
   31 abstract class AbstractCollectionPersister implements CollectionPersister
   32 {
   33     /**
   34      * @var EntityManagerInterface
   35      */
   36     protected $em;
   37 
   38     /**
   39      * @var \Doctrine\DBAL\Connection
   40      */
   41     protected $conn;
   42 
   43     /**
   44      * @var UnitOfWork
   45      */
   46     protected $uow;
   47 
   48     /**
   49      * The database platform.
   50      *
   51      * @var \Doctrine\DBAL\Platforms\AbstractPlatform
   52      */
   53     protected $platform;
   54 
   55     /**
   56      * The quote strategy.
   57      *
   58      * @var \Doctrine\ORM\Mapping\QuoteStrategy
   59      */
   60     protected $quoteStrategy;
   61 
   62     /**
   63      * Initializes a new instance of a class derived from AbstractCollectionPersister.
   64      *
   65      * @param EntityManagerInterface $em
   66      */
   67     public function __construct(EntityManagerInterface $em)
   68     {
   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();
   74     }
   75 
   76     /**
   77      * Check if entity is in a valid state for operations.
   78      *
   79      * @param object $entity
   80      *
   81      * @return bool
   82      */
   83     protected function isValidEntityState($entity)
   84     {
   85         $entityState = $this->uow->getEntityState($entity, UnitOfWork::STATE_NEW);
   86 
   87         if ($entityState === UnitOfWork::STATE_NEW) {
   88             return false;
   89         }
   90 
   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));
   94     }
   95 }