ORMException.php 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. use Exception;
  21. /**
  22. * Base exception class for all ORM exceptions.
  23. *
  24. * @author Roman Borschel <roman@code-factory.org>
  25. * @since 2.0
  26. */
  27. class ORMException extends Exception
  28. {
  29. public static function missingMappingDriverImpl()
  30. {
  31. return new self("It's a requirement to specify a Metadata Driver and pass it ".
  32. "to Doctrine\ORM\Configuration::setMetadataDriverImpl().");
  33. }
  34. public static function entityMissingForeignAssignedId($entity, $relatedEntity)
  35. {
  36. return new self(
  37. "Entity of type " . get_class($entity) . " has identity through a foreign entity " . get_class($relatedEntity) . ", " .
  38. "however this entity has no ientity itself. You have to call EntityManager#persist() on the related entity " .
  39. "and make sure it an identifier was generated before trying to persist '" . get_class($entity) . "'. In case " .
  40. "of Post Insert ID Generation (such as MySQL Auto-Increment or PostgreSQL SERIAL) this means you have to call " .
  41. "EntityManager#flush() between both persist operations."
  42. );
  43. }
  44. public static function entityMissingAssignedId($entity)
  45. {
  46. return new self("Entity of type " . get_class($entity) . " is missing an assigned ID. " .
  47. "The identifier generation strategy for this entity requires the ID field to be populated before ".
  48. "EntityManager#persist() is called. If you want automatically generated identifiers instead " .
  49. "you need to adjust the metadata mapping accordingly."
  50. );
  51. }
  52. public static function unrecognizedField($field)
  53. {
  54. return new self("Unrecognized field: $field");
  55. }
  56. /**
  57. * @param string $className
  58. * @param string $field
  59. */
  60. public static function invalidOrientation($className, $field)
  61. {
  62. return new self("Invalid order by orientation specified for " . $className . "#" . $field);
  63. }
  64. public static function invalidFlushMode($mode)
  65. {
  66. return new self("'$mode' is an invalid flush mode.");
  67. }
  68. public static function entityManagerClosed()
  69. {
  70. return new self("The EntityManager is closed.");
  71. }
  72. public static function invalidHydrationMode($mode)
  73. {
  74. return new self("'$mode' is an invalid hydration mode.");
  75. }
  76. public static function mismatchedEventManager()
  77. {
  78. return new self("Cannot use different EventManager instances for EntityManager and Connection.");
  79. }
  80. public static function findByRequiresParameter($methodName)
  81. {
  82. return new self("You need to pass a parameter to '".$methodName."'");
  83. }
  84. public static function invalidFindByCall($entityName, $fieldName, $method)
  85. {
  86. return new self(
  87. "Entity '".$entityName."' has no field '".$fieldName."'. ".
  88. "You can therefore not call '".$method."' on the entities' repository"
  89. );
  90. }
  91. public static function invalidFindByInverseAssociation($entityName, $associationFieldName)
  92. {
  93. return new self(
  94. "You cannot search for the association field '".$entityName."#".$associationFieldName."', ".
  95. "because it is the inverse side of an association. Find methods only work on owning side associations."
  96. );
  97. }
  98. public static function invalidResultCacheDriver() {
  99. return new self("Invalid result cache driver; it must implement \Doctrine\Common\Cache\Cache.");
  100. }
  101. public static function notSupported() {
  102. return new self("This behaviour is (currently) not supported by Doctrine 2");
  103. }
  104. public static function queryCacheNotConfigured()
  105. {
  106. return new self('Query Cache is not configured.');
  107. }
  108. public static function metadataCacheNotConfigured()
  109. {
  110. return new self('Class Metadata Cache is not configured.');
  111. }
  112. public static function proxyClassesAlwaysRegenerating()
  113. {
  114. return new self('Proxy Classes are always regenerating.');
  115. }
  116. public static function unknownEntityNamespace($entityNamespaceAlias)
  117. {
  118. return new self(
  119. "Unknown Entity namespace alias '$entityNamespaceAlias'."
  120. );
  121. }
  122. }