PageRenderTime 103ms CodeModel.GetById 60ms app.highlight 6ms RepoModel.GetById 35ms app.codeStats 0ms

/protected/extensions/doctrine/vendors/Doctrine/ORM/ORMInvalidArgumentException.php

https://bitbucket.org/NordLabs/yiidoctrine
PHP | 107 lines | 66 code | 13 blank | 28 comment | 6 complexity | 364201708588e67d13a8803902345a5f MD5 | raw file
  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 LGPL. For more information, see
 17 * <http://www.doctrine-project.org>.
 18 */
 19
 20namespace Doctrine\ORM;
 21
 22/**
 23 * Contains exception messages for all invalid lifecycle state exceptions inside UnitOfWork
 24 *
 25 * @author Benjamin Eberlei <kontakt@beberlei.de>
 26 */
 27class ORMInvalidArgumentException extends \InvalidArgumentException
 28{
 29    static public function scheduleInsertForManagedEntity($entity)
 30    {
 31        return new self("A managed+dirty entity " . self::objToStr($entity) . " can not be scheduled for insertion.");
 32    }
 33
 34    static public function scheduleInsertForRemovedEntity($entity)
 35    {
 36        return new self("Removed entity " . self::objToStr($entity) . " can not be scheduled for insertion.");
 37    }
 38
 39    static public function scheduleInsertTwice($entity)
 40    {
 41        return new self("Entity " . self::objToStr($entity) . " can not be scheduled for insertion twice.");
 42    }
 43
 44    static public function entityWithoutIdentity($className, $entity)
 45    {
 46        throw new self(
 47            "The given entity of type '" . $className . "' (".self::objToStr($entity).") has no identity/no " . 
 48            "id values set. It cannot be added to the identity map."
 49        );
 50    }
 51
 52    static public function readOnlyRequiresManagedEntity($entity)
 53    {
 54        return new self("Only managed entities can be marked or checked as read only. But " . self::objToStr($entity) . " is not");
 55    }
 56
 57    static public function newEntityFoundThroughRelationship(array $assoc, $entry)
 58    {
 59        return new self("A new entity was found through the relationship '"
 60                            . $assoc['sourceEntity'] . "#" . $assoc['fieldName'] . "' that was not"
 61                            . " configured to cascade persist operations for entity: " . self::objToStr($entry) . "."
 62                            . " To solve this issue: Either explicitly call EntityManager#persist()"
 63                            . " on this unknown entity or configure cascade persist "
 64                            . " this association in the mapping for example @ManyToOne(..,cascade={\"persist\"}). "
 65                            . " If you cannot find out which entity causes the problem"
 66                            . " implement '" . $assoc['targetEntity'] . "#__toString()' to get a clue.");
 67    }
 68
 69    static public function detachedEntityFoundThroughRelationship(array $assoc, $entry)
 70    {
 71        throw new self("A detached entity of type " . $assoc['targetEntity'] . " (" . self::objToStr($entry) . ") "
 72                        . " was found through the relationship '" . $assoc['sourceEntity'] . "#" . $assoc['fieldName'] . "' "
 73                        . "during cascading a persist operation.");
 74    }
 75
 76    static public function entityNotManaged($entity)
 77    {
 78        throw new self("Entity " . self::objToStr($entity) . " is not managed. An entity is managed if its fetched " .
 79                "from the database or registered as new through EntityManager#persist");
 80    }
 81
 82    static public function entityHasNoIdentity($entity, $operation)
 83    {
 84        throw new self("Entity has no identity, therefore " . $operation ." cannot be performed. " . self::objToStr($entity));
 85    }
 86
 87    static public function entityIsRemoved($entity, $operation)
 88    {
 89        throw new self("Entity is removed, therefore " . $operation ." cannot be performed. " . self::objToStr($entity));
 90    }
 91
 92    static public function detachedEntityCannot($entity, $operation)
 93    {
 94        throw new self("A detached entity was found during " . $operation . " " . self::objToStr($entity));
 95    }
 96
 97    /**
 98     * Helper method to show an object as string.
 99     *
100     * @param  object $obj
101     * @return string
102     */
103    private static function objToStr($obj)
104    {
105        return method_exists($obj, '__toString') ? (string)$obj : get_class($obj).'@'.spl_object_hash($obj);
106    }
107}