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