ORMException.php 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. public static function invalidFlushMode($mode)
  57. {
  58. return new self("'$mode' is an invalid flush mode.");
  59. }
  60. public static function entityManagerClosed()
  61. {
  62. return new self("The EntityManager is closed.");
  63. }
  64. public static function invalidHydrationMode($mode)
  65. {
  66. return new self("'$mode' is an invalid hydration mode.");
  67. }
  68. public static function mismatchedEventManager()
  69. {
  70. return new self("Cannot use different EventManager instances for EntityManager and Connection.");
  71. }
  72. public static function findByRequiresParameter($methodName)
  73. {
  74. return new self("You need to pass a parameter to '".$methodName."'");
  75. }
  76. public static function invalidFindByCall($entityName, $fieldName, $method)
  77. {
  78. return new self(
  79. "Entity '".$entityName."' has no field '".$fieldName."'. ".
  80. "You can therefore not call '".$method."' on the entities' repository"
  81. );
  82. }
  83. public static function invalidFindByInverseAssociation($entityName, $associationFieldName)
  84. {
  85. return new self(
  86. "You cannot search for the association field '".$entityName."#".$associationFieldName."', ".
  87. "because it is the inverse side of an association. Find methods only work on owning side associations."
  88. );
  89. }
  90. public static function invalidResultCacheDriver() {
  91. return new self("Invalid result cache driver; it must implement \Doctrine\Common\Cache\Cache.");
  92. }
  93. public static function notSupported() {
  94. return new self("This behaviour is (currently) not supported by Doctrine 2");
  95. }
  96. public static function queryCacheNotConfigured()
  97. {
  98. return new self('Query Cache is not configured.');
  99. }
  100. public static function metadataCacheNotConfigured()
  101. {
  102. return new self('Class Metadata Cache is not configured.');
  103. }
  104. public static function proxyClassesAlwaysRegenerating()
  105. {
  106. return new self('Proxy Classes are always regenerating.');
  107. }
  108. public static function unknownEntityNamespace($entityNamespaceAlias)
  109. {
  110. return new self(
  111. "Unknown Entity namespace alias '$entityNamespaceAlias'."
  112. );
  113. }
  114. }