MappingException.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937
  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\Mapping;
  20. use Doctrine\ORM\ORMException;
  21. use ReflectionException;
  22. use function array_keys;
  23. use function array_map;
  24. use function array_values;
  25. use function get_parent_class;
  26. use function implode;
  27. use function sprintf;
  28. /**
  29. * A MappingException indicates that something is wrong with the mapping setup.
  30. */
  31. class MappingException extends ORMException
  32. {
  33. /**
  34. * @return MappingException
  35. */
  36. public static function pathRequired()
  37. {
  38. return new self('Specifying the paths to your entities is required ' .
  39. 'in the AnnotationDriver to retrieve all class names.');
  40. }
  41. /**
  42. * @param string $entityName
  43. *
  44. * @return MappingException
  45. */
  46. public static function identifierRequired($entityName)
  47. {
  48. $parent = get_parent_class($entityName);
  49. if ($parent !== false) {
  50. return new self(sprintf(
  51. 'No identifier/primary key specified for Entity "%s" sub class of "%s". Every Entity must have an identifier/primary key.',
  52. $entityName,
  53. $parent
  54. ));
  55. }
  56. return new self(sprintf(
  57. 'No identifier/primary key specified for Entity "%s". Every Entity must have an identifier/primary key.',
  58. $entityName
  59. ));
  60. }
  61. /**
  62. * @param string $entityName
  63. * @param string $type
  64. *
  65. * @return MappingException
  66. */
  67. public static function invalidInheritanceType($entityName, $type)
  68. {
  69. return new self(sprintf("The inheritance type '%s' specified for '%s' does not exist.", $type, $entityName));
  70. }
  71. /**
  72. * @return MappingException
  73. */
  74. public static function generatorNotAllowedWithCompositeId()
  75. {
  76. return new self("Id generators can't be used with a composite id.");
  77. }
  78. /**
  79. * @param string $entity
  80. *
  81. * @return MappingException
  82. */
  83. public static function missingFieldName($entity)
  84. {
  85. return new self(sprintf(
  86. "The field or association mapping misses the 'fieldName' attribute in entity '%s'.",
  87. $entity
  88. ));
  89. }
  90. /**
  91. * @param string $fieldName
  92. *
  93. * @return MappingException
  94. */
  95. public static function missingTargetEntity($fieldName)
  96. {
  97. return new self(sprintf("The association mapping '%s' misses the 'targetEntity' attribute.", $fieldName));
  98. }
  99. /**
  100. * @param string $fieldName
  101. *
  102. * @return MappingException
  103. */
  104. public static function missingSourceEntity($fieldName)
  105. {
  106. return new self(sprintf("The association mapping '%s' misses the 'sourceEntity' attribute.", $fieldName));
  107. }
  108. /**
  109. * @param string $fieldName
  110. *
  111. * @return MappingException
  112. */
  113. public static function missingEmbeddedClass($fieldName)
  114. {
  115. return new self(sprintf("The embed mapping '%s' misses the 'class' attribute.", $fieldName));
  116. }
  117. /**
  118. * @param string $entityName
  119. * @param string $fileName
  120. *
  121. * @return MappingException
  122. */
  123. public static function mappingFileNotFound($entityName, $fileName)
  124. {
  125. return new self(sprintf("No mapping file found named '%s' for class '%s'.", $fileName, $entityName));
  126. }
  127. /**
  128. * Exception for invalid property name override.
  129. *
  130. * @param string $className The entity's name.
  131. * @param string $fieldName
  132. *
  133. * @return MappingException
  134. */
  135. public static function invalidOverrideFieldName($className, $fieldName)
  136. {
  137. return new self(sprintf("Invalid field override named '%s' for class '%s'.", $fieldName, $className));
  138. }
  139. /**
  140. * Exception for invalid property type override.
  141. *
  142. * @param string $className The entity's name.
  143. * @param string $fieldName
  144. *
  145. * @return MappingException
  146. */
  147. public static function invalidOverrideFieldType($className, $fieldName)
  148. {
  149. return new self(sprintf(
  150. "The column type of attribute '%s' on class '%s' could not be changed.",
  151. $fieldName,
  152. $className
  153. ));
  154. }
  155. /**
  156. * @param string $className
  157. * @param string $fieldName
  158. *
  159. * @return MappingException
  160. */
  161. public static function mappingNotFound($className, $fieldName)
  162. {
  163. return new self(sprintf("No mapping found for field '%s' on class '%s'.", $fieldName, $className));
  164. }
  165. /**
  166. * @param string $className
  167. * @param string $queryName
  168. *
  169. * @return MappingException
  170. */
  171. public static function queryNotFound($className, $queryName)
  172. {
  173. return new self(sprintf("No query found named '%s' on class '%s'.", $queryName, $className));
  174. }
  175. /**
  176. * @param string $className
  177. * @param string $resultName
  178. *
  179. * @return MappingException
  180. */
  181. public static function resultMappingNotFound($className, $resultName)
  182. {
  183. return new self(sprintf("No result set mapping found named '%s' on class '%s'.", $resultName, $className));
  184. }
  185. /**
  186. * @param string $entity
  187. * @param string $queryName
  188. *
  189. * @return MappingException
  190. */
  191. public static function emptyQueryMapping($entity, $queryName)
  192. {
  193. return new self(sprintf('Query named "%s" in "%s" could not be empty.', $queryName, $entity));
  194. }
  195. /**
  196. * @param string $className
  197. *
  198. * @return MappingException
  199. */
  200. public static function nameIsMandatoryForQueryMapping($className)
  201. {
  202. return new self(sprintf("Query name on entity class '%s' is not defined.", $className));
  203. }
  204. /**
  205. * @param string $entity
  206. * @param string $queryName
  207. *
  208. * @return MappingException
  209. */
  210. public static function missingQueryMapping($entity, $queryName)
  211. {
  212. return new self(sprintf(
  213. 'Query named "%s" in "%s requires a result class or result set mapping.',
  214. $queryName,
  215. $entity
  216. ));
  217. }
  218. /**
  219. * @param string $entity
  220. * @param string $resultName
  221. *
  222. * @return MappingException
  223. */
  224. public static function missingResultSetMappingEntity($entity, $resultName)
  225. {
  226. return new self(sprintf(
  227. 'Result set mapping named "%s" in "%s requires a entity class name.',
  228. $resultName,
  229. $entity
  230. ));
  231. }
  232. /**
  233. * @param string $entity
  234. * @param string $resultName
  235. *
  236. * @return MappingException
  237. */
  238. public static function missingResultSetMappingFieldName($entity, $resultName)
  239. {
  240. return new self(sprintf(
  241. 'Result set mapping named "%s" in "%s requires a field name.',
  242. $resultName,
  243. $entity
  244. ));
  245. }
  246. /**
  247. * @param string $className
  248. *
  249. * @return MappingException
  250. */
  251. public static function nameIsMandatoryForSqlResultSetMapping($className)
  252. {
  253. return new self(sprintf("Result set mapping name on entity class '%s' is not defined.", $className));
  254. }
  255. /**
  256. * @param string $fieldName
  257. *
  258. * @return MappingException
  259. */
  260. public static function oneToManyRequiresMappedBy($fieldName)
  261. {
  262. return new self(sprintf("OneToMany mapping on field '%s' requires the 'mappedBy' attribute.", $fieldName));
  263. }
  264. /**
  265. * @param string $fieldName
  266. *
  267. * @return MappingException
  268. */
  269. public static function joinTableRequired($fieldName)
  270. {
  271. return new self(sprintf("The mapping of field '%s' requires an the 'joinTable' attribute.", $fieldName));
  272. }
  273. /**
  274. * Called if a required option was not found but is required
  275. *
  276. * @param string $field Which field cannot be processed?
  277. * @param string $expectedOption Which option is required
  278. * @param string $hint Can optionally be used to supply a tip for common mistakes,
  279. * e.g. "Did you think of the plural s?"
  280. *
  281. * @return MappingException
  282. */
  283. public static function missingRequiredOption($field, $expectedOption, $hint = '')
  284. {
  285. $message = "The mapping of field '" . $field . "' is invalid: The option '" . $expectedOption . "' is required.";
  286. if (! empty($hint)) {
  287. $message .= ' (Hint: ' . $hint . ')';
  288. }
  289. return new self($message);
  290. }
  291. /**
  292. * Generic exception for invalid mappings.
  293. *
  294. * @param string $fieldName
  295. *
  296. * @return MappingException
  297. */
  298. public static function invalidMapping($fieldName)
  299. {
  300. return new self(sprintf("The mapping of field '%s' is invalid.", $fieldName));
  301. }
  302. /**
  303. * Exception for reflection exceptions - adds the entity name,
  304. * because there might be long classnames that will be shortened
  305. * within the stacktrace
  306. *
  307. * @param string $entity The entity's name
  308. *
  309. * @return MappingException
  310. */
  311. public static function reflectionFailure($entity, ReflectionException $previousException)
  312. {
  313. return new self(sprintf('An error occurred in %s', $entity), 0, $previousException);
  314. }
  315. /**
  316. * @param string $className
  317. * @param string $joinColumn
  318. *
  319. * @return MappingException
  320. */
  321. public static function joinColumnMustPointToMappedField($className, $joinColumn)
  322. {
  323. return new self(sprintf(
  324. 'The column %s must be mapped to a field in class %s since it is referenced by a join column of another class.',
  325. $joinColumn,
  326. $className
  327. ));
  328. }
  329. /**
  330. * @param string $className
  331. *
  332. * @return MappingException
  333. */
  334. public static function classIsNotAValidEntityOrMappedSuperClass($className)
  335. {
  336. $parent = get_parent_class($className);
  337. if ($parent !== false) {
  338. return new self(sprintf(
  339. 'Class "%s" sub class of "%s" is not a valid entity or mapped super class.',
  340. $className,
  341. $parent
  342. ));
  343. }
  344. return new self(sprintf(
  345. 'Class "%s" is not a valid entity or mapped super class.',
  346. $className
  347. ));
  348. }
  349. /**
  350. * @param string $className
  351. * @param string $propertyName
  352. *
  353. * @return MappingException
  354. */
  355. public static function propertyTypeIsRequired($className, $propertyName)
  356. {
  357. return new self(sprintf(
  358. "The attribute 'type' is required for the column description of property %s::\$%s.",
  359. $className,
  360. $propertyName
  361. ));
  362. }
  363. /**
  364. * @param string $className
  365. *
  366. * @return MappingException
  367. */
  368. public static function tableIdGeneratorNotImplemented($className)
  369. {
  370. return new self(sprintf('TableIdGenerator is not yet implemented for use with class %s', $className));
  371. }
  372. /**
  373. * @param string $entity The entity's name.
  374. * @param string $fieldName The name of the field that was already declared.
  375. *
  376. * @return MappingException
  377. */
  378. public static function duplicateFieldMapping($entity, $fieldName)
  379. {
  380. return new self(sprintf(
  381. 'Property "%s" in "%s" was already declared, but it must be declared only once',
  382. $fieldName,
  383. $entity
  384. ));
  385. }
  386. /**
  387. * @param string $entity
  388. * @param string $fieldName
  389. *
  390. * @return MappingException
  391. */
  392. public static function duplicateAssociationMapping($entity, $fieldName)
  393. {
  394. return new self(sprintf(
  395. 'Property "%s" in "%s" was already declared, but it must be declared only once',
  396. $fieldName,
  397. $entity
  398. ));
  399. }
  400. /**
  401. * @param string $entity
  402. * @param string $queryName
  403. *
  404. * @return MappingException
  405. */
  406. public static function duplicateQueryMapping($entity, $queryName)
  407. {
  408. return new self(sprintf(
  409. 'Query named "%s" in "%s" was already declared, but it must be declared only once',
  410. $queryName,
  411. $entity
  412. ));
  413. }
  414. /**
  415. * @param string $entity
  416. * @param string $resultName
  417. *
  418. * @return MappingException
  419. */
  420. public static function duplicateResultSetMapping($entity, $resultName)
  421. {
  422. return new self(sprintf(
  423. 'Result set mapping named "%s" in "%s" was already declared, but it must be declared only once',
  424. $resultName,
  425. $entity
  426. ));
  427. }
  428. /**
  429. * @param string $entity
  430. *
  431. * @return MappingException
  432. */
  433. public static function singleIdNotAllowedOnCompositePrimaryKey($entity)
  434. {
  435. return new self('Single id is not allowed on composite primary key in entity ' . $entity);
  436. }
  437. /**
  438. * @param string $entity
  439. *
  440. * @return MappingException
  441. */
  442. public static function noIdDefined($entity)
  443. {
  444. return new self('No ID defined for entity ' . $entity);
  445. }
  446. /**
  447. * @param string $entity
  448. * @param string $fieldName
  449. * @param string $unsupportedType
  450. *
  451. * @return MappingException
  452. */
  453. public static function unsupportedOptimisticLockingType($entity, $fieldName, $unsupportedType)
  454. {
  455. return new self(sprintf(
  456. 'Locking type "%s" (specified in "%s", field "%s") is not supported by Doctrine.',
  457. $unsupportedType,
  458. $entity,
  459. $fieldName
  460. ));
  461. }
  462. /**
  463. * @param string|null $path
  464. *
  465. * @return MappingException
  466. */
  467. public static function fileMappingDriversRequireConfiguredDirectoryPath($path = null)
  468. {
  469. if (! empty($path)) {
  470. $path = '[' . $path . ']';
  471. }
  472. return new self(
  473. 'File mapping drivers must have a valid directory path, ' .
  474. 'however the given path ' . $path . ' seems to be incorrect!'
  475. );
  476. }
  477. /**
  478. * Returns an exception that indicates that a class used in a discriminator map does not exist.
  479. * An example would be an outdated (maybe renamed) classname.
  480. *
  481. * @param string $className The class that could not be found
  482. * @param string $owningClass The class that declares the discriminator map.
  483. *
  484. * @return MappingException
  485. */
  486. public static function invalidClassInDiscriminatorMap($className, $owningClass)
  487. {
  488. return new self(sprintf(
  489. "Entity class '%s' used in the discriminator map of class '%s' " .
  490. 'does not exist.',
  491. $className,
  492. $owningClass
  493. ));
  494. }
  495. /**
  496. * @param string $className
  497. * @param string[] $entries
  498. * @param array<string,string> $map
  499. *
  500. * @return MappingException
  501. */
  502. public static function duplicateDiscriminatorEntry($className, array $entries, array $map)
  503. {
  504. return new self(
  505. 'The entries ' . implode(', ', $entries) . " in discriminator map of class '" . $className . "' is duplicated. " .
  506. 'If the discriminator map is automatically generated you have to convert it to an explicit discriminator map now. ' .
  507. 'The entries of the current map are: @DiscriminatorMap({' . implode(', ', array_map(
  508. static function ($a, $b) {
  509. return sprintf("'%s': '%s'", $a, $b);
  510. },
  511. array_keys($map),
  512. array_values($map)
  513. )) . '})'
  514. );
  515. }
  516. /**
  517. * @param string $className
  518. *
  519. * @return MappingException
  520. */
  521. public static function missingDiscriminatorMap($className)
  522. {
  523. return new self(sprintf(
  524. "Entity class '%s' is using inheritance but no discriminator map was defined.",
  525. $className
  526. ));
  527. }
  528. /**
  529. * @param string $className
  530. *
  531. * @return MappingException
  532. */
  533. public static function missingDiscriminatorColumn($className)
  534. {
  535. return new self(sprintf(
  536. "Entity class '%s' is using inheritance but no discriminator column was defined.",
  537. $className
  538. ));
  539. }
  540. /**
  541. * @param string $className
  542. * @param string $type
  543. *
  544. * @return MappingException
  545. */
  546. public static function invalidDiscriminatorColumnType($className, $type)
  547. {
  548. return new self(sprintf(
  549. "Discriminator column type on entity class '%s' is not allowed to be '%s'. 'string' or 'integer' type variables are suggested!",
  550. $className,
  551. $type
  552. ));
  553. }
  554. /**
  555. * @param string $className
  556. *
  557. * @return MappingException
  558. */
  559. public static function nameIsMandatoryForDiscriminatorColumns($className)
  560. {
  561. return new self(sprintf("Discriminator column name on entity class '%s' is not defined.", $className));
  562. }
  563. /**
  564. * @param string $className
  565. * @param string $fieldName
  566. *
  567. * @return MappingException
  568. */
  569. public static function cannotVersionIdField($className, $fieldName)
  570. {
  571. return new self(sprintf(
  572. "Setting Id field '%s' as versionable in entity class '%s' is not supported.",
  573. $fieldName,
  574. $className
  575. ));
  576. }
  577. /**
  578. * @param string $className
  579. * @param string $fieldName
  580. * @param string $type
  581. *
  582. * @return MappingException
  583. */
  584. public static function sqlConversionNotAllowedForIdentifiers($className, $fieldName, $type)
  585. {
  586. return new self(sprintf(
  587. "It is not possible to set id field '%s' to type '%s' in entity class '%s'. The type '%s' requires conversion SQL which is not allowed for identifiers.",
  588. $fieldName,
  589. $type,
  590. $className,
  591. $type
  592. ));
  593. }
  594. /**
  595. * @param string $className
  596. * @param string $columnName
  597. *
  598. * @return MappingException
  599. */
  600. public static function duplicateColumnName($className, $columnName)
  601. {
  602. return new self("Duplicate definition of column '" . $columnName . "' on entity '" . $className . "' in a field or discriminator column mapping.");
  603. }
  604. /**
  605. * @param string $className
  606. * @param string $field
  607. *
  608. * @return MappingException
  609. */
  610. public static function illegalToManyAssociationOnMappedSuperclass($className, $field)
  611. {
  612. return new self("It is illegal to put an inverse side one-to-many or many-to-many association on mapped superclass '" . $className . '#' . $field . "'.");
  613. }
  614. /**
  615. * @param string $className
  616. * @param string $targetEntity
  617. * @param string $targetField
  618. *
  619. * @return MappingException
  620. */
  621. public static function cannotMapCompositePrimaryKeyEntitiesAsForeignId($className, $targetEntity, $targetField)
  622. {
  623. return new self("It is not possible to map entity '" . $className . "' with a composite primary key " .
  624. "as part of the primary key of another entity '" . $targetEntity . '#' . $targetField . "'.");
  625. }
  626. /**
  627. * @param string $className
  628. * @param string $field
  629. *
  630. * @return MappingException
  631. */
  632. public static function noSingleAssociationJoinColumnFound($className, $field)
  633. {
  634. return new self(sprintf("'%s#%s' is not an association with a single join column.", $className, $field));
  635. }
  636. /**
  637. * @param string $className
  638. * @param string $column
  639. *
  640. * @return MappingException
  641. */
  642. public static function noFieldNameFoundForColumn($className, $column)
  643. {
  644. return new self(sprintf(
  645. "Cannot find a field on '%s' that is mapped to column '%s'. Either the " .
  646. 'field does not exist or an association exists but it has multiple join columns.',
  647. $className,
  648. $column
  649. ));
  650. }
  651. /**
  652. * @param string $className
  653. * @param string $field
  654. *
  655. * @return MappingException
  656. */
  657. public static function illegalOrphanRemovalOnIdentifierAssociation($className, $field)
  658. {
  659. return new self(sprintf(
  660. "The orphan removal option is not allowed on an association that is part of the identifier in '%s#%s'.",
  661. $className,
  662. $field
  663. ));
  664. }
  665. /**
  666. * @param string $className
  667. * @param string $field
  668. *
  669. * @return MappingException
  670. */
  671. public static function illegalOrphanRemoval($className, $field)
  672. {
  673. return new self('Orphan removal is only allowed on one-to-one and one-to-many ' .
  674. 'associations, but ' . $className . '#' . $field . ' is not.');
  675. }
  676. /**
  677. * @param string $className
  678. * @param string $field
  679. *
  680. * @return MappingException
  681. */
  682. public static function illegalInverseIdentifierAssociation($className, $field)
  683. {
  684. return new self(sprintf(
  685. "An inverse association is not allowed to be identifier in '%s#%s'.",
  686. $className,
  687. $field
  688. ));
  689. }
  690. /**
  691. * @param string $className
  692. * @param string $field
  693. *
  694. * @return MappingException
  695. */
  696. public static function illegalToManyIdentifierAssociation($className, $field)
  697. {
  698. return new self(sprintf(
  699. "Many-to-many or one-to-many associations are not allowed to be identifier in '%s#%s'.",
  700. $className,
  701. $field
  702. ));
  703. }
  704. /**
  705. * @param string $className
  706. *
  707. * @return MappingException
  708. */
  709. public static function noInheritanceOnMappedSuperClass($className)
  710. {
  711. return new self("It is not supported to define inheritance information on a mapped superclass '" . $className . "'.");
  712. }
  713. /**
  714. * @param string $className
  715. * @param string $rootClassName
  716. *
  717. * @return MappingException
  718. */
  719. public static function mappedClassNotPartOfDiscriminatorMap($className, $rootClassName)
  720. {
  721. return new self(
  722. "Entity '" . $className . "' has to be part of the discriminator map of '" . $rootClassName . "' " .
  723. "to be properly mapped in the inheritance hierarchy. Alternatively you can make '" . $className . "' an abstract class " .
  724. 'to avoid this exception from occurring.'
  725. );
  726. }
  727. /**
  728. * @param string $className
  729. * @param string $methodName
  730. *
  731. * @return MappingException
  732. */
  733. public static function lifecycleCallbackMethodNotFound($className, $methodName)
  734. {
  735. return new self("Entity '" . $className . "' has no method '" . $methodName . "' to be registered as lifecycle callback.");
  736. }
  737. /**
  738. * @param string $listenerName
  739. * @param string $className
  740. *
  741. * @return MappingException
  742. */
  743. public static function entityListenerClassNotFound($listenerName, $className)
  744. {
  745. return new self(sprintf('Entity Listener "%s" declared on "%s" not found.', $listenerName, $className));
  746. }
  747. /**
  748. * @param string $listenerName
  749. * @param string $methodName
  750. * @param string $className
  751. *
  752. * @return MappingException
  753. */
  754. public static function entityListenerMethodNotFound($listenerName, $methodName, $className)
  755. {
  756. return new self(sprintf('Entity Listener "%s" declared on "%s" has no method "%s".', $listenerName, $className, $methodName));
  757. }
  758. /**
  759. * @param string $listenerName
  760. * @param string $methodName
  761. * @param string $className
  762. *
  763. * @return MappingException
  764. */
  765. public static function duplicateEntityListener($listenerName, $methodName, $className)
  766. {
  767. return new self(sprintf('Entity Listener "%s#%s()" in "%s" was already declared, but it must be declared only once.', $listenerName, $methodName, $className));
  768. }
  769. /**
  770. * @param string $className
  771. * @param string $annotation
  772. *
  773. * @return MappingException
  774. */
  775. public static function invalidFetchMode($className, $annotation)
  776. {
  777. return new self("Entity '" . $className . "' has a mapping with invalid fetch mode '" . $annotation . "'");
  778. }
  779. /**
  780. * @param string $className
  781. *
  782. * @return MappingException
  783. */
  784. public static function compositeKeyAssignedIdGeneratorRequired($className)
  785. {
  786. return new self("Entity '" . $className . "' has a composite identifier but uses an ID generator other than manually assigning (Identity, Sequence). This is not supported.");
  787. }
  788. /**
  789. * @param string $targetEntity
  790. * @param string $sourceEntity
  791. * @param string $associationName
  792. *
  793. * @return MappingException
  794. */
  795. public static function invalidTargetEntityClass($targetEntity, $sourceEntity, $associationName)
  796. {
  797. return new self('The target-entity ' . $targetEntity . " cannot be found in '" . $sourceEntity . '#' . $associationName . "'.");
  798. }
  799. /**
  800. * @param string[] $cascades
  801. * @param string $className
  802. * @param string $propertyName
  803. *
  804. * @return MappingException
  805. */
  806. public static function invalidCascadeOption(array $cascades, $className, $propertyName)
  807. {
  808. $cascades = implode(', ', array_map(static function ($e) {
  809. return "'" . $e . "'";
  810. }, $cascades));
  811. return new self(sprintf(
  812. "You have specified invalid cascade options for %s::$%s: %s; available options: 'remove', 'persist', 'refresh', 'merge', and 'detach'",
  813. $className,
  814. $propertyName,
  815. $cascades
  816. ));
  817. }
  818. /**
  819. * @param string $className
  820. *
  821. * @return MappingException
  822. */
  823. public static function missingSequenceName($className)
  824. {
  825. return new self(
  826. sprintf('Missing "sequenceName" attribute for sequence id generator definition on class "%s".', $className)
  827. );
  828. }
  829. /**
  830. * @param string $className
  831. * @param string $propertyName
  832. *
  833. * @return MappingException
  834. */
  835. public static function infiniteEmbeddableNesting($className, $propertyName)
  836. {
  837. return new self(
  838. sprintf(
  839. 'Infinite nesting detected for embedded property %s::%s. ' .
  840. 'You cannot embed an embeddable from the same type inside an embeddable.',
  841. $className,
  842. $propertyName
  843. )
  844. );
  845. }
  846. /**
  847. * @return MappingException
  848. */
  849. public static function illegalOverrideOfInheritedProperty($className, $propertyName)
  850. {
  851. return new self(
  852. sprintf(
  853. 'Override for %s::%s is only allowed for attributes/associations ' .
  854. 'declared on a mapped superclass or a trait.',
  855. $className,
  856. $propertyName
  857. )
  858. );
  859. }
  860. }