ORMException.php 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. 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 namedQueryNotFound($queryName)
  35. {
  36. return new self('Could not find a named query by the name "' . $queryName . '"');
  37. }
  38. public static function namedNativeQueryNotFound($nativeQueryName)
  39. {
  40. return new self('Could not find a named native query by the name "' . $nativeQueryName . '"');
  41. }
  42. public static function entityMissingForeignAssignedId($entity, $relatedEntity)
  43. {
  44. return new self(
  45. "Entity of type " . get_class($entity) . " has identity through a foreign entity " . get_class($relatedEntity) . ", " .
  46. "however this entity has no identity itself. You have to call EntityManager#persist() on the related entity " .
  47. "and make sure that an identifier was generated before trying to persist '" . get_class($entity) . "'. In case " .
  48. "of Post Insert ID Generation (such as MySQL Auto-Increment or PostgreSQL SERIAL) this means you have to call " .
  49. "EntityManager#flush() between both persist operations."
  50. );
  51. }
  52. public static function entityMissingAssignedIdForField($entity, $field)
  53. {
  54. return new self("Entity of type " . get_class($entity) . " is missing an assigned ID for field '" . $field . "'. " .
  55. "The identifier generation strategy for this entity requires the ID field to be populated before ".
  56. "EntityManager#persist() is called. If you want automatically generated identifiers instead " .
  57. "you need to adjust the metadata mapping accordingly."
  58. );
  59. }
  60. public static function unrecognizedField($field)
  61. {
  62. return new self("Unrecognized field: $field");
  63. }
  64. /**
  65. * @param string $className
  66. * @param string $field
  67. */
  68. public static function invalidOrientation($className, $field)
  69. {
  70. return new self("Invalid order by orientation specified for " . $className . "#" . $field);
  71. }
  72. public static function invalidFlushMode($mode)
  73. {
  74. return new self("'$mode' is an invalid flush mode.");
  75. }
  76. public static function entityManagerClosed()
  77. {
  78. return new self("The EntityManager is closed.");
  79. }
  80. public static function invalidHydrationMode($mode)
  81. {
  82. return new self("'$mode' is an invalid hydration mode.");
  83. }
  84. public static function mismatchedEventManager()
  85. {
  86. return new self("Cannot use different EventManager instances for EntityManager and Connection.");
  87. }
  88. public static function findByRequiresParameter($methodName)
  89. {
  90. return new self("You need to pass a parameter to '".$methodName."'");
  91. }
  92. public static function invalidFindByCall($entityName, $fieldName, $method)
  93. {
  94. return new self(
  95. "Entity '".$entityName."' has no field '".$fieldName."'. ".
  96. "You can therefore not call '".$method."' on the entities' repository"
  97. );
  98. }
  99. public static function invalidFindByInverseAssociation($entityName, $associationFieldName)
  100. {
  101. return new self(
  102. "You cannot search for the association field '".$entityName."#".$associationFieldName."', ".
  103. "because it is the inverse side of an association. Find methods only work on owning side associations."
  104. );
  105. }
  106. public static function invalidResultCacheDriver() {
  107. return new self("Invalid result cache driver; it must implement Doctrine\\Common\\Cache\\Cache.");
  108. }
  109. public static function notSupported() {
  110. return new self("This behaviour is (currently) not supported by Doctrine 2");
  111. }
  112. public static function queryCacheNotConfigured()
  113. {
  114. return new self('Query Cache is not configured.');
  115. }
  116. public static function metadataCacheNotConfigured()
  117. {
  118. return new self('Class Metadata Cache is not configured.');
  119. }
  120. public static function proxyClassesAlwaysRegenerating()
  121. {
  122. return new self('Proxy Classes are always regenerating.');
  123. }
  124. public static function unknownEntityNamespace($entityNamespaceAlias)
  125. {
  126. return new self(
  127. "Unknown Entity namespace alias '$entityNamespaceAlias'."
  128. );
  129. }
  130. public static function invalidEntityRepository($className)
  131. {
  132. return new self("Invalid repository class '".$className."'. It must be a Doctrine\Common\Persistence\ObjectRepository.");
  133. }
  134. public static function missingIdentifierField($className, $fieldName)
  135. {
  136. return new self("The identifier $fieldName is missing for a query of " . $className);
  137. }
  138. public static function overwriteInternalDQLFunctionNotAllowed($functionName)
  139. {
  140. return new self("It is not allowed to overwrite internal function '$functionName' in the DQL parser through user-defined functions.");
  141. }
  142. }