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;
23 * Contains exception messages for all invalid lifecycle state exceptions inside UnitOfWork
25 * @author Benjamin Eberlei <kontakt@beberlei.de>
27 class ORMInvalidArgumentException extends \InvalidArgumentException
29 static public function scheduleInsertForManagedEntity($entity)
31 return new self("A managed+dirty entity " . self::objToStr($entity) . " can not be scheduled for insertion.");
34 static public function scheduleInsertForRemovedEntity($entity)
36 return new self("Removed entity " . self::objToStr($entity) . " can not be scheduled for insertion.");
39 static public function scheduleInsertTwice($entity)
41 return new self("Entity " . self::objToStr($entity) . " can not be scheduled for insertion twice.");
44 static public function entityWithoutIdentity($className, $entity)
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."
52 static public function readOnlyRequiresManagedEntity($entity)
54 return new self("Only managed entities can be marked or checked as read only. But " . self::objToStr($entity) . " is not");
57 static public function newEntityFoundThroughRelationship(array $assoc, $entry)
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 . (method_exists($entry, '__toString') ?
67 " If you cannot find out which entity causes the problem"
68 ." implement '" . $assoc['targetEntity'] . "#__toString()' to get a clue."));
71 static public function detachedEntityFoundThroughRelationship(array $assoc, $entry)
73 return new self("A detached entity of type " . $assoc['targetEntity'] . " (" . self::objToStr($entry) . ") "
74 . " was found through the relationship '" . $assoc['sourceEntity'] . "#" . $assoc['fieldName'] . "' "
75 . "during cascading a persist operation.");
78 static public function entityNotManaged($entity)
80 return new self("Entity " . self::objToStr($entity) . " is not managed. An entity is managed if its fetched " .
81 "from the database or registered as new through EntityManager#persist");
84 static public function entityHasNoIdentity($entity, $operation)
86 return new self("Entity has no identity, therefore " . $operation ." cannot be performed. " . self::objToStr($entity));
89 static public function entityIsRemoved($entity, $operation)
91 return new self("Entity is removed, therefore " . $operation ." cannot be performed. " . self::objToStr($entity));
94 static public function detachedEntityCannot($entity, $operation)
96 return new self("A detached entity was found during " . $operation . " " . self::objToStr($entity));
99 public static function invalidObject($context, $given, $parameterIndex = 1)
101 return new self($context .' expects parameter ' . $parameterIndex .
102 ' to be an entity object, '. gettype($given) . ' given.');
106 * Helper method to show an object as string.
111 private static function objToStr($obj)
113 return method_exists($obj, '__toString') ? (string)$obj : get_class($obj).'@'.spl_object_hash($obj);