vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php line 47

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\ORM\Query;
  4. use Doctrine\ORM\Exception\ORMException;
  5. use Doctrine\ORM\Query\AST\PathExpression;
  6. use Exception;
  7. /**
  8. * Description of QueryException.
  9. *
  10. * @link www.doctrine-project.org
  11. */
  12. class QueryException extends ORMException
  13. {
  14. /**
  15. * @param string $dql
  16. *
  17. * @return QueryException
  18. */
  19. public static function dqlError($dql)
  20. {
  21. return new self($dql);
  22. }
  23. /**
  24. * @param string $message
  25. * @param Exception|null $previous
  26. *
  27. * @return QueryException
  28. */
  29. public static function syntaxError($message, $previous = null)
  30. {
  31. return new self('[Syntax Error] ' . $message, 0, $previous);
  32. }
  33. /**
  34. * @param string $message
  35. * @param Exception|null $previous
  36. *
  37. * @return QueryException
  38. */
  39. public static function semanticalError($message, $previous = null)
  40. {
  41. return new self('[Semantical Error] ' . $message, 0, $previous);
  42. }
  43. /**
  44. * @return QueryException
  45. */
  46. public static function invalidLockMode()
  47. {
  48. return new self('Invalid lock mode hint provided.');
  49. }
  50. /**
  51. * @param string $expected
  52. * @param string $received
  53. *
  54. * @return QueryException
  55. */
  56. public static function invalidParameterType($expected, $received)
  57. {
  58. return new self('Invalid parameter type, ' . $received . ' given, but ' . $expected . ' expected.');
  59. }
  60. /**
  61. * @param string $pos
  62. *
  63. * @return QueryException
  64. */
  65. public static function invalidParameterPosition($pos)
  66. {
  67. return new self('Invalid parameter position: ' . $pos);
  68. }
  69. /**
  70. * @param int $expected
  71. * @param int $received
  72. *
  73. * @return QueryException
  74. */
  75. public static function tooManyParameters($expected, $received)
  76. {
  77. return new self('Too many parameters: the query defines ' . $expected . ' parameters and you bound ' . $received);
  78. }
  79. /**
  80. * @param int $expected
  81. * @param int $received
  82. *
  83. * @return QueryException
  84. */
  85. public static function tooFewParameters($expected, $received)
  86. {
  87. return new self('Too few parameters: the query defines ' . $expected . ' parameters but you only bound ' . $received);
  88. }
  89. /**
  90. * @param string $value
  91. *
  92. * @return QueryException
  93. */
  94. public static function invalidParameterFormat($value)
  95. {
  96. return new self('Invalid parameter format, ' . $value . ' given, but :<name> or ?<num> expected.');
  97. }
  98. /**
  99. * @param string $key
  100. *
  101. * @return QueryException
  102. */
  103. public static function unknownParameter($key)
  104. {
  105. return new self('Invalid parameter: token ' . $key . ' is not defined in the query.');
  106. }
  107. /**
  108. * @return QueryException
  109. */
  110. public static function parameterTypeMismatch()
  111. {
  112. return new self('DQL Query parameter and type numbers mismatch, but have to be exactly equal.');
  113. }
  114. /**
  115. * @param object $pathExpr
  116. *
  117. * @return QueryException
  118. */
  119. public static function invalidPathExpression($pathExpr)
  120. {
  121. return new self(
  122. "Invalid PathExpression '" . $pathExpr->identificationVariable . '.' . $pathExpr->field . "'."
  123. );
  124. }
  125. /**
  126. * @param string $literal
  127. *
  128. * @return QueryException
  129. */
  130. public static function invalidLiteral($literal)
  131. {
  132. return new self("Invalid literal '" . $literal . "'");
  133. }
  134. /**
  135. * @param string[] $assoc
  136. * @psalm-param array<string, string> $assoc
  137. *
  138. * @return QueryException
  139. */
  140. public static function iterateWithFetchJoinCollectionNotAllowed($assoc)
  141. {
  142. return new self(
  143. 'Invalid query operation: Not allowed to iterate over fetch join collections ' .
  144. 'in class ' . $assoc['sourceEntity'] . ' association ' . $assoc['fieldName']
  145. );
  146. }
  147. /**
  148. * @return QueryException
  149. */
  150. public static function partialObjectsAreDangerous()
  151. {
  152. return new self(
  153. 'Loading partial objects is dangerous. Fetch full objects or consider ' .
  154. 'using a different fetch mode. If you really want partial objects, ' .
  155. 'set the doctrine.forcePartialLoad query hint to TRUE.'
  156. );
  157. }
  158. /**
  159. * @param string[] $assoc
  160. * @psalm-param array<string, string> $assoc
  161. *
  162. * @return QueryException
  163. */
  164. public static function overwritingJoinConditionsNotYetSupported($assoc)
  165. {
  166. return new self(
  167. 'Unsupported query operation: It is not yet possible to overwrite the join ' .
  168. 'conditions in class ' . $assoc['sourceEntityName'] . ' association ' . $assoc['fieldName'] . '. ' .
  169. 'Use WITH to append additional join conditions to the association.'
  170. );
  171. }
  172. /**
  173. * @return QueryException
  174. */
  175. public static function associationPathInverseSideNotSupported(PathExpression $pathExpr)
  176. {
  177. return new self(
  178. 'A single-valued association path expression to an inverse side is not supported in DQL queries. ' .
  179. 'Instead of "' . $pathExpr->identificationVariable . '.' . $pathExpr->field . '" use an explicit join.'
  180. );
  181. }
  182. /**
  183. * @param string[] $assoc
  184. * @psalm-param array<string, string> $assoc
  185. *
  186. * @return QueryException
  187. */
  188. public static function iterateWithFetchJoinNotAllowed($assoc)
  189. {
  190. return new self(
  191. 'Iterate with fetch join in class ' . $assoc['sourceEntity'] .
  192. ' using association ' . $assoc['fieldName'] . ' not allowed.'
  193. );
  194. }
  195. public static function iterateWithMixedResultNotAllowed(): QueryException
  196. {
  197. return new self('Iterating a query with mixed results (using scalars) is not supported.');
  198. }
  199. /**
  200. * @return QueryException
  201. */
  202. public static function associationPathCompositeKeyNotSupported()
  203. {
  204. return new self(
  205. 'A single-valued association path expression to an entity with a composite primary ' .
  206. 'key is not supported. Explicitly name the components of the composite primary key ' .
  207. 'in the query.'
  208. );
  209. }
  210. /**
  211. * @param string $className
  212. * @param string $rootClass
  213. *
  214. * @return QueryException
  215. */
  216. public static function instanceOfUnrelatedClass($className, $rootClass)
  217. {
  218. return new self("Cannot check if a child of '" . $rootClass . "' is instanceof '" . $className . "', " .
  219. 'inheritance hierarchy does not exists between these two classes.');
  220. }
  221. /**
  222. * @param string $dqlAlias
  223. *
  224. * @return QueryException
  225. */
  226. public static function invalidQueryComponent($dqlAlias)
  227. {
  228. return new self(
  229. "Invalid query component given for DQL alias '" . $dqlAlias . "', " .
  230. "requires 'metadata', 'parent', 'relation', 'map', 'nestingLevel' and 'token' keys."
  231. );
  232. }
  233. }