ClassMetadataInfo.php 65KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986
  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. if (! isset($mapping['id']) || ! $mapping['id']) {
  814. $joinColumn['unique'] = true;
  815. }
  816. } else {
  817. $uniqueContraintColumns[] = $joinColumn['name'];
  818. }
  819. }
  820. if (empty($joinColumn['name'])) {
  821. $joinColumn['name'] = $mapping['fieldName'] . '_id';
  822. }
  823. if (empty($joinColumn['referencedColumnName'])) {
  824. $joinColumn['referencedColumnName'] = 'id';
  825. }
  826. $mapping['sourceToTargetKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName'];
  827. $mapping['joinColumnFieldNames'][$joinColumn['name']] = isset($joinColumn['fieldName'])
  828. ? $joinColumn['fieldName'] : $joinColumn['name'];
  829. }
  830. if ($uniqueContraintColumns) {
  831. if (!$this->table) {
  832. throw new \RuntimeException("ClassMetadataInfo::setTable() has to be called before defining a one to one relationship.");
  833. }
  834. $this->table['uniqueConstraints'][$mapping['fieldName']."_uniq"] = array(
  835. 'columns' => $uniqueContraintColumns
  836. );
  837. }
  838. $mapping['targetToSourceKeyColumns'] = array_flip($mapping['sourceToTargetKeyColumns']);
  839. }
  840. $mapping['orphanRemoval'] = isset($mapping['orphanRemoval']) ? (bool) $mapping['orphanRemoval'] : false;
  841. $mapping['isCascadeRemove'] = $mapping['orphanRemoval'] ? true : $mapping['isCascadeRemove'];
  842. if (isset($mapping['id']) && $mapping['id'] === true && !$mapping['isOwningSide']) {
  843. throw MappingException::illegalInverseIdentifierAssocation($this->name, $mapping['fieldName']);
  844. }
  845. return $mapping;
  846. }
  847. /**
  848. * Validates and completes the mapping.
  849. *
  850. * @param array $mapping The mapping to validate and complete.
  851. * @return array The validated and completed mapping.
  852. * @override
  853. */
  854. protected function _validateAndCompleteOneToManyMapping(array $mapping)
  855. {
  856. $mapping = $this->_validateAndCompleteAssociationMapping($mapping);
  857. // OneToMany-side MUST be inverse (must have mappedBy)
  858. if ( ! isset($mapping['mappedBy'])) {
  859. throw MappingException::oneToManyRequiresMappedBy($mapping['fieldName']);
  860. }
  861. $mapping['orphanRemoval'] = isset($mapping['orphanRemoval']) ? (bool) $mapping['orphanRemoval'] : false;
  862. $mapping['isCascadeRemove'] = $mapping['orphanRemoval'] ? true : $mapping['isCascadeRemove'];
  863. if (isset($mapping['orderBy'])) {
  864. if ( ! is_array($mapping['orderBy'])) {
  865. throw new \InvalidArgumentException("'orderBy' is expected to be an array, not ".gettype($mapping['orderBy']));
  866. }
  867. }
  868. return $mapping;
  869. }
  870. protected function _validateAndCompleteManyToManyMapping(array $mapping)
  871. {
  872. $mapping = $this->_validateAndCompleteAssociationMapping($mapping);
  873. if ($mapping['isOwningSide']) {
  874. if (strpos($mapping['sourceEntity'], '\\') !== false) {
  875. $sourceShortName = strtolower(substr($mapping['sourceEntity'], strrpos($mapping['sourceEntity'], '\\') + 1));
  876. } else {
  877. $sourceShortName = strtolower($mapping['sourceEntity']);
  878. }
  879. if (strpos($mapping['targetEntity'], '\\') !== false) {
  880. $targetShortName = strtolower(substr($mapping['targetEntity'], strrpos($mapping['targetEntity'], '\\') + 1));
  881. } else {
  882. $targetShortName = strtolower($mapping['targetEntity']);
  883. }
  884. // owning side MUST have a join table
  885. if ( ! isset($mapping['joinTable']['name'])) {
  886. $mapping['joinTable']['name'] = $sourceShortName .'_' . $targetShortName;
  887. }
  888. if ( ! isset($mapping['joinTable']['joinColumns'])) {
  889. $mapping['joinTable']['joinColumns'] = array(array(
  890. 'name' => $sourceShortName . '_id',
  891. 'referencedColumnName' => 'id',
  892. 'onDelete' => 'CASCADE'));
  893. }
  894. if ( ! isset($mapping['joinTable']['inverseJoinColumns'])) {
  895. $mapping['joinTable']['inverseJoinColumns'] = array(array(
  896. 'name' => $targetShortName . '_id',
  897. 'referencedColumnName' => 'id',
  898. 'onDelete' => 'CASCADE'));
  899. }
  900. foreach ($mapping['joinTable']['joinColumns'] as &$joinColumn) {
  901. if (empty($joinColumn['name'])) {
  902. $joinColumn['name'] = $sourceShortName . '_id';
  903. }
  904. if (empty($joinColumn['referencedColumnName'])) {
  905. $joinColumn['referencedColumnName'] = 'id';
  906. }
  907. if (isset($joinColumn['onDelete']) && strtolower($joinColumn['onDelete']) == 'cascade') {
  908. $mapping['isOnDeleteCascade'] = true;
  909. }
  910. $mapping['relationToSourceKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName'];
  911. $mapping['joinTableColumns'][] = $joinColumn['name'];
  912. }
  913. foreach ($mapping['joinTable']['inverseJoinColumns'] as &$inverseJoinColumn) {
  914. if (empty($inverseJoinColumn['name'])) {
  915. $inverseJoinColumn['name'] = $targetShortName . '_id';
  916. }
  917. if (empty($inverseJoinColumn['referencedColumnName'])) {
  918. $inverseJoinColumn['referencedColumnName'] = 'id';
  919. }
  920. if (isset($inverseJoinColumn['onDelete']) && strtolower($inverseJoinColumn['onDelete']) == 'cascade') {
  921. $mapping['isOnDeleteCascade'] = true;
  922. }
  923. $mapping['relationToTargetKeyColumns'][$inverseJoinColumn['name']] = $inverseJoinColumn['referencedColumnName'];
  924. $mapping['joinTableColumns'][] = $inverseJoinColumn['name'];
  925. }
  926. }
  927. if (isset($mapping['orderBy'])) {
  928. if ( ! is_array($mapping['orderBy'])) {
  929. throw new \InvalidArgumentException("'orderBy' is expected to be an array, not ".gettype($mapping['orderBy']));
  930. }
  931. }
  932. return $mapping;
  933. }
  934. /**
  935. * Gets the identifier (primary key) field names of the class.
  936. *
  937. * @return mixed
  938. */
  939. public function getIdentifierFieldNames()
  940. {
  941. return $this->identifier;
  942. }
  943. /**
  944. * Gets the name of the single id field. Note that this only works on
  945. * entity classes that have a single-field pk.
  946. *
  947. * @return string
  948. * @throws MappingException If the class has a composite primary key.
  949. */
  950. public function getSingleIdentifierFieldName()
  951. {
  952. if ($this->isIdentifierComposite) {
  953. throw MappingException::singleIdNotAllowedOnCompositePrimaryKey($this->name);
  954. }
  955. return $this->identifier[0];
  956. }
  957. /**
  958. * Gets the column name of the single id column. Note that this only works on
  959. * entity classes that have a single-field pk.
  960. *
  961. * @return string
  962. * @throws MappingException If the class has a composite primary key.
  963. */
  964. public function getSingleIdentifierColumnName()
  965. {
  966. return $this->getColumnName($this->getSingleIdentifierFieldName());
  967. }
  968. /**
  969. * INTERNAL:
  970. * Sets the mapped identifier/primary key fields of this class.
  971. * Mainly used by the ClassMetadataFactory to assign inherited identifiers.
  972. *
  973. * @param array $identifier
  974. */
  975. public function setIdentifier(array $identifier)
  976. {
  977. $this->identifier = $identifier;
  978. $this->isIdentifierComposite = (count($this->identifier) > 1);
  979. }
  980. /**
  981. * Gets the mapped identifier field of this class.
  982. *
  983. * @return string $identifier
  984. */
  985. public function getIdentifier()
  986. {
  987. return $this->identifier;
  988. }
  989. /**
  990. * Checks whether the class has a (mapped) field with a certain name.
  991. *
  992. * @return boolean
  993. */
  994. public function hasField($fieldName)
  995. {
  996. return isset($this->fieldMappings[$fieldName]);
  997. }
  998. /**
  999. * Gets an array containing all the column names.
  1000. *
  1001. * @return array
  1002. */
  1003. public function getColumnNames(array $fieldNames = null)
  1004. {
  1005. if ($fieldNames === null) {
  1006. return array_keys($this->fieldNames);
  1007. } else {
  1008. $columnNames = array();
  1009. foreach ($fieldNames as $fieldName) {
  1010. $columnNames[] = $this->getColumnName($fieldName);
  1011. }
  1012. return $columnNames;
  1013. }
  1014. }
  1015. /**
  1016. * Returns an array with all the identifier column names.
  1017. *
  1018. * @return array
  1019. */
  1020. public function getIdentifierColumnNames()
  1021. {
  1022. $columnNames = array();
  1023. foreach ($this->identifier as $idProperty) {
  1024. if (isset($this->fieldMappings[$idProperty])) {
  1025. $columnNames[] = $this->fieldMappings[$idProperty]['columnName'];
  1026. continue;
  1027. }
  1028. // Association defined as Id field
  1029. $joinColumns = $this->associationMappings[$idProperty]['joinColumns'];
  1030. $assocColumnNames = array_map(function ($joinColumn) { return $joinColumn['name']; }, $joinColumns);
  1031. $columnNames = array_merge($columnNames, $assocColumnNames);
  1032. }
  1033. return $columnNames;
  1034. }
  1035. /**
  1036. * Sets the type of Id generator to use for the mapped class.
  1037. */
  1038. public function setIdGeneratorType($generatorType)
  1039. {
  1040. $this->generatorType = $generatorType;
  1041. }
  1042. /**
  1043. * Checks whether the mapped class uses an Id generator.
  1044. *
  1045. * @return boolean TRUE if the mapped class uses an Id generator, FALSE otherwise.
  1046. */
  1047. public function usesIdGenerator()
  1048. {
  1049. return $this->generatorType != self::GENERATOR_TYPE_NONE;
  1050. }
  1051. /**
  1052. * @return boolean
  1053. */
  1054. public function isInheritanceTypeNone()
  1055. {
  1056. return $this->inheritanceType == self::INHERITANCE_TYPE_NONE;
  1057. }
  1058. /**
  1059. * Checks whether the mapped class uses the JOINED inheritance mapping strategy.
  1060. *
  1061. * @return boolean TRUE if the class participates in a JOINED inheritance mapping,
  1062. * FALSE otherwise.
  1063. */
  1064. public function isInheritanceTypeJoined()
  1065. {
  1066. return $this->inheritanceType == self::INHERITANCE_TYPE_JOINED;
  1067. }
  1068. /**
  1069. * Checks whether the mapped class uses the SINGLE_TABLE inheritance mapping strategy.
  1070. *
  1071. * @return boolean TRUE if the class participates in a SINGLE_TABLE inheritance mapping,
  1072. * FALSE otherwise.
  1073. */
  1074. public function isInheritanceTypeSingleTable()
  1075. {
  1076. return $this->inheritanceType == self::INHERITANCE_TYPE_SINGLE_TABLE;
  1077. }
  1078. /**
  1079. * Checks whether the mapped class uses the TABLE_PER_CLASS inheritance mapping strategy.
  1080. *
  1081. * @return boolean TRUE if the class participates in a TABLE_PER_CLASS inheritance mapping,
  1082. * FALSE otherwise.
  1083. */
  1084. public function isInheritanceTypeTablePerClass()
  1085. {
  1086. return $this->inheritanceType == self::INHERITANCE_TYPE_TABLE_PER_CLASS;
  1087. }
  1088. /**
  1089. * Checks whether the class uses an identity column for the Id generation.
  1090. *
  1091. * @return boolean TRUE if the class uses the IDENTITY generator, FALSE otherwise.
  1092. */
  1093. public function isIdGeneratorIdentity()
  1094. {
  1095. return $this->generatorType == self::GENERATOR_TYPE_IDENTITY;
  1096. }
  1097. /**
  1098. * Checks whether the class uses a sequence for id generation.
  1099. *
  1100. * @return boolean TRUE if the class uses the SEQUENCE generator, FALSE otherwise.
  1101. */
  1102. public function isIdGeneratorSequence()
  1103. {
  1104. return $this->generatorType == self::GENERATOR_TYPE_SEQUENCE;
  1105. }
  1106. /**
  1107. * Checks whether the class uses a table for id generation.
  1108. *
  1109. * @return boolean TRUE if the class uses the TABLE generator, FALSE otherwise.
  1110. */
  1111. public function isIdGeneratorTable()
  1112. {
  1113. $this->generatorType == self::GENERATOR_TYPE_TABLE;
  1114. }
  1115. /**
  1116. * Checks whether the class has a natural identifier/pk (which means it does
  1117. * not use any Id generator.
  1118. *
  1119. * @return boolean
  1120. */
  1121. public function isIdentifierNatural()
  1122. {
  1123. return $this->generatorType == self::GENERATOR_TYPE_NONE;
  1124. }
  1125. /**
  1126. * Gets the type of a field.
  1127. *
  1128. * @param string $fieldName
  1129. * @return \Doctrine\DBAL\Types\Type
  1130. */
  1131. public function getTypeOfField($fieldName)
  1132. {
  1133. return isset($this->fieldMappings[$fieldName]) ?
  1134. $this->fieldMappings[$fieldName]['type'] : null;
  1135. }
  1136. /**
  1137. * Gets the type of a column.
  1138. *
  1139. * @return \Doctrine\DBAL\Types\Type
  1140. */
  1141. public function getTypeOfColumn($columnName)
  1142. {
  1143. return $this->getTypeOfField($this->getFieldName($columnName));
  1144. }
  1145. /**
  1146. * Gets the name of the primary table.
  1147. *
  1148. * @return string
  1149. */
  1150. public function getTableName()
  1151. {
  1152. return $this->table['name'];
  1153. }
  1154. /**
  1155. * Gets the table name to use for temporary identifier tables of this class.
  1156. *
  1157. * @return string
  1158. */
  1159. public function getTemporaryIdTableName()
  1160. {
  1161. // replace dots with underscores because PostgreSQL creates temporary tables in a special schema
  1162. return str_replace('.', '_', $this->table['name'] . '_id_tmp');
  1163. }
  1164. /**
  1165. * Sets the mapped subclasses of this class.
  1166. *
  1167. * @param array $subclasses The names of all mapped subclasses.
  1168. */
  1169. public function setSubclasses(array $subclasses)
  1170. {
  1171. foreach ($subclasses as $subclass) {
  1172. if (strpos($subclass, '\\') === false && strlen($this->namespace)) {
  1173. $this->subClasses[] = $this->namespace . '\\' . $subclass;
  1174. } else {
  1175. $this->subClasses[] = $subclass;
  1176. }
  1177. }
  1178. }
  1179. /**
  1180. * Sets the parent class names.
  1181. * Assumes that the class names in the passed array are in the order:
  1182. * directParent -> directParentParent -> directParentParentParent ... -> root.
  1183. */
  1184. public function setParentClasses(array $classNames)
  1185. {
  1186. $this->parentClasses = $classNames;
  1187. if (count($classNames) > 0) {
  1188. $this->rootEntityName = array_pop($classNames);
  1189. }
  1190. }
  1191. /**
  1192. * Sets the inheritance type used by the class and it's subclasses.
  1193. *
  1194. * @param integer $type
  1195. */
  1196. public function setInheritanceType($type)
  1197. {
  1198. if ( ! $this->_isInheritanceType($type)) {
  1199. throw MappingException::invalidInheritanceType($this->name, $type);
  1200. }
  1201. $this->inheritanceType = $type;
  1202. }
  1203. /**
  1204. * Checks whether a mapped field is inherited from an entity superclass.
  1205. *
  1206. * @return boolean TRUE if the field is inherited, FALSE otherwise.
  1207. */
  1208. public function isInheritedField($fieldName)
  1209. {
  1210. return isset($this->fieldMappings[$fieldName]['inherited']);
  1211. }
  1212. /**
  1213. * Checks whether a mapped association field is inherited from a superclass.
  1214. *
  1215. * @param string $fieldName
  1216. * @return boolean TRUE if the field is inherited, FALSE otherwise.
  1217. */
  1218. public function isInheritedAssociation($fieldName)
  1219. {
  1220. return isset($this->associationMappings[$fieldName]['inherited']);
  1221. }
  1222. /**
  1223. * Sets the name of the primary table the class is mapped to.
  1224. *
  1225. * @param string $tableName The table name.
  1226. * @deprecated Use {@link setPrimaryTable}.
  1227. */
  1228. public function setTableName($tableName)
  1229. {
  1230. $this->table['name'] = $tableName;
  1231. }
  1232. /**
  1233. * Sets the primary table definition. The provided array supports the
  1234. * following structure:
  1235. *
  1236. * name => <tableName> (optional, defaults to class name)
  1237. * indexes => array of indexes (optional)
  1238. * uniqueConstraints => array of constraints (optional)
  1239. *
  1240. * If a key is omitted, the current value is kept.
  1241. *
  1242. * @param array $table The table description.
  1243. */
  1244. public function setPrimaryTable(array $table)
  1245. {
  1246. if (isset($table['name'])) {
  1247. if ($table['name'][0] == '`') {
  1248. $this->table['name'] = trim($table['name'], '`');
  1249. $this->table['quoted'] = true;
  1250. } else {
  1251. $this->table['name'] = $table['name'];
  1252. }
  1253. }
  1254. if (isset($table['indexes'])) {
  1255. $this->table['indexes'] = $table['indexes'];
  1256. }
  1257. if (isset($table['uniqueConstraints'])) {
  1258. $this->table['uniqueConstraints'] = $table['uniqueConstraints'];
  1259. }
  1260. }
  1261. /**
  1262. * Checks whether the given type identifies an inheritance type.
  1263. *
  1264. * @param integer $type
  1265. * @return boolean TRUE if the given type identifies an inheritance type, FALSe otherwise.
  1266. */
  1267. private function _isInheritanceType($type)
  1268. {
  1269. return $type == self::INHERITANCE_TYPE_NONE ||
  1270. $type == self::INHERITANCE_TYPE_SINGLE_TABLE ||
  1271. $type == self::INHERITANCE_TYPE_JOINED ||
  1272. $type == self::INHERITANCE_TYPE_TABLE_PER_CLASS;
  1273. }
  1274. /**
  1275. * Adds a mapped field to the class.
  1276. *
  1277. * @param array $mapping The field mapping.
  1278. */
  1279. public function mapField(array $mapping)
  1280. {
  1281. $this->_validateAndCompleteFieldMapping($mapping);
  1282. if (isset($this->fieldMappings[$mapping['fieldName']]) || isset($this->associationMappings[$mapping['fieldName']])) {
  1283. throw MappingException::duplicateFieldMapping($this->name, $mapping['fieldName']);
  1284. }
  1285. $this->fieldMappings[$mapping['fieldName']] = $mapping;
  1286. }
  1287. /**
  1288. * INTERNAL:
  1289. * Adds an association mapping without completing/validating it.
  1290. * This is mainly used to add inherited association mappings to derived classes.
  1291. *
  1292. * @param array $mapping
  1293. */
  1294. public function addInheritedAssociationMapping(array $mapping/*, $owningClassName = null*/)
  1295. {
  1296. if (isset($this->associationMappings[$mapping['fieldName']])) {
  1297. throw MappingException::duplicateAssociationMapping($this->name, $mapping['fieldName']);
  1298. }
  1299. $this->associationMappings[$mapping['fieldName']] = $mapping;
  1300. }
  1301. /**
  1302. * INTERNAL:
  1303. * Adds a field mapping without completing/validating it.
  1304. * This is mainly used to add inherited field mappings to derived classes.
  1305. *
  1306. * @param array $mapping
  1307. */
  1308. public function addInheritedFieldMapping(array $fieldMapping)
  1309. {
  1310. $this->fieldMappings[$fieldMapping['fieldName']] = $fieldMapping;
  1311. $this->columnNames[$fieldMapping['fieldName']] = $fieldMapping['columnName'];
  1312. $this->fieldNames[$fieldMapping['columnName']] = $fieldMapping['fieldName'];
  1313. }
  1314. /**
  1315. * INTERNAL:
  1316. * Adds a named query to this class.
  1317. *
  1318. * @throws MappingException
  1319. * @param array $queryMapping
  1320. */
  1321. public function addNamedQuery(array $queryMapping)
  1322. {
  1323. if (isset($this->namedQueries[$queryMapping['name']])) {
  1324. throw MappingException::duplicateQueryMapping($this->name, $queryMapping['name']);
  1325. }
  1326. $query = str_replace('__CLASS__', $this->name, $queryMapping['query']);
  1327. $this->namedQueries[$queryMapping['name']] = $query;
  1328. }
  1329. /**
  1330. * Adds a one-to-one mapping.
  1331. *
  1332. * @param array $mapping The mapping.
  1333. */
  1334. public function mapOneToOne(array $mapping)
  1335. {
  1336. $mapping['type'] = self::ONE_TO_ONE;
  1337. $mapping = $this->_validateAndCompleteOneToOneMapping($mapping);
  1338. $this->_storeAssociationMapping($mapping);
  1339. }
  1340. /**
  1341. * Adds a one-to-many mapping.
  1342. *
  1343. * @param array $mapping The mapping.
  1344. */
  1345. public function mapOneToMany(array $mapping)
  1346. {
  1347. $mapping['type'] = self::ONE_TO_MANY;
  1348. $mapping = $this->_validateAndCompleteOneToManyMapping($mapping);
  1349. $this->_storeAssociationMapping($mapping);
  1350. }
  1351. /**
  1352. * Adds a many-to-one mapping.
  1353. *
  1354. * @param array $mapping The mapping.
  1355. */
  1356. public function mapManyToOne(array $mapping)
  1357. {
  1358. $mapping['type'] = self::MANY_TO_ONE;
  1359. // A many-to-one mapping is essentially a one-one backreference
  1360. $mapping = $this->_validateAndCompleteOneToOneMapping($mapping);
  1361. $this->_storeAssociationMapping($mapping);
  1362. }
  1363. /**
  1364. * Adds a many-to-many mapping.
  1365. *
  1366. * @param array $mapping The mapping.
  1367. */
  1368. public function mapManyToMany(array $mapping)
  1369. {
  1370. $mapping['type'] = self::MANY_TO_MANY;
  1371. $mapping = $this->_validateAndCompleteManyToManyMapping($mapping);
  1372. $this->_storeAssociationMapping($mapping);
  1373. }
  1374. /**
  1375. * Stores the association mapping.
  1376. *
  1377. * @param AssociationMapping $assocMapping
  1378. */
  1379. protected function _storeAssociationMapping(array $assocMapping)
  1380. {
  1381. $sourceFieldName = $assocMapping['fieldName'];
  1382. if (isset($this->fieldMappings[$sourceFieldName]) || isset($this->associationMappings[$sourceFieldName])) {
  1383. throw MappingException::duplicateFieldMapping($this->name, $sourceFieldName);
  1384. }
  1385. $this->associationMappings[$sourceFieldName] = $assocMapping;
  1386. }
  1387. /**
  1388. * Registers a custom repository class for the entity class.
  1389. *
  1390. * @param string $mapperClassName The class name of the custom mapper.
  1391. */
  1392. public function setCustomRepositoryClass($repositoryClassName)
  1393. {
  1394. $this->customRepositoryClassName = $repositoryClassName;
  1395. }
  1396. /**
  1397. * Dispatches the lifecycle event of the given entity to the registered
  1398. * lifecycle callbacks and lifecycle listeners.
  1399. *
  1400. * @param string $event The lifecycle event.
  1401. * @param Entity $entity The Entity on which the event occured.
  1402. */
  1403. public function invokeLifecycleCallbacks($lifecycleEvent, $entity)
  1404. {
  1405. foreach ($this->lifecycleCallbacks[$lifecycleEvent] as $callback) {
  1406. $entity->$callback();
  1407. }
  1408. }
  1409. /**
  1410. * Whether the class has any attached lifecycle listeners or callbacks for a lifecycle event.
  1411. *
  1412. * @param string $lifecycleEvent
  1413. * @return boolean
  1414. */
  1415. public function hasLifecycleCallbacks($lifecycleEvent)
  1416. {
  1417. return isset($this->lifecycleCallbacks[$lifecycleEvent]);
  1418. }
  1419. /**
  1420. * Gets the registered lifecycle callbacks for an event.
  1421. *
  1422. * @param string $event
  1423. * @return array
  1424. */
  1425. public function getLifecycleCallbacks($event)
  1426. {
  1427. return isset($this->lifecycleCallbacks[$event]) ? $this->lifecycleCallbacks[$event] : array();
  1428. }
  1429. /**
  1430. * Adds a lifecycle callback for entities of this class.
  1431. *
  1432. * Note: If the same callback is registered more than once, the old one
  1433. * will be overridden.
  1434. *
  1435. * @param string $callback
  1436. * @param string $event
  1437. */
  1438. public function addLifecycleCallback($callback, $event)
  1439. {
  1440. $this->lifecycleCallbacks[$event][] = $callback;
  1441. }
  1442. /**
  1443. * Sets the lifecycle callbacks for entities of this class.
  1444. * Any previously registered callbacks are overwritten.
  1445. *
  1446. * @param array $callbacks
  1447. */
  1448. public function setLifecycleCallbacks(array $callbacks)
  1449. {
  1450. $this->lifecycleCallbacks = $callbacks;
  1451. }
  1452. /**
  1453. * Sets the discriminator column definition.
  1454. *
  1455. * @param array $columnDef
  1456. * @see getDiscriminatorColumn()
  1457. */
  1458. public function setDiscriminatorColumn($columnDef)
  1459. {
  1460. if ($columnDef !== null) {
  1461. if (isset($this->fieldNames[$columnDef['name']])) {
  1462. throw MappingException::duplicateColumnName($this->name, $columnDef['name']);
  1463. }
  1464. if ( ! isset($columnDef['name'])) {
  1465. throw MappingException::nameIsMandatoryForDiscriminatorColumns($this->name, $columnDef);
  1466. }
  1467. if ( ! isset($columnDef['fieldName'])) {
  1468. $columnDef['fieldName'] = $columnDef['name'];
  1469. }
  1470. if ( ! isset($columnDef['type'])) {
  1471. $columnDef['type'] = "string";
  1472. }
  1473. if (in_array($columnDef['type'], array("boolean", "array", "object", "datetime", "time", "date"))) {
  1474. throw MappingException::invalidDiscriminatorColumnType($this->name, $columnDef['type']);
  1475. }
  1476. $this->discriminatorColumn = $columnDef;
  1477. }
  1478. }
  1479. /**
  1480. * Sets the discriminator values used by this class.
  1481. * Used for JOINED and SINGLE_TABLE inheritance mapping strategies.
  1482. *
  1483. * @param array $map
  1484. */
  1485. public function setDiscriminatorMap(array $map)
  1486. {
  1487. foreach ($map as $value => $className) {
  1488. if (strlen($this->namespace) > 0 && strpos($className, '\\') === false) {
  1489. $className = $this->namespace . '\\' . $className;
  1490. }
  1491. $className = ltrim($className, '\\');
  1492. $this->discriminatorMap[$value] = $className;
  1493. if ($this->name == $className) {
  1494. $this->discriminatorValue = $value;
  1495. } else {
  1496. if ( ! class_exists($className)) {
  1497. throw MappingException::invalidClassInDiscriminatorMap($className, $this->name);
  1498. }
  1499. if (is_subclass_of($className, $this->name) && ! in_array($className, $this->subClasses)) {
  1500. $this->subClasses[] = $className;
  1501. }
  1502. }
  1503. }
  1504. }
  1505. /**
  1506. * Checks whether the class has a named query with the given query name.
  1507. *
  1508. * @param string $fieldName
  1509. * @return boolean
  1510. */
  1511. public function hasNamedQuery($queryName)
  1512. {
  1513. return isset($this->namedQueries[$queryName]);
  1514. }
  1515. /**
  1516. * Checks whether the class has a mapped association with the given field name.
  1517. *
  1518. * @param string $fieldName
  1519. * @return boolean
  1520. */
  1521. public function hasAssociation($fieldName)
  1522. {
  1523. return isset($this->associationMappings[$fieldName]);
  1524. }
  1525. /**
  1526. * Checks whether the class has a mapped association for the specified field
  1527. * and if yes, checks whether it is a single-valued association (to-one).
  1528. *
  1529. * @param string $fieldName
  1530. * @return boolean TRUE if the association exists and is single-valued, FALSE otherwise.
  1531. */
  1532. public function isSingleValuedAssociation($fieldName)
  1533. {
  1534. return isset($this->associationMappings[$fieldName]) &&
  1535. ($this->associationMappings[$fieldName]['type'] & self::TO_ONE);
  1536. }
  1537. /**
  1538. * Checks whether the class has a mapped association for the specified field
  1539. * and if yes, checks whether it is a collection-valued association (to-many).
  1540. *
  1541. * @param string $fieldName
  1542. * @return boolean TRUE if the association exists and is collection-valued, FALSE otherwise.
  1543. */
  1544. public function isCollectionValuedAssociation($fieldName)
  1545. {
  1546. return isset($this->associationMappings[$fieldName]) &&
  1547. ! ($this->associationMappings[$fieldName]['type'] & self::TO_ONE);
  1548. }
  1549. /**
  1550. * Is this an association that only has a single join column?
  1551. *
  1552. * @param string $fieldName
  1553. * @return bool
  1554. */
  1555. public function isAssociationWithSingleJoinColumn($fieldName)
  1556. {
  1557. return (
  1558. isset($this->associationMappings[$fieldName]) &&
  1559. isset($this->associationMappings[$fieldName]['joinColumns'][0]) &&
  1560. !isset($this->associationMappings[$fieldName]['joinColumns'][1])
  1561. );
  1562. }
  1563. /**
  1564. * Return the single association join column (if any).
  1565. *
  1566. * @param string $fieldName
  1567. * @return string
  1568. */
  1569. public function getSingleAssociationJoinColumnName($fieldName)
  1570. {
  1571. if (!$this->isAssociationWithSingleJoinColumn($fieldName)) {
  1572. throw MappingException::noSingleAssociationJoinColumnFound($this->name, $fieldName);
  1573. }
  1574. return $this->associationMappings[$fieldName]['joinColumns'][0]['name'];
  1575. }
  1576. /**
  1577. * Return the single association referenced join column name (if any).
  1578. *
  1579. * @param string $fieldName
  1580. * @return string
  1581. */
  1582. public function getSingleAssociationReferencedJoinColumnName($fieldName)
  1583. {
  1584. if (!$this->isAssociationWithSingleJoinColumn($fieldName)) {
  1585. throw MappingException::noSingleAssociationJoinColumnFound($this->name, $fieldName);
  1586. }
  1587. return $this->associationMappings[$fieldName]['joinColumns'][0]['referencedColumnName'];
  1588. }
  1589. /**
  1590. * Used to retrieve a fieldname for either field or association from a given column,
  1591. *
  1592. * This method is used in foreign-key as primary-key contexts.
  1593. *
  1594. * @param string $columnName
  1595. * @return string
  1596. */
  1597. public function getFieldForColumn($columnName)
  1598. {
  1599. if (isset($this->fieldNames[$columnName])) {
  1600. return $this->fieldNames[$columnName];
  1601. } else {
  1602. foreach ($this->associationMappings AS $assocName => $mapping) {
  1603. if ($this->isAssociationWithSingleJoinColumn($assocName) &&
  1604. $this->associationMappings[$assocName]['joinColumns'][0]['name'] == $columnName) {
  1605. return $assocName;
  1606. }
  1607. }
  1608. throw MappingException::noFieldNameFoundForColumn($this->name, $columnName);
  1609. }
  1610. }
  1611. /**
  1612. * Sets the ID generator used to generate IDs for instances of this class.
  1613. *
  1614. * @param AbstractIdGenerator $generator
  1615. */
  1616. public function setIdGenerator($generator)
  1617. {
  1618. $this->idGenerator = $generator;
  1619. }
  1620. /**
  1621. * Sets the definition of the sequence ID generator for this class.
  1622. *
  1623. * The definition must have the following structure:
  1624. * <code>
  1625. * array(
  1626. * 'sequenceName' => 'name',
  1627. * 'allocationSize' => 20,
  1628. * 'initialValue' => 1
  1629. * )
  1630. * </code>
  1631. *
  1632. * @param array $definition
  1633. */
  1634. public function setSequenceGeneratorDefinition(array $definition)
  1635. {
  1636. $this->sequenceGeneratorDefinition = $definition;
  1637. }
  1638. /**
  1639. * Sets the version field mapping used for versioning. Sets the default
  1640. * value to use depending on the column type.
  1641. *
  1642. * @param array $mapping The version field mapping array
  1643. */
  1644. public function setVersionMapping(array &$mapping)
  1645. {
  1646. $this->isVersioned = true;
  1647. $this->versionField = $mapping['fieldName'];
  1648. if ( ! isset($mapping['default'])) {
  1649. if ($mapping['type'] == 'integer') {
  1650. $mapping['default'] = 1;
  1651. } else if ($mapping['type'] == 'datetime') {
  1652. $mapping['default'] = 'CURRENT_TIMESTAMP';
  1653. } else {
  1654. throw MappingException::unsupportedOptimisticLockingType($this->name, $mapping['fieldName'], $mapping['type']);
  1655. }
  1656. }
  1657. }
  1658. /**
  1659. * Sets whether this class is to be versioned for optimistic locking.
  1660. *
  1661. * @param boolean $bool
  1662. */
  1663. public function setVersioned($bool)
  1664. {
  1665. $this->isVersioned = $bool;
  1666. }
  1667. /**
  1668. * Sets the name of the field that is to be used for versioning if this class is
  1669. * versioned for optimistic locking.
  1670. *
  1671. * @param string $versionField
  1672. */
  1673. public function setVersionField($versionField)
  1674. {
  1675. $this->versionField = $versionField;
  1676. }
  1677. /**
  1678. * Mark this class as read only, no change tracking is applied to it.
  1679. *
  1680. * @return void
  1681. */
  1682. public function markReadOnly()
  1683. {
  1684. $this->isReadOnly = true;
  1685. }
  1686. /**
  1687. * A numerically indexed list of field names of this persistent class.
  1688. *
  1689. * This array includes identifier fields if present on this class.
  1690. *
  1691. * @return array
  1692. */
  1693. public function getFieldNames()
  1694. {
  1695. return array_keys($this->fieldMappings);
  1696. }
  1697. /**
  1698. * A numerically indexed list of association names of this persistent class.
  1699. *
  1700. * This array includes identifier associations if present on this class.
  1701. *
  1702. * @return array
  1703. */
  1704. public function getAssociationNames()
  1705. {
  1706. return array_keys($this->associationMappings);
  1707. }
  1708. /**
  1709. * Returns the target class name of the given association.
  1710. *
  1711. * @param string $assocName
  1712. * @return string
  1713. */
  1714. public function getAssociationTargetClass($assocName)
  1715. {
  1716. if (!isset($this->associationMappings[$assocName])) {
  1717. throw new \InvalidArgumentException("Association name expected, '" . $assocName ."' is not an association.");
  1718. }
  1719. return $this->associationMappings[$assocName]['targetEntity'];
  1720. }
  1721. /**
  1722. * Get fully-qualified class name of this persistent class.
  1723. *
  1724. * @return string
  1725. */
  1726. public function getName()
  1727. {
  1728. return $this->name;
  1729. }
  1730. /**
  1731. * Gets the (possibly quoted) identifier column names for safe use in an SQL statement.
  1732. *
  1733. * @param AbstractPlatform $platform
  1734. * @return array
  1735. */
  1736. public function getQuotedIdentifierColumnNames($platform)
  1737. {
  1738. $quotedColumnNames = array();
  1739. foreach ($this->identifier as $idProperty) {
  1740. if (isset($this->fieldMappings[$idProperty])) {
  1741. $quotedColumnNames[] = isset($this->fieldMappings[$idProperty]['quoted'])
  1742. ? $platform->quoteIdentifier($this->fieldMappings[$idProperty]['columnName'])
  1743. : $this->fieldMappings[$idProperty]['columnName'];
  1744. continue;
  1745. }
  1746. // Association defined as Id field
  1747. $joinColumns = $this->associationMappings[$idProperty]['joinColumns'];
  1748. $assocQuotedColumnNames = array_map(
  1749. function ($joinColumn) {
  1750. return isset($joinColumn['quoted'])
  1751. ? $platform->quoteIdentifier($joinColumn['name'])
  1752. : $joinColumn['name'];
  1753. },
  1754. $joinColumns
  1755. );
  1756. $quotedColumnNames = array_merge($quotedColumnNames, $assocQuotedColumnNames);
  1757. }
  1758. return $quotedColumnNames;
  1759. }
  1760. /**
  1761. * Gets the (possibly quoted) column name of a mapped field for safe use
  1762. * in an SQL statement.
  1763. *
  1764. * @param string $field
  1765. * @param AbstractPlatform $platform
  1766. * @return string
  1767. */
  1768. public function getQuotedColumnName($field, $platform)
  1769. {
  1770. return isset($this->fieldMappings[$field]['quoted']) ?
  1771. $platform->quoteIdentifier($this->fieldMappings[$field]['columnName']) :
  1772. $this->fieldMappings[$field]['columnName'];
  1773. }
  1774. /**
  1775. * Gets the (possibly quoted) primary table name of this class for safe use
  1776. * in an SQL statement.
  1777. *
  1778. * @param AbstractPlatform $platform
  1779. * @return string
  1780. */
  1781. public function getQuotedTableName($platform)
  1782. {
  1783. return isset($this->table['quoted']) ?
  1784. $platform->quoteIdentifier($this->table['name']) :
  1785. $this->table['name'];
  1786. }
  1787. /**
  1788. * Gets the (possibly quoted) name of the join table.
  1789. *
  1790. * @param AbstractPlatform $platform
  1791. * @return string
  1792. */
  1793. public function getQuotedJoinTableName(array $assoc, $platform)
  1794. {
  1795. return isset($assoc['joinTable']['quoted'])
  1796. ? $platform->quoteIdentifier($assoc['joinTable']['name'])
  1797. : $assoc['joinTable']['name'];
  1798. }
  1799. public function isAssociationInverseSide($fieldName)
  1800. {
  1801. return isset($this->associationMappings[$fieldName]) && !$this->associationMappings[$fieldName]['isOwningSide'];
  1802. }
  1803. public function getAssociationMappedByTargetField($fieldName)
  1804. {
  1805. return $this->associationMappings[$fieldName]['mappedBy'];
  1806. }
  1807. }