vendor/doctrine/orm/src/Query/QueryException.php line 23

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