ClassMetadataInfo.php 65KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984
  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\Mapping;
  20. use Doctrine\Common\Persistence\Mapping\ClassMetadata;
  21. use ReflectionClass;
  22. /**
  23. * A <tt>ClassMetadata</tt> instance holds all the object-relational mapping metadata
  24. * of an entity and it's associations.
  25. *
  26. * Once populated, ClassMetadata instances are usually cached in a serialized form.
  27. *
  28. * <b>IMPORTANT NOTE:</b>
  29. *
  30. * The fields of this class are only public for 2 reasons:
  31. * 1) To allow fast READ access.
  32. * 2) To drastically reduce the size of a serialized instance (private/protected members
  33. * get the whole class name, namespace inclusive, prepended to every property in
  34. * the serialized representation).
  35. *
  36. * @author Roman Borschel <roman@code-factory.org>
  37. * @author Jonathan H. Wage <jonwage@gmail.com>
  38. * @since 2.0
  39. */
  40. class ClassMetadataInfo implements ClassMetadata
  41. {
  42. /* The inheritance mapping types */
  43. /**
  44. * NONE means the class does not participate in an inheritance hierarchy
  45. * and therefore does not need an inheritance mapping type.
  46. */
  47. const INHERITANCE_TYPE_NONE = 1;
  48. /**
  49. * JOINED means the class will be persisted according to the rules of
  50. * <tt>Class Table Inheritance</tt>.
  51. */
  52. const INHERITANCE_TYPE_JOINED = 2;
  53. /**
  54. * SINGLE_TABLE means the class will be persisted according to the rules of
  55. * <tt>Single Table Inheritance</tt>.
  56. */
  57. const INHERITANCE_TYPE_SINGLE_TABLE = 3;
  58. /**
  59. * TABLE_PER_CLASS means the class will be persisted according to the rules
  60. * of <tt>Concrete Table Inheritance</tt>.
  61. */
  62. const INHERITANCE_TYPE_TABLE_PER_CLASS = 4;
  63. /* The Id generator types. */
  64. /**
  65. * AUTO means the generator type will depend on what the used platform prefers.
  66. * Offers full portability.
  67. */
  68. const GENERATOR_TYPE_AUTO = 1;
  69. /**
  70. * SEQUENCE means a separate sequence object will be used. Platforms that do
  71. * not have native sequence support may emulate it. Full portability is currently
  72. * not guaranteed.
  73. */
  74. const GENERATOR_TYPE_SEQUENCE = 2;
  75. /**
  76. * TABLE means a separate table is used for id generation.
  77. * Offers full portability.
  78. */
  79. const GENERATOR_TYPE_TABLE = 3;
  80. /**
  81. * IDENTITY means an identity column is used for id generation. The database
  82. * will fill in the id column on insertion. Platforms that do not support
  83. * native identity columns may emulate them. Full portability is currently
  84. * not guaranteed.
  85. */
  86. const GENERATOR_TYPE_IDENTITY = 4;
  87. /**
  88. * NONE means the class does not have a generated id. That means the class
  89. * must have a natural, manually assigned id.
  90. */
  91. const GENERATOR_TYPE_NONE = 5;
  92. /**
  93. * DEFERRED_IMPLICIT means that changes of entities are calculated at commit-time
  94. * by doing a property-by-property comparison with the original data. This will
  95. * be done for all entities that are in MANAGED state at commit-time.
  96. *
  97. * This is the default change tracking policy.
  98. */
  99. const CHANGETRACKING_DEFERRED_IMPLICIT = 1;
  100. /**
  101. * DEFERRED_EXPLICIT means that changes of entities are calculated at commit-time
  102. * by doing a property-by-property comparison with the original data. This will
  103. * be done only for entities that were explicitly saved (through persist() or a cascade).
  104. */
  105. const CHANGETRACKING_DEFERRED_EXPLICIT = 2;
  106. /**
  107. * NOTIFY means that Doctrine relies on the entities sending out notifications
  108. * when their properties change. Such entity classes must implement
  109. * the <tt>NotifyPropertyChanged</tt> interface.
  110. */
  111. const CHANGETRACKING_NOTIFY = 3;
  112. /**
  113. * Specifies that an association is to be fetched when it is first accessed.
  114. */
  115. const FETCH_LAZY = 2;
  116. /**
  117. * Specifies that an association is to be fetched when the owner of the
  118. * association is fetched.
  119. */
  120. const FETCH_EAGER = 3;
  121. /**
  122. * Specifies that an association is to be fetched lazy (on first access) and that
  123. * commands such as Collection#count, Collection#slice are issued directly against
  124. * the database if the collection is not yet initialized.
  125. */
  126. const FETCH_EXTRA_LAZY = 4;
  127. /**
  128. * Identifies a one-to-one association.
  129. */
  130. const ONE_TO_ONE = 1;
  131. /**
  132. * Identifies a many-to-one association.
  133. */
  134. const MANY_TO_ONE = 2;
  135. /**
  136. * Combined bitmask for to-one (single-valued) associations.
  137. */
  138. const TO_ONE = 3;
  139. /**
  140. * Identifies a one-to-many association.
  141. */
  142. const ONE_TO_MANY = 4;
  143. /**
  144. * Identifies a many-to-many association.
  145. */
  146. const MANY_TO_MANY = 8;
  147. /**
  148. * Combined bitmask for to-many (collection-valued) associations.
  149. */
  150. const TO_MANY = 12;
  151. /**
  152. * READ-ONLY: The name of the entity class.
  153. */
  154. public $name;
  155. /**
  156. * READ-ONLY: The namespace the entity class is contained in.
  157. *
  158. * @var string
  159. * @todo Not really needed. Usage could be localized.
  160. */
  161. public $namespace;
  162. /**
  163. * READ-ONLY: The name of the entity class that is at the root of the mapped entity inheritance
  164. * hierarchy. If the entity is not part of a mapped inheritance hierarchy this is the same
  165. * as {@link $entityName}.
  166. *
  167. * @var string
  168. */
  169. public $rootEntityName;
  170. /**
  171. * The name of the custom repository class used for the entity class.
  172. * (Optional).
  173. *
  174. * @var string
  175. */
  176. public $customRepositoryClassName;
  177. /**
  178. * READ-ONLY: Whether this class describes the mapping of a mapped superclass.
  179. *
  180. * @var boolean
  181. */
  182. public $isMappedSuperclass = false;
  183. /**
  184. * READ-ONLY: The names of the parent classes (ancestors).
  185. *
  186. * @var array
  187. */
  188. public $parentClasses = array();
  189. /**
  190. * READ-ONLY: The names of all subclasses (descendants).
  191. *
  192. * @var array
  193. */
  194. public $subClasses = array();
  195. /**
  196. * READ-ONLY: The named queries allowed to be called directly from Repository.
  197. *
  198. * @var array
  199. */
  200. public $namedQueries = array();
  201. /**
  202. * READ-ONLY: The field names of all fields that are part of the identifier/primary key
  203. * of the mapped entity class.
  204. *
  205. * @var array
  206. */
  207. public $identifier = array();
  208. /**
  209. * READ-ONLY: The inheritance mapping type used by the class.
  210. *
  211. * @var integer
  212. */
  213. public $inheritanceType = self::INHERITANCE_TYPE_NONE;
  214. /**
  215. * READ-ONLY: The Id generator type used by the class.
  216. *
  217. * @var string
  218. */
  219. public $generatorType = self::GENERATOR_TYPE_NONE;
  220. /**
  221. * READ-ONLY: The field mappings of the class.
  222. * Keys are field names and values are mapping definitions.
  223. *
  224. * The mapping definition array has the following values:
  225. *
  226. * - <b>fieldName</b> (string)
  227. * The name of the field in the Entity.
  228. *
  229. * - <b>type</b> (string)
  230. * The type name of the mapped field. Can be one of Doctrine's mapping types
  231. * or a custom mapping type.
  232. *
  233. * - <b>columnName</b> (string, optional)
  234. * The column name. Optional. Defaults to the field name.
  235. *
  236. * - <b>length</b> (integer, optional)
  237. * The database length of the column. Optional. Default value taken from
  238. * the type.
  239. *
  240. * - <b>id</b> (boolean, optional)
  241. * Marks the field as the primary key of the entity. Multiple fields of an
  242. * entity can have the id attribute, forming a composite key.
  243. *
  244. * - <b>nullable</b> (boolean, optional)
  245. * Whether the column is nullable. Defaults to FALSE.
  246. *
  247. * - <b>columnDefinition</b> (string, optional, schema-only)
  248. * The SQL fragment that is used when generating the DDL for the column.
  249. *
  250. * - <b>precision</b> (integer, optional, schema-only)
  251. * The precision of a decimal column. Only valid if the column type is decimal.
  252. *
  253. * - <b>scale</b> (integer, optional, schema-only)
  254. * The scale of a decimal column. Only valid if the column type is decimal.
  255. *
  256. [* - <b>'unique'] (string, optional, schema-only)</b>
  257. * Whether a unique constraint should be generated for the column.
  258. *
  259. * @var array
  260. */
  261. public $fieldMappings = array();
  262. /**
  263. * READ-ONLY: An array of field names. Used to look up field names from column names.
  264. * Keys are column names and values are field names.
  265. * This is the reverse lookup map of $_columnNames.
  266. *
  267. * @var array
  268. */
  269. public $fieldNames = array();
  270. /**
  271. * READ-ONLY: A map of field names to column names. Keys are field names and values column names.
  272. * Used to look up column names from field names.
  273. * This is the reverse lookup map of $_fieldNames.
  274. *
  275. * @var array
  276. * @todo We could get rid of this array by just using $fieldMappings[$fieldName]['columnName'].
  277. */
  278. public $columnNames = array();
  279. /**
  280. * READ-ONLY: The discriminator value of this class.
  281. *
  282. * <b>This does only apply to the JOINED and SINGLE_TABLE inheritance mapping strategies
  283. * where a discriminator column is used.</b>
  284. *
  285. * @var mixed
  286. * @see discriminatorColumn
  287. */
  288. public $discriminatorValue;
  289. /**
  290. * READ-ONLY: The discriminator map of all mapped classes in the hierarchy.
  291. *
  292. * <b>This does only apply to the JOINED and SINGLE_TABLE inheritance mapping strategies
  293. * where a discriminator column is used.</b>
  294. *
  295. * @var mixed
  296. * @see discriminatorColumn
  297. */
  298. public $discriminatorMap = array();
  299. /**
  300. * READ-ONLY: The definition of the descriminator column used in JOINED and SINGLE_TABLE
  301. * inheritance mappings.
  302. *
  303. * @var array
  304. */
  305. public $discriminatorColumn;
  306. /**
  307. * READ-ONLY: The primary table definition. The definition is an array with the
  308. * following entries:
  309. *
  310. * name => <tableName>
  311. * schema => <schemaName>
  312. * indexes => array
  313. * uniqueConstraints => array
  314. *
  315. * @var array
  316. */
  317. public $table;
  318. /**
  319. * READ-ONLY: The registered lifecycle callbacks for entities of this class.
  320. *
  321. * @var array
  322. */
  323. public $lifecycleCallbacks = array();
  324. /**
  325. * READ-ONLY: The association mappings of this class.
  326. *
  327. * The mapping definition array supports the following keys:
  328. *
  329. * - <b>fieldName</b> (string)
  330. * The name of the field in the entity the association is mapped to.
  331. *
  332. * - <b>targetEntity</b> (string)
  333. * The class name of the target entity. If it is fully-qualified it is used as is.
  334. * If it is a simple, unqualified class name the namespace is assumed to be the same
  335. * as the namespace of the source entity.
  336. *
  337. * - <b>mappedBy</b> (string, required for bidirectional associations)
  338. * The name of the field that completes the bidirectional association on the owning side.
  339. * This key must be specified on the inverse side of a bidirectional association.
  340. *
  341. * - <b>inversedBy</b> (string, required for bidirectional associations)
  342. * The name of the field that completes the bidirectional association on the inverse side.
  343. * This key must be specified on the owning side of a bidirectional association.
  344. *
  345. * - <b>cascade</b> (array, optional)
  346. * The names of persistence operations to cascade on the association. The set of possible
  347. * values are: "persist", "remove", "detach", "merge", "refresh", "all" (implies all others).
  348. *
  349. * - <b>orderBy</b> (array, one-to-many/many-to-many only)
  350. * A map of field names (of the target entity) to sorting directions (ASC/DESC).
  351. * Example: array('priority' => 'desc')
  352. *
  353. * - <b>fetch</b> (integer, optional)
  354. * The fetching strategy to use for the association, usually defaults to FETCH_LAZY.
  355. * Possible values are: ClassMetadata::FETCH_EAGER, ClassMetadata::FETCH_LAZY.
  356. *
  357. * - <b>joinTable</b> (array, optional, many-to-many only)
  358. * Specification of the join table and its join columns (foreign keys).
  359. * Only valid for many-to-many mappings. Note that one-to-many associations can be mapped
  360. * through a join table by simply mapping the association as many-to-many with a unique
  361. * constraint on the join table.
  362. *
  363. * - <b>indexBy</b> (string, optional, to-many only)
  364. * Specification of a field on target-entity that is used to index the collection by.
  365. * This field HAS to be either the primary key or a unique column. Otherwise the collection
  366. * does not contain all the entities that are actually related.
  367. *
  368. * A join table definition has the following structure:
  369. * <pre>
  370. * array(
  371. * 'name' => <join table name>,
  372. * 'joinColumns' => array(<join column mapping from join table to source table>),
  373. * 'inverseJoinColumns' => array(<join column mapping from join table to target table>)
  374. * )
  375. * </pre>
  376. *
  377. *
  378. * @var array
  379. */
  380. public $associationMappings = array();
  381. /**
  382. * READ-ONLY: Flag indicating whether the identifier/primary key of the class is composite.
  383. *
  384. * @var boolean
  385. */
  386. public $isIdentifierComposite = false;
  387. /**
  388. * READ-ONLY: Flag indicating wheather the identifier/primary key contains at least one foreign key association.
  389. *
  390. * This flag is necessary because some code blocks require special treatment of this cases.
  391. *
  392. * @var boolean
  393. */
  394. public $containsForeignIdentifier = false;
  395. /**
  396. * READ-ONLY: The ID generator used for generating IDs for this class.
  397. *
  398. * @var AbstractIdGenerator
  399. * @todo Remove!
  400. */
  401. public $idGenerator;
  402. /**
  403. * READ-ONLY: The definition of the sequence generator of this class. Only used for the
  404. * SEQUENCE generation strategy.
  405. *
  406. * The definition has the following structure:
  407. * <code>
  408. * array(
  409. * 'sequenceName' => 'name',
  410. * 'allocationSize' => 20,
  411. * 'initialValue' => 1
  412. * )
  413. * </code>
  414. *
  415. * @var array
  416. * @todo Merge with tableGeneratorDefinition into generic generatorDefinition
  417. */
  418. public $sequenceGeneratorDefinition;
  419. /**
  420. * READ-ONLY: The definition of the table generator of this class. Only used for the
  421. * TABLE generation strategy.
  422. *
  423. * @var array
  424. * @todo Merge with tableGeneratorDefinition into generic generatorDefinition
  425. */
  426. public $tableGeneratorDefinition;
  427. /**
  428. * READ-ONLY: The policy used for change-tracking on entities of this class.
  429. *
  430. * @var integer
  431. */
  432. public $changeTrackingPolicy = self::CHANGETRACKING_DEFERRED_IMPLICIT;
  433. /**
  434. * READ-ONLY: A flag for whether or not instances of this class are to be versioned
  435. * with optimistic locking.
  436. *
  437. * @var boolean $isVersioned
  438. */
  439. public $isVersioned;
  440. /**
  441. * READ-ONLY: The name of the field which is used for versioning in optimistic locking (if any).
  442. *
  443. * @var mixed $versionField
  444. */
  445. public $versionField;
  446. /**
  447. * The ReflectionClass instance of the mapped class.
  448. *
  449. * @var ReflectionClass
  450. */
  451. public $reflClass;
  452. /**
  453. * Is this entity marked as "read-only"?
  454. *
  455. * That means it is never considered for change-tracking in the UnitOfWork. It is a very helpful performance
  456. * optimization for entities that are immutable, either in your domain or through the relation database
  457. * (coming from a view, or a history table for example).
  458. *
  459. * @var bool
  460. */
  461. public $isReadOnly = false;
  462. /**
  463. * Initializes a new ClassMetadata instance that will hold the object-relational mapping
  464. * metadata of the class with the given name.
  465. *
  466. * @param string $entityName The name of the entity class the new instance is used for.
  467. */
  468. public function __construct($entityName)
  469. {
  470. $this->name = $entityName;
  471. $this->rootEntityName = $entityName;
  472. }
  473. /**
  474. * Gets the ReflectionClass instance of the mapped class.
  475. *
  476. * @return ReflectionClass
  477. */
  478. public function getReflectionClass()
  479. {
  480. if ( ! $this->reflClass) {
  481. $this->reflClass = new ReflectionClass($this->name);
  482. }
  483. return $this->reflClass;
  484. }
  485. /**
  486. * Sets the change tracking policy used by this class.
  487. *
  488. * @param integer $policy
  489. */
  490. public function setChangeTrackingPolicy($policy)
  491. {
  492. $this->changeTrackingPolicy = $policy;
  493. }
  494. /**
  495. * Whether the change tracking policy of this class is "deferred explicit".
  496. *
  497. * @return boolean
  498. */
  499. public function isChangeTrackingDeferredExplicit()
  500. {
  501. return $this->changeTrackingPolicy == self::CHANGETRACKING_DEFERRED_EXPLICIT;
  502. }
  503. /**
  504. * Whether the change tracking policy of this class is "deferred implicit".
  505. *
  506. * @return boolean
  507. */
  508. public function isChangeTrackingDeferredImplicit()
  509. {
  510. return $this->changeTrackingPolicy == self::CHANGETRACKING_DEFERRED_IMPLICIT;
  511. }
  512. /**
  513. * Whether the change tracking policy of this class is "notify".
  514. *
  515. * @return boolean
  516. */
  517. public function isChangeTrackingNotify()
  518. {
  519. return $this->changeTrackingPolicy == self::CHANGETRACKING_NOTIFY;
  520. }
  521. /**
  522. * Checks whether a field is part of the identifier/primary key field(s).
  523. *
  524. * @param string $fieldName The field name
  525. * @return boolean TRUE if the field is part of the table identifier/primary key field(s),
  526. * FALSE otherwise.
  527. */
  528. public function isIdentifier($fieldName)
  529. {
  530. if ( ! $this->isIdentifierComposite) {
  531. return $fieldName === $this->identifier[0];
  532. }
  533. return in_array($fieldName, $this->identifier);
  534. }
  535. /**
  536. * Check if the field is unique.
  537. *
  538. * @param string $fieldName The field name
  539. * @return boolean TRUE if the field is unique, FALSE otherwise.
  540. */
  541. public function isUniqueField($fieldName)
  542. {
  543. $mapping = $this->getFieldMapping($fieldName);
  544. if ($mapping !== false) {
  545. return isset($mapping['unique']) && $mapping['unique'] == true;
  546. }
  547. return false;
  548. }
  549. /**
  550. * Check if the field is not null.
  551. *
  552. * @param string $fieldName The field name
  553. * @return boolean TRUE if the field is not null, FALSE otherwise.
  554. */
  555. public function isNullable($fieldName)
  556. {
  557. $mapping = $this->getFieldMapping($fieldName);
  558. if ($mapping !== false) {
  559. return isset($mapping['nullable']) && $mapping['nullable'] == true;
  560. }
  561. return false;
  562. }
  563. /**
  564. * Gets a column name for a field name.
  565. * If the column name for the field cannot be found, the given field name
  566. * is returned.
  567. *
  568. * @param string $fieldName The field name.
  569. * @return string The column name.
  570. */
  571. public function getColumnName($fieldName)
  572. {
  573. return isset($this->columnNames[$fieldName]) ?
  574. $this->columnNames[$fieldName] : $fieldName;
  575. }
  576. /**
  577. * Gets the mapping of a (regular) field that holds some data but not a
  578. * reference to another object.
  579. *
  580. * @param string $fieldName The field name.
  581. * @return array The field mapping.
  582. */
  583. public function getFieldMapping($fieldName)
  584. {
  585. if ( ! isset($this->fieldMappings[$fieldName])) {
  586. throw MappingException::mappingNotFound($this->name, $fieldName);
  587. }
  588. return $this->fieldMappings[$fieldName];
  589. }
  590. /**
  591. * Gets the mapping of an association.
  592. *
  593. * @see ClassMetadataInfo::$associationMappings
  594. * @param string $fieldName The field name that represents the association in
  595. * the object model.
  596. * @return array The mapping.
  597. */
  598. public function getAssociationMapping($fieldName)
  599. {
  600. if ( ! isset($this->associationMappings[$fieldName])) {
  601. throw MappingException::mappingNotFound($this->name, $fieldName);
  602. }
  603. return $this->associationMappings[$fieldName];
  604. }
  605. /**
  606. * Gets all association mappings of the class.
  607. *
  608. * @return array
  609. */
  610. public function getAssociationMappings()
  611. {
  612. return $this->associationMappings;
  613. }
  614. /**
  615. * Gets the field name for a column name.
  616. * If no field name can be found the column name is returned.
  617. *
  618. * @param string $columnName column name
  619. * @return string column alias
  620. */
  621. public function getFieldName($columnName)
  622. {
  623. return isset($this->fieldNames[$columnName]) ?
  624. $this->fieldNames[$columnName] : $columnName;
  625. }
  626. /**
  627. * Gets the named query.
  628. *
  629. * @see ClassMetadataInfo::$namedQueries
  630. * @throws MappingException
  631. * @param string $queryName The query name
  632. * @return string
  633. */
  634. public function getNamedQuery($queryName)
  635. {
  636. if ( ! isset($this->namedQueries[$queryName])) {
  637. throw MappingException::queryNotFound($this->name, $queryName);
  638. }
  639. return $this->namedQueries[$queryName];
  640. }
  641. /**
  642. * Gets all named queries of the class.
  643. *
  644. * @return array
  645. */
  646. public function getNamedQueries()
  647. {
  648. return $this->namedQueries;
  649. }
  650. /**
  651. * Validates & completes the given field mapping.
  652. *
  653. * @param array $mapping The field mapping to validated & complete.
  654. * @return array The validated and completed field mapping.
  655. */
  656. protected function _validateAndCompleteFieldMapping(array &$mapping)
  657. {
  658. // Check mandatory fields
  659. if ( ! isset($mapping['fieldName']) || strlen($mapping['fieldName']) == 0) {
  660. throw MappingException::missingFieldName($this->name);
  661. }
  662. if ( ! isset($mapping['type'])) {
  663. // Default to string
  664. $mapping['type'] = 'string';
  665. }
  666. // Complete fieldName and columnName mapping
  667. if ( ! isset($mapping['columnName'])) {
  668. $mapping['columnName'] = $mapping['fieldName'];
  669. } else {
  670. if ($mapping['columnName'][0] == '`') {
  671. $mapping['columnName'] = trim($mapping['columnName'], '`');
  672. $mapping['quoted'] = true;
  673. }
  674. }
  675. $this->columnNames[$mapping['fieldName']] = $mapping['columnName'];
  676. if (isset($this->fieldNames[$mapping['columnName']]) || ($this->discriminatorColumn != null && $this->discriminatorColumn['name'] == $mapping['columnName'])) {
  677. throw MappingException::duplicateColumnName($this->name, $mapping['columnName']);
  678. }
  679. $this->fieldNames[$mapping['columnName']] = $mapping['fieldName'];
  680. // Complete id mapping
  681. if (isset($mapping['id']) && $mapping['id'] === true) {
  682. if ($this->versionField == $mapping['fieldName']) {
  683. throw MappingException::cannotVersionIdField($this->name, $mapping['fieldName']);
  684. }
  685. if ( ! in_array($mapping['fieldName'], $this->identifier)) {
  686. $this->identifier[] = $mapping['fieldName'];
  687. }
  688. // Check for composite key
  689. if ( ! $this->isIdentifierComposite && count($this->identifier) > 1) {
  690. $this->isIdentifierComposite = true;
  691. }
  692. }
  693. }
  694. /**
  695. * Validates & completes the basic mapping information that is common to all
  696. * association mappings (one-to-one, many-ot-one, one-to-many, many-to-many).
  697. *
  698. * @param array $mapping The mapping.
  699. * @return array The updated mapping.
  700. * @throws MappingException If something is wrong with the mapping.
  701. */
  702. protected function _validateAndCompleteAssociationMapping(array $mapping)
  703. {
  704. if ( ! isset($mapping['mappedBy'])) {
  705. $mapping['mappedBy'] = null;
  706. }
  707. if ( ! isset($mapping['inversedBy'])) {
  708. $mapping['inversedBy'] = null;
  709. }
  710. $mapping['isOwningSide'] = true; // assume owning side until we hit mappedBy
  711. // unset optional indexBy attribute if its empty
  712. if (!isset($mapping['indexBy']) || !$mapping['indexBy']) {
  713. unset($mapping['indexBy']);
  714. }
  715. // If targetEntity is unqualified, assume it is in the same namespace as
  716. // the sourceEntity.
  717. $mapping['sourceEntity'] = $this->name;
  718. if (isset($mapping['targetEntity'])) {
  719. if (strlen($this->namespace) > 0 && strpos($mapping['targetEntity'], '\\') === false) {
  720. $mapping['targetEntity'] = $this->namespace . '\\' . $mapping['targetEntity'];
  721. }
  722. $mapping['targetEntity'] = ltrim($mapping['targetEntity'], '\\');
  723. }
  724. // Complete id mapping
  725. if (isset($mapping['id']) && $mapping['id'] === true) {
  726. if (isset($mapping['orphanRemoval']) && $mapping['orphanRemoval'] == true) {
  727. throw MappingException::illegalOrphanRemovalOnIdentifierAssociation($this->name, $mapping['fieldName']);
  728. }
  729. if ( ! in_array($mapping['fieldName'], $this->identifier)) {
  730. if (count($mapping['joinColumns']) >= 2) {
  731. throw MappingException::cannotMapCompositePrimaryKeyEntitiesAsForeignId(
  732. $mapping['targetEntity'], $this->name, $mapping['fieldName']
  733. );
  734. }
  735. $this->identifier[] = $mapping['fieldName'];
  736. $this->containsForeignIdentifier = true;
  737. }
  738. // Check for composite key
  739. if ( ! $this->isIdentifierComposite && count($this->identifier) > 1) {
  740. $this->isIdentifierComposite = true;
  741. }
  742. }
  743. // Mandatory attributes for both sides
  744. // Mandatory: fieldName, targetEntity
  745. if ( ! isset($mapping['fieldName']) || strlen($mapping['fieldName']) == 0) {
  746. throw MappingException::missingFieldName($this->name);
  747. }
  748. if ( ! isset($mapping['targetEntity'])) {
  749. throw MappingException::missingTargetEntity($mapping['fieldName']);
  750. }
  751. // Mandatory and optional attributes for either side
  752. if ( ! $mapping['mappedBy']) {
  753. if (isset($mapping['joinTable']) && $mapping['joinTable']) {
  754. if (isset($mapping['joinTable']['name']) && $mapping['joinTable']['name'][0] == '`') {
  755. $mapping['joinTable']['name'] = trim($mapping['joinTable']['name'], '`');
  756. $mapping['joinTable']['quoted'] = true;
  757. }
  758. }
  759. } else {
  760. $mapping['isOwningSide'] = false;
  761. }
  762. if (isset($mapping['id']) && $mapping['id'] === true && $mapping['type'] & self::TO_MANY) {
  763. throw MappingException::illegalToManyIdentifierAssoaction($this->name, $mapping['fieldName']);
  764. }
  765. // Fetch mode. Default fetch mode to LAZY, if not set.
  766. if ( ! isset($mapping['fetch'])) {
  767. $mapping['fetch'] = self::FETCH_LAZY;
  768. }
  769. // Cascades
  770. $cascades = isset($mapping['cascade']) ? array_map('strtolower', $mapping['cascade']) : array();
  771. if (in_array('all', $cascades)) {
  772. $cascades = array(
  773. 'remove',
  774. 'persist',
  775. 'refresh',
  776. 'merge',
  777. 'detach'
  778. );
  779. }
  780. $mapping['cascade'] = $cascades;
  781. $mapping['isCascadeRemove'] = in_array('remove', $cascades);
  782. $mapping['isCascadePersist'] = in_array('persist', $cascades);
  783. $mapping['isCascadeRefresh'] = in_array('refresh', $cascades);
  784. $mapping['isCascadeMerge'] = in_array('merge', $cascades);
  785. $mapping['isCascadeDetach'] = in_array('detach', $cascades);
  786. return $mapping;
  787. }
  788. /**
  789. * Validates & completes a one-to-one association mapping.
  790. *
  791. * @param array $mapping The mapping to validate & complete.
  792. * @return array The validated & completed mapping.
  793. * @override
  794. */
  795. protected function _validateAndCompleteOneToOneMapping(array $mapping)
  796. {
  797. $mapping = $this->_validateAndCompleteAssociationMapping($mapping);
  798. if (isset($mapping['joinColumns']) && $mapping['joinColumns']) {
  799. $mapping['isOwningSide'] = true;
  800. }
  801. if ($mapping['isOwningSide']) {
  802. if ( ! isset($mapping['joinColumns']) || ! $mapping['joinColumns']) {
  803. // Apply default join column
  804. $mapping['joinColumns'] = array(array(
  805. 'name' => $mapping['fieldName'] . '_id',
  806. 'referencedColumnName' => 'id'
  807. ));
  808. }
  809. $uniqueContraintColumns = array();
  810. foreach ($mapping['joinColumns'] as $key => &$joinColumn) {
  811. if ($mapping['type'] === self::ONE_TO_ONE) {
  812. if (count($mapping['joinColumns']) == 1) {
  813. $joinColumn['unique'] = true;
  814. } else {
  815. $uniqueContraintColumns[] = $joinColumn['name'];
  816. }
  817. }
  818. if (empty($joinColumn['name'])) {
  819. $joinColumn['name'] = $mapping['fieldName'] . '_id';
  820. }
  821. if (empty($joinColumn['referencedColumnName'])) {
  822. $joinColumn['referencedColumnName'] = 'id';
  823. }
  824. $mapping['sourceToTargetKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName'];
  825. $mapping['joinColumnFieldNames'][$joinColumn['name']] = isset($joinColumn['fieldName'])
  826. ? $joinColumn['fieldName'] : $joinColumn['name'];
  827. }
  828. if ($uniqueContraintColumns) {
  829. if (!$this->table) {
  830. throw new \RuntimeException("ClassMetadataInfo::setTable() has to be called before defining a one to one relationship.");
  831. }
  832. $this->table['uniqueConstraints'][$mapping['fieldName']."_uniq"] = array(
  833. 'columns' => $uniqueContraintColumns
  834. );
  835. }
  836. $mapping['targetToSourceKeyColumns'] = array_flip($mapping['sourceToTargetKeyColumns']);
  837. }
  838. $mapping['orphanRemoval'] = isset($mapping['orphanRemoval']) ? (bool) $mapping['orphanRemoval'] : false;
  839. $mapping['isCascadeRemove'] = $mapping['orphanRemoval'] ? true : $mapping['isCascadeRemove'];
  840. if (isset($mapping['id']) && $mapping['id'] === true && !$mapping['isOwningSide']) {
  841. throw MappingException::illegalInverseIdentifierAssocation($this->name, $mapping['fieldName']);
  842. }
  843. return $mapping;
  844. }
  845. /**
  846. * Validates and completes the mapping.
  847. *
  848. * @param array $mapping The mapping to validate and complete.
  849. * @return array The validated and completed mapping.
  850. * @override
  851. */
  852. protected function _validateAndCompleteOneToManyMapping(array $mapping)
  853. {
  854. $mapping = $this->_validateAndCompleteAssociationMapping($mapping);
  855. // OneToMany-side MUST be inverse (must have mappedBy)
  856. if ( ! isset($mapping['mappedBy'])) {
  857. throw MappingException::oneToManyRequiresMappedBy($mapping['fieldName']);
  858. }
  859. $mapping['orphanRemoval'] = isset($mapping['orphanRemoval']) ? (bool) $mapping['orphanRemoval'] : false;
  860. $mapping['isCascadeRemove'] = $mapping['orphanRemoval'] ? true : $mapping['isCascadeRemove'];
  861. if (isset($mapping['orderBy'])) {
  862. if ( ! is_array($mapping['orderBy'])) {
  863. throw new \InvalidArgumentException("'orderBy' is expected to be an array, not ".gettype($mapping['orderBy']));
  864. }
  865. }
  866. return $mapping;
  867. }
  868. protected function _validateAndCompleteManyToManyMapping(array $mapping)
  869. {
  870. $mapping = $this->_validateAndCompleteAssociationMapping($mapping);
  871. if ($mapping['isOwningSide']) {
  872. if (strpos($mapping['sourceEntity'], '\\') !== false) {
  873. $sourceShortName = strtolower(substr($mapping['sourceEntity'], strrpos($mapping['sourceEntity'], '\\') + 1));
  874. } else {
  875. $sourceShortName = strtolower($mapping['sourceEntity']);
  876. }
  877. if (strpos($mapping['targetEntity'], '\\') !== false) {
  878. $targetShortName = strtolower(substr($mapping['targetEntity'], strrpos($mapping['targetEntity'], '\\') + 1));
  879. } else {
  880. $targetShortName = strtolower($mapping['targetEntity']);
  881. }
  882. // owning side MUST have a join table
  883. if ( ! isset($mapping['joinTable']['name'])) {
  884. $mapping['joinTable']['name'] = $sourceShortName .'_' . $targetShortName;
  885. }
  886. if ( ! isset($mapping['joinTable']['joinColumns'])) {
  887. $mapping['joinTable']['joinColumns'] = array(array(
  888. 'name' => $sourceShortName . '_id',
  889. 'referencedColumnName' => 'id',
  890. 'onDelete' => 'CASCADE'));
  891. }
  892. if ( ! isset($mapping['joinTable']['inverseJoinColumns'])) {
  893. $mapping['joinTable']['inverseJoinColumns'] = array(array(
  894. 'name' => $targetShortName . '_id',
  895. 'referencedColumnName' => 'id',
  896. 'onDelete' => 'CASCADE'));
  897. }
  898. foreach ($mapping['joinTable']['joinColumns'] as &$joinColumn) {
  899. if (empty($joinColumn['name'])) {
  900. $joinColumn['name'] = $sourceShortName . '_id';
  901. }
  902. if (empty($joinColumn['referencedColumnName'])) {
  903. $joinColumn['referencedColumnName'] = 'id';
  904. }
  905. if (isset($joinColumn['onDelete']) && strtolower($joinColumn['onDelete']) == 'cascade') {
  906. $mapping['isOnDeleteCascade'] = true;
  907. }
  908. $mapping['relationToSourceKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName'];
  909. $mapping['joinTableColumns'][] = $joinColumn['name'];
  910. }
  911. foreach ($mapping['joinTable']['inverseJoinColumns'] as &$inverseJoinColumn) {
  912. if (empty($inverseJoinColumn['name'])) {
  913. $inverseJoinColumn['name'] = $targetShortName . '_id';
  914. }
  915. if (empty($inverseJoinColumn['referencedColumnName'])) {
  916. $inverseJoinColumn['referencedColumnName'] = 'id';
  917. }
  918. if (isset($inverseJoinColumn['onDelete']) && strtolower($inverseJoinColumn['onDelete']) == 'cascade') {
  919. $mapping['isOnDeleteCascade'] = true;
  920. }
  921. $mapping['relationToTargetKeyColumns'][$inverseJoinColumn['name']] = $inverseJoinColumn['referencedColumnName'];
  922. $mapping['joinTableColumns'][] = $inverseJoinColumn['name'];
  923. }
  924. }
  925. if (isset($mapping['orderBy'])) {
  926. if ( ! is_array($mapping['orderBy'])) {
  927. throw new \InvalidArgumentException("'orderBy' is expected to be an array, not ".gettype($mapping['orderBy']));
  928. }
  929. }
  930. return $mapping;
  931. }
  932. /**
  933. * Gets the identifier (primary key) field names of the class.
  934. *
  935. * @return mixed
  936. */
  937. public function getIdentifierFieldNames()
  938. {
  939. return $this->identifier;
  940. }
  941. /**
  942. * Gets the name of the single id field. Note that this only works on
  943. * entity classes that have a single-field pk.
  944. *
  945. * @return string
  946. * @throws MappingException If the class has a composite primary key.
  947. */
  948. public function getSingleIdentifierFieldName()
  949. {
  950. if ($this->isIdentifierComposite) {
  951. throw MappingException::singleIdNotAllowedOnCompositePrimaryKey($this->name);
  952. }
  953. return $this->identifier[0];
  954. }
  955. /**
  956. * Gets the column name of the single id column. Note that this only works on
  957. * entity classes that have a single-field pk.
  958. *
  959. * @return string
  960. * @throws MappingException If the class has a composite primary key.
  961. */
  962. public function getSingleIdentifierColumnName()
  963. {
  964. return $this->getColumnName($this->getSingleIdentifierFieldName());
  965. }
  966. /**
  967. * INTERNAL:
  968. * Sets the mapped identifier/primary key fields of this class.
  969. * Mainly used by the ClassMetadataFactory to assign inherited identifiers.
  970. *
  971. * @param array $identifier
  972. */
  973. public function setIdentifier(array $identifier)
  974. {
  975. $this->identifier = $identifier;
  976. $this->isIdentifierComposite = (count($this->identifier) > 1);
  977. }
  978. /**
  979. * Gets the mapped identifier field of this class.
  980. *
  981. * @return string $identifier
  982. */
  983. public function getIdentifier()
  984. {
  985. return $this->identifier;
  986. }
  987. /**
  988. * Checks whether the class has a (mapped) field with a certain name.
  989. *
  990. * @return boolean
  991. */
  992. public function hasField($fieldName)
  993. {
  994. return isset($this->fieldMappings[$fieldName]);
  995. }
  996. /**
  997. * Gets an array containing all the column names.
  998. *
  999. * @return array
  1000. */
  1001. public function getColumnNames(array $fieldNames = null)
  1002. {
  1003. if ($fieldNames === null) {
  1004. return array_keys($this->fieldNames);
  1005. } else {
  1006. $columnNames = array();
  1007. foreach ($fieldNames as $fieldName) {
  1008. $columnNames[] = $this->getColumnName($fieldName);
  1009. }
  1010. return $columnNames;
  1011. }
  1012. }
  1013. /**
  1014. * Returns an array with all the identifier column names.
  1015. *
  1016. * @return array
  1017. */
  1018. public function getIdentifierColumnNames()
  1019. {
  1020. $columnNames = array();
  1021. foreach ($this->identifier as $idProperty) {
  1022. if (isset($this->fieldMappings[$idProperty])) {
  1023. $columnNames[] = $this->fieldMappings[$idProperty]['columnName'];
  1024. continue;
  1025. }
  1026. // Association defined as Id field
  1027. $joinColumns = $this->associationMappings[$idProperty]['joinColumns'];
  1028. $assocColumnNames = array_map(function ($joinColumn) { return $joinColumn['name']; }, $joinColumns);
  1029. $columnNames = array_merge($columnNames, $assocColumnNames);
  1030. }
  1031. return $columnNames;
  1032. }
  1033. /**
  1034. * Sets the type of Id generator to use for the mapped class.
  1035. */
  1036. public function setIdGeneratorType($generatorType)
  1037. {
  1038. $this->generatorType = $generatorType;
  1039. }
  1040. /**
  1041. * Checks whether the mapped class uses an Id generator.
  1042. *
  1043. * @return boolean TRUE if the mapped class uses an Id generator, FALSE otherwise.
  1044. */
  1045. public function usesIdGenerator()
  1046. {
  1047. return $this->generatorType != self::GENERATOR_TYPE_NONE;
  1048. }
  1049. /**
  1050. * @return boolean
  1051. */
  1052. public function isInheritanceTypeNone()
  1053. {
  1054. return $this->inheritanceType == self::INHERITANCE_TYPE_NONE;
  1055. }
  1056. /**
  1057. * Checks whether the mapped class uses the JOINED inheritance mapping strategy.
  1058. *
  1059. * @return boolean TRUE if the class participates in a JOINED inheritance mapping,
  1060. * FALSE otherwise.
  1061. */
  1062. public function isInheritanceTypeJoined()
  1063. {
  1064. return $this->inheritanceType == self::INHERITANCE_TYPE_JOINED;
  1065. }
  1066. /**
  1067. * Checks whether the mapped class uses the SINGLE_TABLE inheritance mapping strategy.
  1068. *
  1069. * @return boolean TRUE if the class participates in a SINGLE_TABLE inheritance mapping,
  1070. * FALSE otherwise.
  1071. */
  1072. public function isInheritanceTypeSingleTable()
  1073. {
  1074. return $this->inheritanceType == self::INHERITANCE_TYPE_SINGLE_TABLE;
  1075. }
  1076. /**
  1077. * Checks whether the mapped class uses the TABLE_PER_CLASS inheritance mapping strategy.
  1078. *
  1079. * @return boolean TRUE if the class participates in a TABLE_PER_CLASS inheritance mapping,
  1080. * FALSE otherwise.
  1081. */
  1082. public function isInheritanceTypeTablePerClass()
  1083. {
  1084. return $this->inheritanceType == self::INHERITANCE_TYPE_TABLE_PER_CLASS;
  1085. }
  1086. /**
  1087. * Checks whether the class uses an identity column for the Id generation.
  1088. *
  1089. * @return boolean TRUE if the class uses the IDENTITY generator, FALSE otherwise.
  1090. */
  1091. public function isIdGeneratorIdentity()
  1092. {
  1093. return $this->generatorType == self::GENERATOR_TYPE_IDENTITY;
  1094. }
  1095. /**
  1096. * Checks whether the class uses a sequence for id generation.
  1097. *
  1098. * @return boolean TRUE if the class uses the SEQUENCE generator, FALSE otherwise.
  1099. */
  1100. public function isIdGeneratorSequence()
  1101. {
  1102. return $this->generatorType == self::GENERATOR_TYPE_SEQUENCE;
  1103. }
  1104. /**
  1105. * Checks whether the class uses a table for id generation.
  1106. *
  1107. * @return boolean TRUE if the class uses the TABLE generator, FALSE otherwise.
  1108. */
  1109. public function isIdGeneratorTable()
  1110. {
  1111. $this->generatorType == self::GENERATOR_TYPE_TABLE;
  1112. }
  1113. /**
  1114. * Checks whether the class has a natural identifier/pk (which means it does
  1115. * not use any Id generator.
  1116. *
  1117. * @return boolean
  1118. */
  1119. public function isIdentifierNatural()
  1120. {
  1121. return $this->generatorType == self::GENERATOR_TYPE_NONE;
  1122. }
  1123. /**
  1124. * Gets the type of a field.
  1125. *
  1126. * @param string $fieldName
  1127. * @return \Doctrine\DBAL\Types\Type
  1128. */
  1129. public function getTypeOfField($fieldName)
  1130. {
  1131. return isset($this->fieldMappings[$fieldName]) ?
  1132. $this->fieldMappings[$fieldName]['type'] : null;
  1133. }
  1134. /**
  1135. * Gets the type of a column.
  1136. *
  1137. * @return \Doctrine\DBAL\Types\Type
  1138. */
  1139. public function getTypeOfColumn($columnName)
  1140. {
  1141. return $this->getTypeOfField($this->getFieldName($columnName));
  1142. }
  1143. /**
  1144. * Gets the name of the primary table.
  1145. *
  1146. * @return string
  1147. */
  1148. public function getTableName()
  1149. {
  1150. return $this->table['name'];
  1151. }
  1152. /**
  1153. * Gets the table name to use for temporary identifier tables of this class.
  1154. *
  1155. * @return string
  1156. */
  1157. public function getTemporaryIdTableName()
  1158. {
  1159. // replace dots with underscores because PostgreSQL creates temporary tables in a special schema
  1160. return str_replace('.', '_', $this->table['name'] . '_id_tmp');
  1161. }
  1162. /**
  1163. * Sets the mapped subclasses of this class.
  1164. *
  1165. * @param array $subclasses The names of all mapped subclasses.
  1166. */
  1167. public function setSubclasses(array $subclasses)
  1168. {
  1169. foreach ($subclasses as $subclass) {
  1170. if (strpos($subclass, '\\') === false && strlen($this->namespace)) {
  1171. $this->subClasses[] = $this->namespace . '\\' . $subclass;
  1172. } else {
  1173. $this->subClasses[] = $subclass;
  1174. }
  1175. }
  1176. }
  1177. /**
  1178. * Sets the parent class names.
  1179. * Assumes that the class names in the passed array are in the order:
  1180. * directParent -> directParentParent -> directParentParentParent ... -> root.
  1181. */
  1182. public function setParentClasses(array $classNames)
  1183. {
  1184. $this->parentClasses = $classNames;
  1185. if (count($classNames) > 0) {
  1186. $this->rootEntityName = array_pop($classNames);
  1187. }
  1188. }
  1189. /**
  1190. * Sets the inheritance type used by the class and it's subclasses.
  1191. *
  1192. * @param integer $type
  1193. */
  1194. public function setInheritanceType($type)
  1195. {
  1196. if ( ! $this->_isInheritanceType($type)) {
  1197. throw MappingException::invalidInheritanceType($this->name, $type);
  1198. }
  1199. $this->inheritanceType = $type;
  1200. }
  1201. /**
  1202. * Checks whether a mapped field is inherited from an entity superclass.
  1203. *
  1204. * @return boolean TRUE if the field is inherited, FALSE otherwise.
  1205. */
  1206. public function isInheritedField($fieldName)
  1207. {
  1208. return isset($this->fieldMappings[$fieldName]['inherited']);
  1209. }
  1210. /**
  1211. * Checks whether a mapped association field is inherited from a superclass.
  1212. *
  1213. * @param string $fieldName
  1214. * @return boolean TRUE if the field is inherited, FALSE otherwise.
  1215. */
  1216. public function isInheritedAssociation($fieldName)
  1217. {
  1218. return isset($this->associationMappings[$fieldName]['inherited']);
  1219. }
  1220. /**
  1221. * Sets the name of the primary table the class is mapped to.
  1222. *
  1223. * @param string $tableName The table name.
  1224. * @deprecated Use {@link setPrimaryTable}.
  1225. */
  1226. public function setTableName($tableName)
  1227. {
  1228. $this->table['name'] = $tableName;
  1229. }
  1230. /**
  1231. * Sets the primary table definition. The provided array supports the
  1232. * following structure:
  1233. *
  1234. * name => <tableName> (optional, defaults to class name)
  1235. * indexes => array of indexes (optional)
  1236. * uniqueConstraints => array of constraints (optional)
  1237. *
  1238. * If a key is omitted, the current value is kept.
  1239. *
  1240. * @param array $table The table description.
  1241. */
  1242. public function setPrimaryTable(array $table)
  1243. {
  1244. if (isset($table['name'])) {
  1245. if ($table['name'][0] == '`') {
  1246. $this->table['name'] = trim($table['name'], '`');
  1247. $this->table['quoted'] = true;
  1248. } else {
  1249. $this->table['name'] = $table['name'];
  1250. }
  1251. }
  1252. if (isset($table['indexes'])) {
  1253. $this->table['indexes'] = $table['indexes'];
  1254. }
  1255. if (isset($table['uniqueConstraints'])) {
  1256. $this->table['uniqueConstraints'] = $table['uniqueConstraints'];
  1257. }
  1258. }
  1259. /**
  1260. * Checks whether the given type identifies an inheritance type.
  1261. *
  1262. * @param integer $type
  1263. * @return boolean TRUE if the given type identifies an inheritance type, FALSe otherwise.
  1264. */
  1265. private function _isInheritanceType($type)
  1266. {
  1267. return $type == self::INHERITANCE_TYPE_NONE ||
  1268. $type == self::INHERITANCE_TYPE_SINGLE_TABLE ||
  1269. $type == self::INHERITANCE_TYPE_JOINED ||
  1270. $type == self::INHERITANCE_TYPE_TABLE_PER_CLASS;
  1271. }
  1272. /**
  1273. * Adds a mapped field to the class.
  1274. *
  1275. * @param array $mapping The field mapping.
  1276. */
  1277. public function mapField(array $mapping)
  1278. {
  1279. $this->_validateAndCompleteFieldMapping($mapping);
  1280. if (isset($this->fieldMappings[$mapping['fieldName']]) || isset($this->associationMappings[$mapping['fieldName']])) {
  1281. throw MappingException::duplicateFieldMapping($this->name, $mapping['fieldName']);
  1282. }
  1283. $this->fieldMappings[$mapping['fieldName']] = $mapping;
  1284. }
  1285. /**
  1286. * INTERNAL:
  1287. * Adds an association mapping without completing/validating it.
  1288. * This is mainly used to add inherited association mappings to derived classes.
  1289. *
  1290. * @param array $mapping
  1291. */
  1292. public function addInheritedAssociationMapping(array $mapping/*, $owningClassName = null*/)
  1293. {
  1294. if (isset($this->associationMappings[$mapping['fieldName']])) {
  1295. throw MappingException::duplicateAssociationMapping($this->name, $mapping['fieldName']);
  1296. }
  1297. $this->associationMappings[$mapping['fieldName']] = $mapping;
  1298. }
  1299. /**
  1300. * INTERNAL:
  1301. * Adds a field mapping without completing/validating it.
  1302. * This is mainly used to add inherited field mappings to derived classes.
  1303. *
  1304. * @param array $mapping
  1305. */
  1306. public function addInheritedFieldMapping(array $fieldMapping)
  1307. {
  1308. $this->fieldMappings[$fieldMapping['fieldName']] = $fieldMapping;
  1309. $this->columnNames[$fieldMapping['fieldName']] = $fieldMapping['columnName'];
  1310. $this->fieldNames[$fieldMapping['columnName']] = $fieldMapping['fieldName'];
  1311. }
  1312. /**
  1313. * INTERNAL:
  1314. * Adds a named query to this class.
  1315. *
  1316. * @throws MappingException
  1317. * @param array $queryMapping
  1318. */
  1319. public function addNamedQuery(array $queryMapping)
  1320. {
  1321. if (isset($this->namedQueries[$queryMapping['name']])) {
  1322. throw MappingException::duplicateQueryMapping($this->name, $queryMapping['name']);
  1323. }
  1324. $query = str_replace('__CLASS__', $this->name, $queryMapping['query']);
  1325. $this->namedQueries[$queryMapping['name']] = $query;
  1326. }
  1327. /**
  1328. * Adds a one-to-one mapping.
  1329. *
  1330. * @param array $mapping The mapping.
  1331. */
  1332. public function mapOneToOne(array $mapping)
  1333. {
  1334. $mapping['type'] = self::ONE_TO_ONE;
  1335. $mapping = $this->_validateAndCompleteOneToOneMapping($mapping);
  1336. $this->_storeAssociationMapping($mapping);
  1337. }
  1338. /**
  1339. * Adds a one-to-many mapping.
  1340. *
  1341. * @param array $mapping The mapping.
  1342. */
  1343. public function mapOneToMany(array $mapping)
  1344. {
  1345. $mapping['type'] = self::ONE_TO_MANY;
  1346. $mapping = $this->_validateAndCompleteOneToManyMapping($mapping);
  1347. $this->_storeAssociationMapping($mapping);
  1348. }
  1349. /**
  1350. * Adds a many-to-one mapping.
  1351. *
  1352. * @param array $mapping The mapping.
  1353. */
  1354. public function mapManyToOne(array $mapping)
  1355. {
  1356. $mapping['type'] = self::MANY_TO_ONE;
  1357. // A many-to-one mapping is essentially a one-one backreference
  1358. $mapping = $this->_validateAndCompleteOneToOneMapping($mapping);
  1359. $this->_storeAssociationMapping($mapping);
  1360. }
  1361. /**
  1362. * Adds a many-to-many mapping.
  1363. *
  1364. * @param array $mapping The mapping.
  1365. */
  1366. public function mapManyToMany(array $mapping)
  1367. {
  1368. $mapping['type'] = self::MANY_TO_MANY;
  1369. $mapping = $this->_validateAndCompleteManyToManyMapping($mapping);
  1370. $this->_storeAssociationMapping($mapping);
  1371. }
  1372. /**
  1373. * Stores the association mapping.
  1374. *
  1375. * @param AssociationMapping $assocMapping
  1376. */
  1377. protected function _storeAssociationMapping(array $assocMapping)
  1378. {
  1379. $sourceFieldName = $assocMapping['fieldName'];
  1380. if (isset($this->fieldMappings[$sourceFieldName]) || isset($this->associationMappings[$sourceFieldName])) {
  1381. throw MappingException::duplicateFieldMapping($this->name, $sourceFieldName);
  1382. }
  1383. $this->associationMappings[$sourceFieldName] = $assocMapping;
  1384. }
  1385. /**
  1386. * Registers a custom repository class for the entity class.
  1387. *
  1388. * @param string $mapperClassName The class name of the custom mapper.
  1389. */
  1390. public function setCustomRepositoryClass($repositoryClassName)
  1391. {
  1392. $this->customRepositoryClassName = $repositoryClassName;
  1393. }
  1394. /**
  1395. * Dispatches the lifecycle event of the given entity to the registered
  1396. * lifecycle callbacks and lifecycle listeners.
  1397. *
  1398. * @param string $event The lifecycle event.
  1399. * @param Entity $entity The Entity on which the event occured.
  1400. */
  1401. public function invokeLifecycleCallbacks($lifecycleEvent, $entity)
  1402. {
  1403. foreach ($this->lifecycleCallbacks[$lifecycleEvent] as $callback) {
  1404. $entity->$callback();
  1405. }
  1406. }
  1407. /**
  1408. * Whether the class has any attached lifecycle listeners or callbacks for a lifecycle event.
  1409. *
  1410. * @param string $lifecycleEvent
  1411. * @return boolean
  1412. */
  1413. public function hasLifecycleCallbacks($lifecycleEvent)
  1414. {
  1415. return isset($this->lifecycleCallbacks[$lifecycleEvent]);
  1416. }
  1417. /**
  1418. * Gets the registered lifecycle callbacks for an event.
  1419. *
  1420. * @param string $event
  1421. * @return array
  1422. */
  1423. public function getLifecycleCallbacks($event)
  1424. {
  1425. return isset($this->lifecycleCallbacks[$event]) ? $this->lifecycleCallbacks[$event] : array();
  1426. }
  1427. /**
  1428. * Adds a lifecycle callback for entities of this class.
  1429. *
  1430. * Note: If the same callback is registered more than once, the old one
  1431. * will be overridden.
  1432. *
  1433. * @param string $callback
  1434. * @param string $event
  1435. */
  1436. public function addLifecycleCallback($callback, $event)
  1437. {
  1438. $this->lifecycleCallbacks[$event][] = $callback;
  1439. }
  1440. /**
  1441. * Sets the lifecycle callbacks for entities of this class.
  1442. * Any previously registered callbacks are overwritten.
  1443. *
  1444. * @param array $callbacks
  1445. */
  1446. public function setLifecycleCallbacks(array $callbacks)
  1447. {
  1448. $this->lifecycleCallbacks = $callbacks;
  1449. }
  1450. /**
  1451. * Sets the discriminator column definition.
  1452. *
  1453. * @param array $columnDef
  1454. * @see getDiscriminatorColumn()
  1455. */
  1456. public function setDiscriminatorColumn($columnDef)
  1457. {
  1458. if ($columnDef !== null) {
  1459. if (isset($this->fieldNames[$columnDef['name']])) {
  1460. throw MappingException::duplicateColumnName($this->name, $columnDef['name']);
  1461. }
  1462. if ( ! isset($columnDef['name'])) {
  1463. throw MappingException::nameIsMandatoryForDiscriminatorColumns($this->name, $columnDef);
  1464. }
  1465. if ( ! isset($columnDef['fieldName'])) {
  1466. $columnDef['fieldName'] = $columnDef['name'];
  1467. }
  1468. if ( ! isset($columnDef['type'])) {
  1469. $columnDef['type'] = "string";
  1470. }
  1471. if (in_array($columnDef['type'], array("boolean", "array", "object", "datetime", "time", "date"))) {
  1472. throw MappingException::invalidDiscriminatorColumnType($this->name, $columnDef['type']);
  1473. }
  1474. $this->discriminatorColumn = $columnDef;
  1475. }
  1476. }
  1477. /**
  1478. * Sets the discriminator values used by this class.
  1479. * Used for JOINED and SINGLE_TABLE inheritance mapping strategies.
  1480. *
  1481. * @param array $map
  1482. */
  1483. public function setDiscriminatorMap(array $map)
  1484. {
  1485. foreach ($map as $value => $className) {
  1486. if (strlen($this->namespace) > 0 && strpos($className, '\\') === false) {
  1487. $className = $this->namespace . '\\' . $className;
  1488. }
  1489. $className = ltrim($className, '\\');
  1490. $this->discriminatorMap[$value] = $className;
  1491. if ($this->name == $className) {
  1492. $this->discriminatorValue = $value;
  1493. } else {
  1494. if ( ! class_exists($className)) {
  1495. throw MappingException::invalidClassInDiscriminatorMap($className, $this->name);
  1496. }
  1497. if (is_subclass_of($className, $this->name)) {
  1498. $this->subClasses[] = $className;
  1499. }
  1500. }
  1501. }
  1502. }
  1503. /**
  1504. * Checks whether the class has a named query with the given query name.
  1505. *
  1506. * @param string $fieldName
  1507. * @return boolean
  1508. */
  1509. public function hasNamedQuery($queryName)
  1510. {
  1511. return isset($this->namedQueries[$queryName]);
  1512. }
  1513. /**
  1514. * Checks whether the class has a mapped association with the given field name.
  1515. *
  1516. * @param string $fieldName
  1517. * @return boolean
  1518. */
  1519. public function hasAssociation($fieldName)
  1520. {
  1521. return isset($this->associationMappings[$fieldName]);
  1522. }
  1523. /**
  1524. * Checks whether the class has a mapped association for the specified field
  1525. * and if yes, checks whether it is a single-valued association (to-one).
  1526. *
  1527. * @param string $fieldName
  1528. * @return boolean TRUE if the association exists and is single-valued, FALSE otherwise.
  1529. */
  1530. public function isSingleValuedAssociation($fieldName)
  1531. {
  1532. return isset($this->associationMappings[$fieldName]) &&
  1533. ($this->associationMappings[$fieldName]['type'] & self::TO_ONE);
  1534. }
  1535. /**
  1536. * Checks whether the class has a mapped association for the specified field
  1537. * and if yes, checks whether it is a collection-valued association (to-many).
  1538. *
  1539. * @param string $fieldName
  1540. * @return boolean TRUE if the association exists and is collection-valued, FALSE otherwise.
  1541. */
  1542. public function isCollectionValuedAssociation($fieldName)
  1543. {
  1544. return isset($this->associationMappings[$fieldName]) &&
  1545. ! ($this->associationMappings[$fieldName]['type'] & self::TO_ONE);
  1546. }
  1547. /**
  1548. * Is this an association that only has a single join column?
  1549. *
  1550. * @param string $fieldName
  1551. * @return bool
  1552. */
  1553. public function isAssociationWithSingleJoinColumn($fieldName)
  1554. {
  1555. return (
  1556. isset($this->associationMappings[$fieldName]) &&
  1557. isset($this->associationMappings[$fieldName]['joinColumns'][0]) &&
  1558. !isset($this->associationMappings[$fieldName]['joinColumns'][1])
  1559. );
  1560. }
  1561. /**
  1562. * Return the single association join column (if any).
  1563. *
  1564. * @param string $fieldName
  1565. * @return string
  1566. */
  1567. public function getSingleAssociationJoinColumnName($fieldName)
  1568. {
  1569. if (!$this->isAssociationWithSingleJoinColumn($fieldName)) {
  1570. throw MappingException::noSingleAssociationJoinColumnFound($this->name, $fieldName);
  1571. }
  1572. return $this->associationMappings[$fieldName]['joinColumns'][0]['name'];
  1573. }
  1574. /**
  1575. * Return the single association referenced join column name (if any).
  1576. *
  1577. * @param string $fieldName
  1578. * @return string
  1579. */
  1580. public function getSingleAssociationReferencedJoinColumnName($fieldName)
  1581. {
  1582. if (!$this->isAssociationWithSingleJoinColumn($fieldName)) {
  1583. throw MappingException::noSingleAssociationJoinColumnFound($this->name, $fieldName);
  1584. }
  1585. return $this->associationMappings[$fieldName]['joinColumns'][0]['referencedColumnName'];
  1586. }
  1587. /**
  1588. * Used to retrieve a fieldname for either field or association from a given column,
  1589. *
  1590. * This method is used in foreign-key as primary-key contexts.
  1591. *
  1592. * @param string $columnName
  1593. * @return string
  1594. */
  1595. public function getFieldForColumn($columnName)
  1596. {
  1597. if (isset($this->fieldNames[$columnName])) {
  1598. return $this->fieldNames[$columnName];
  1599. } else {
  1600. foreach ($this->associationMappings AS $assocName => $mapping) {
  1601. if ($this->isAssociationWithSingleJoinColumn($assocName) &&
  1602. $this->associationMappings[$assocName]['joinColumns'][0]['name'] == $columnName) {
  1603. return $assocName;
  1604. }
  1605. }
  1606. throw MappingException::noFieldNameFoundForColumn($this->name, $columnName);
  1607. }
  1608. }
  1609. /**
  1610. * Sets the ID generator used to generate IDs for instances of this class.
  1611. *
  1612. * @param AbstractIdGenerator $generator
  1613. */
  1614. public function setIdGenerator($generator)
  1615. {
  1616. $this->idGenerator = $generator;
  1617. }
  1618. /**
  1619. * Sets the definition of the sequence ID generator for this class.
  1620. *
  1621. * The definition must have the following structure:
  1622. * <code>
  1623. * array(
  1624. * 'sequenceName' => 'name',
  1625. * 'allocationSize' => 20,
  1626. * 'initialValue' => 1
  1627. * )
  1628. * </code>
  1629. *
  1630. * @param array $definition
  1631. */
  1632. public function setSequenceGeneratorDefinition(array $definition)
  1633. {
  1634. $this->sequenceGeneratorDefinition = $definition;
  1635. }
  1636. /**
  1637. * Sets the version field mapping used for versioning. Sets the default
  1638. * value to use depending on the column type.
  1639. *
  1640. * @param array $mapping The version field mapping array
  1641. */
  1642. public function setVersionMapping(array &$mapping)
  1643. {
  1644. $this->isVersioned = true;
  1645. $this->versionField = $mapping['fieldName'];
  1646. if ( ! isset($mapping['default'])) {
  1647. if ($mapping['type'] == 'integer') {
  1648. $mapping['default'] = 1;
  1649. } else if ($mapping['type'] == 'datetime') {
  1650. $mapping['default'] = 'CURRENT_TIMESTAMP';
  1651. } else {
  1652. throw MappingException::unsupportedOptimisticLockingType($this->name, $mapping['fieldName'], $mapping['type']);
  1653. }
  1654. }
  1655. }
  1656. /**
  1657. * Sets whether this class is to be versioned for optimistic locking.
  1658. *
  1659. * @param boolean $bool
  1660. */
  1661. public function setVersioned($bool)
  1662. {
  1663. $this->isVersioned = $bool;
  1664. }
  1665. /**
  1666. * Sets the name of the field that is to be used for versioning if this class is
  1667. * versioned for optimistic locking.
  1668. *
  1669. * @param string $versionField
  1670. */
  1671. public function setVersionField($versionField)
  1672. {
  1673. $this->versionField = $versionField;
  1674. }
  1675. /**
  1676. * Mark this class as read only, no change tracking is applied to it.
  1677. *
  1678. * @return void
  1679. */
  1680. public function markReadOnly()
  1681. {
  1682. $this->isReadOnly = true;
  1683. }
  1684. /**
  1685. * A numerically indexed list of field names of this persistent class.
  1686. *
  1687. * This array includes identifier fields if present on this class.
  1688. *
  1689. * @return array
  1690. */
  1691. public function getFieldNames()
  1692. {
  1693. return array_keys($this->fieldMappings);
  1694. }
  1695. /**
  1696. * A numerically indexed list of association names of this persistent class.
  1697. *
  1698. * This array includes identifier associations if present on this class.
  1699. *
  1700. * @return array
  1701. */
  1702. public function getAssociationNames()
  1703. {
  1704. return array_keys($this->associationMappings);
  1705. }
  1706. /**
  1707. * Returns the target class name of the given association.
  1708. *
  1709. * @param string $assocName
  1710. * @return string
  1711. */
  1712. public function getAssociationTargetClass($assocName)
  1713. {
  1714. if (!isset($this->associationMappings[$assocName])) {
  1715. throw new \InvalidArgumentException("Association name expected, '" . $assocName ."' is not an association.");
  1716. }
  1717. return $this->associationMappings[$assocName]['targetEntity'];
  1718. }
  1719. /**
  1720. * Get fully-qualified class name of this persistent class.
  1721. *
  1722. * @return string
  1723. */
  1724. public function getName()
  1725. {
  1726. return $this->name;
  1727. }
  1728. /**
  1729. * Gets the (possibly quoted) identifier column names for safe use in an SQL statement.
  1730. *
  1731. * @param AbstractPlatform $platform
  1732. * @return array
  1733. */
  1734. public function getQuotedIdentifierColumnNames($platform)
  1735. {
  1736. $quotedColumnNames = array();
  1737. foreach ($this->identifier as $idProperty) {
  1738. if (isset($this->fieldMappings[$idProperty])) {
  1739. $quotedColumnNames[] = isset($this->fieldMappings[$idProperty]['quoted'])
  1740. ? $platform->quoteIdentifier($this->fieldMappings[$idProperty]['columnName'])
  1741. : $this->fieldMappings[$idProperty]['columnName'];
  1742. continue;
  1743. }
  1744. // Association defined as Id field
  1745. $joinColumns = $this->associationMappings[$idProperty]['joinColumns'];
  1746. $assocQuotedColumnNames = array_map(
  1747. function ($joinColumn) {
  1748. return isset($joinColumn['quoted'])
  1749. ? $platform->quoteIdentifier($joinColumn['name'])
  1750. : $joinColumn['name'];
  1751. },
  1752. $joinColumns
  1753. );
  1754. $quotedColumnNames = array_merge($quotedColumnNames, $assocQuotedColumnNames);
  1755. }
  1756. return $quotedColumnNames;
  1757. }
  1758. /**
  1759. * Gets the (possibly quoted) column name of a mapped field for safe use
  1760. * in an SQL statement.
  1761. *
  1762. * @param string $field
  1763. * @param AbstractPlatform $platform
  1764. * @return string
  1765. */
  1766. public function getQuotedColumnName($field, $platform)
  1767. {
  1768. return isset($this->fieldMappings[$field]['quoted']) ?
  1769. $platform->quoteIdentifier($this->fieldMappings[$field]['columnName']) :
  1770. $this->fieldMappings[$field]['columnName'];
  1771. }
  1772. /**
  1773. * Gets the (possibly quoted) primary table name of this class for safe use
  1774. * in an SQL statement.
  1775. *
  1776. * @param AbstractPlatform $platform
  1777. * @return string
  1778. */
  1779. public function getQuotedTableName($platform)
  1780. {
  1781. return isset($this->table['quoted']) ?
  1782. $platform->quoteIdentifier($this->table['name']) :
  1783. $this->table['name'];
  1784. }
  1785. /**
  1786. * Gets the (possibly quoted) name of the join table.
  1787. *
  1788. * @param AbstractPlatform $platform
  1789. * @return string
  1790. */
  1791. public function getQuotedJoinTableName(array $assoc, $platform)
  1792. {
  1793. return isset($assoc['joinTable']['quoted'])
  1794. ? $platform->quoteIdentifier($assoc['joinTable']['name'])
  1795. : $assoc['joinTable']['name'];
  1796. }
  1797. public function isAssociationInverseSide($fieldName)
  1798. {
  1799. return isset($this->associationMappings[$fieldName]) && !$this->associationMappings[$fieldName]['isOwningSide'];
  1800. }
  1801. public function getAssociationMappedByTargetField($fieldName)
  1802. {
  1803. return $this->associationMappings[$fieldName]['mappedBy'];
  1804. }
  1805. }