Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / lib / Doctrine / ORM / ORMInvalidArgumentException.php
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;
21
22 /**
23  * Contains exception messages for all invalid lifecycle state exceptions inside UnitOfWork
24  *
25  * @author Benjamin Eberlei <kontakt@beberlei.de>
26  */
27 class 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         return 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                             . (method_exists($entry, '__toString') ?
66                                 "":
67                                 " If you cannot find out which entity causes the problem"
68                                ." implement '" . $assoc['targetEntity'] . "#__toString()' to get a clue."));
69     }
70
71     static public function detachedEntityFoundThroughRelationship(array $assoc, $entry)
72     {
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.");
76     }
77
78     static public function entityNotManaged($entity)
79     {
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");
82     }
83
84     static public function entityHasNoIdentity($entity, $operation)
85     {
86         return new self("Entity has no identity, therefore " . $operation ." cannot be performed. " . self::objToStr($entity));
87     }
88
89     static public function entityIsRemoved($entity, $operation)
90     {
91         return new self("Entity is removed, therefore " . $operation ." cannot be performed. " . self::objToStr($entity));
92     }
93
94     static public function detachedEntityCannot($entity, $operation)
95     {
96         return new self("A detached entity was found during " . $operation . " " . self::objToStr($entity));
97     }
98
99     public static function invalidObject($context, $given, $parameterIndex = 1)
100     {
101         return new self($context .' expects parameter ' . $parameterIndex . 
102                     ' to be an entity object, '. gettype($given) . ' given.');
103     }
104
105     /**
106      * Helper method to show an object as string.
107      *
108      * @param  object $obj
109      * @return string
110      */
111     private static function objToStr($obj)
112     {
113         return method_exists($obj, '__toString') ? (string)$obj : get_class($obj).'@'.spl_object_hash($obj);
114     }
115 }