Complex classes like ClassMetadataInfo often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ClassMetadataInfo, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
51 | class ClassMetadataInfo implements ClassMetadata |
||
52 | { |
||
53 | /* The inheritance mapping types */ |
||
54 | /** |
||
55 | * NONE means the class does not participate in an inheritance hierarchy |
||
56 | * and therefore does not need an inheritance mapping type. |
||
57 | */ |
||
58 | const INHERITANCE_TYPE_NONE = 1; |
||
59 | |||
60 | /** |
||
61 | * JOINED means the class will be persisted according to the rules of |
||
62 | * <tt>Class Table Inheritance</tt>. |
||
63 | */ |
||
64 | const INHERITANCE_TYPE_JOINED = 2; |
||
65 | |||
66 | /** |
||
67 | * SINGLE_TABLE means the class will be persisted according to the rules of |
||
68 | * <tt>Single Table Inheritance</tt>. |
||
69 | */ |
||
70 | const INHERITANCE_TYPE_SINGLE_TABLE = 3; |
||
71 | |||
72 | /** |
||
73 | * TABLE_PER_CLASS means the class will be persisted according to the rules |
||
74 | * of <tt>Concrete Table Inheritance</tt>. |
||
75 | */ |
||
76 | const INHERITANCE_TYPE_TABLE_PER_CLASS = 4; |
||
77 | |||
78 | /* The Id generator types. */ |
||
79 | /** |
||
80 | * AUTO means the generator type will depend on what the used platform prefers. |
||
81 | * Offers full portability. |
||
82 | */ |
||
83 | const GENERATOR_TYPE_AUTO = 1; |
||
84 | |||
85 | /** |
||
86 | * SEQUENCE means a separate sequence object will be used. Platforms that do |
||
87 | * not have native sequence support may emulate it. Full portability is currently |
||
88 | * not guaranteed. |
||
89 | */ |
||
90 | const GENERATOR_TYPE_SEQUENCE = 2; |
||
91 | |||
92 | /** |
||
93 | * TABLE means a separate table is used for id generation. |
||
94 | * Offers full portability. |
||
95 | */ |
||
96 | const GENERATOR_TYPE_TABLE = 3; |
||
97 | |||
98 | /** |
||
99 | * IDENTITY means an identity column is used for id generation. The database |
||
100 | * will fill in the id column on insertion. Platforms that do not support |
||
101 | * native identity columns may emulate them. Full portability is currently |
||
102 | * not guaranteed. |
||
103 | */ |
||
104 | const GENERATOR_TYPE_IDENTITY = 4; |
||
105 | |||
106 | /** |
||
107 | * NONE means the class does not have a generated id. That means the class |
||
108 | * must have a natural, manually assigned id. |
||
109 | */ |
||
110 | const GENERATOR_TYPE_NONE = 5; |
||
111 | |||
112 | /** |
||
113 | * UUID means that a UUID/GUID expression is used for id generation. Full |
||
114 | * portability is currently not guaranteed. |
||
115 | */ |
||
116 | const GENERATOR_TYPE_UUID = 6; |
||
117 | |||
118 | /** |
||
119 | * CUSTOM means that customer will use own ID generator that supposedly work |
||
120 | */ |
||
121 | const GENERATOR_TYPE_CUSTOM = 7; |
||
122 | |||
123 | /** |
||
124 | * DEFERRED_IMPLICIT means that changes of entities are calculated at commit-time |
||
125 | * by doing a property-by-property comparison with the original data. This will |
||
126 | * be done for all entities that are in MANAGED state at commit-time. |
||
127 | * |
||
128 | * This is the default change tracking policy. |
||
129 | */ |
||
130 | const CHANGETRACKING_DEFERRED_IMPLICIT = 1; |
||
131 | |||
132 | /** |
||
133 | * DEFERRED_EXPLICIT means that changes of entities are calculated at commit-time |
||
134 | * by doing a property-by-property comparison with the original data. This will |
||
135 | * be done only for entities that were explicitly saved (through persist() or a cascade). |
||
136 | */ |
||
137 | const CHANGETRACKING_DEFERRED_EXPLICIT = 2; |
||
138 | |||
139 | /** |
||
140 | * NOTIFY means that Doctrine relies on the entities sending out notifications |
||
141 | * when their properties change. Such entity classes must implement |
||
142 | * the <tt>NotifyPropertyChanged</tt> interface. |
||
143 | */ |
||
144 | const CHANGETRACKING_NOTIFY = 3; |
||
145 | |||
146 | /** |
||
147 | * Specifies that an association is to be fetched when it is first accessed. |
||
148 | */ |
||
149 | const FETCH_LAZY = 2; |
||
150 | |||
151 | /** |
||
152 | * Specifies that an association is to be fetched when the owner of the |
||
153 | * association is fetched. |
||
154 | */ |
||
155 | const FETCH_EAGER = 3; |
||
156 | |||
157 | /** |
||
158 | * Specifies that an association is to be fetched lazy (on first access) and that |
||
159 | * commands such as Collection#count, Collection#slice are issued directly against |
||
160 | * the database if the collection is not yet initialized. |
||
161 | */ |
||
162 | const FETCH_EXTRA_LAZY = 4; |
||
163 | |||
164 | /** |
||
165 | * Identifies a one-to-one association. |
||
166 | */ |
||
167 | const ONE_TO_ONE = 1; |
||
168 | |||
169 | /** |
||
170 | * Identifies a many-to-one association. |
||
171 | */ |
||
172 | const MANY_TO_ONE = 2; |
||
173 | |||
174 | /** |
||
175 | * Identifies a one-to-many association. |
||
176 | */ |
||
177 | const ONE_TO_MANY = 4; |
||
178 | |||
179 | /** |
||
180 | * Identifies a many-to-many association. |
||
181 | */ |
||
182 | const MANY_TO_MANY = 8; |
||
183 | |||
184 | /** |
||
185 | * Combined bitmask for to-one (single-valued) associations. |
||
186 | */ |
||
187 | const TO_ONE = 3; |
||
188 | |||
189 | /** |
||
190 | * Combined bitmask for to-many (collection-valued) associations. |
||
191 | */ |
||
192 | const TO_MANY = 12; |
||
193 | |||
194 | /** |
||
195 | * ReadOnly cache can do reads, inserts and deletes, cannot perform updates or employ any locks, |
||
196 | */ |
||
197 | const CACHE_USAGE_READ_ONLY = 1; |
||
198 | |||
199 | /** |
||
200 | * Nonstrict Read Write Cache doesn’t employ any locks but can do inserts, update and deletes. |
||
201 | */ |
||
202 | const CACHE_USAGE_NONSTRICT_READ_WRITE = 2; |
||
203 | |||
204 | /** |
||
205 | * Read Write Attempts to lock the entity before update/delete. |
||
206 | */ |
||
207 | const CACHE_USAGE_READ_WRITE = 3; |
||
208 | |||
209 | /** |
||
210 | * READ-ONLY: The name of the entity class. |
||
211 | * |
||
212 | * @var string |
||
213 | */ |
||
214 | public $name; |
||
215 | |||
216 | /** |
||
217 | * READ-ONLY: The namespace the entity class is contained in. |
||
218 | * |
||
219 | * @var string |
||
220 | * |
||
221 | * @todo Not really needed. Usage could be localized. |
||
222 | */ |
||
223 | public $namespace; |
||
224 | |||
225 | /** |
||
226 | * READ-ONLY: The name of the entity class that is at the root of the mapped entity inheritance |
||
227 | * hierarchy. If the entity is not part of a mapped inheritance hierarchy this is the same |
||
228 | * as {@link $name}. |
||
229 | * |
||
230 | * @var string |
||
231 | */ |
||
232 | public $rootEntityName; |
||
233 | |||
234 | /** |
||
235 | * READ-ONLY: The definition of custom generator. Only used for CUSTOM |
||
236 | * generator type |
||
237 | * |
||
238 | * The definition has the following structure: |
||
239 | * <code> |
||
240 | * array( |
||
241 | * 'class' => 'ClassName', |
||
242 | * ) |
||
243 | * </code> |
||
244 | * |
||
245 | * @var array |
||
246 | * |
||
247 | * @todo Merge with tableGeneratorDefinition into generic generatorDefinition |
||
248 | */ |
||
249 | public $customGeneratorDefinition; |
||
250 | |||
251 | /** |
||
252 | * The name of the custom repository class used for the entity class. |
||
253 | * (Optional). |
||
254 | * |
||
255 | * @var string |
||
256 | */ |
||
257 | public $customRepositoryClassName; |
||
258 | |||
259 | /** |
||
260 | * READ-ONLY: Whether this class describes the mapping of a mapped superclass. |
||
261 | * |
||
262 | * @var boolean |
||
263 | */ |
||
264 | public $isMappedSuperclass = false; |
||
265 | |||
266 | /** |
||
267 | * READ-ONLY: Whether this class describes the mapping of an embeddable class. |
||
268 | * |
||
269 | * @var boolean |
||
270 | */ |
||
271 | public $isEmbeddedClass = false; |
||
272 | |||
273 | /** |
||
274 | * READ-ONLY: The names of the parent classes (ancestors). |
||
275 | * |
||
276 | * @var array |
||
277 | */ |
||
278 | public $parentClasses = array(); |
||
279 | |||
280 | /** |
||
281 | * READ-ONLY: The names of all subclasses (descendants). |
||
282 | * |
||
283 | * @var array |
||
284 | */ |
||
285 | public $subClasses = array(); |
||
286 | |||
287 | /** |
||
288 | * READ-ONLY: The names of all embedded classes based on properties. |
||
289 | * |
||
290 | * @var array |
||
291 | */ |
||
292 | public $embeddedClasses = array(); |
||
293 | |||
294 | /** |
||
295 | * READ-ONLY: The named queries allowed to be called directly from Repository. |
||
296 | * |
||
297 | * @var array |
||
298 | */ |
||
299 | public $namedQueries = array(); |
||
300 | |||
301 | /** |
||
302 | * READ-ONLY: The named native queries allowed to be called directly from Repository. |
||
303 | * |
||
304 | * A native SQL named query definition has the following structure: |
||
305 | * <pre> |
||
306 | * array( |
||
307 | * 'name' => <query name>, |
||
308 | * 'query' => <sql query>, |
||
309 | * 'resultClass' => <class of the result>, |
||
310 | * 'resultSetMapping' => <name of a SqlResultSetMapping> |
||
311 | * ) |
||
312 | * </pre> |
||
313 | * |
||
314 | * @var array |
||
315 | */ |
||
316 | public $namedNativeQueries = array(); |
||
317 | |||
318 | /** |
||
319 | * READ-ONLY: The mappings of the results of native SQL queries. |
||
320 | * |
||
321 | * A native result mapping definition has the following structure: |
||
322 | * <pre> |
||
323 | * array( |
||
324 | * 'name' => <result name>, |
||
325 | * 'entities' => array(<entity result mapping>), |
||
326 | * 'columns' => array(<column result mapping>) |
||
327 | * ) |
||
328 | * </pre> |
||
329 | * |
||
330 | * @var array |
||
331 | */ |
||
332 | public $sqlResultSetMappings = array(); |
||
333 | |||
334 | /** |
||
335 | * READ-ONLY: The field names of all fields that are part of the identifier/primary key |
||
336 | * of the mapped entity class. |
||
337 | * |
||
338 | * @var array |
||
339 | */ |
||
340 | public $identifier = array(); |
||
341 | |||
342 | /** |
||
343 | * READ-ONLY: The inheritance mapping type used by the class. |
||
344 | * |
||
345 | * @var integer |
||
346 | */ |
||
347 | public $inheritanceType = self::INHERITANCE_TYPE_NONE; |
||
348 | |||
349 | /** |
||
350 | * READ-ONLY: The Id generator type used by the class. |
||
351 | * |
||
352 | * @var int |
||
353 | */ |
||
354 | public $generatorType = self::GENERATOR_TYPE_NONE; |
||
355 | |||
356 | /** |
||
357 | * READ-ONLY: The field mappings of the class. |
||
358 | * Keys are field names and values are mapping definitions. |
||
359 | * |
||
360 | * The mapping definition array has the following values: |
||
361 | * |
||
362 | * - <b>fieldName</b> (string) |
||
363 | * The name of the field in the Entity. |
||
364 | * |
||
365 | * - <b>type</b> (string) |
||
366 | * The type name of the mapped field. Can be one of Doctrine's mapping types |
||
367 | * or a custom mapping type. |
||
368 | * |
||
369 | * - <b>columnName</b> (string, optional) |
||
370 | * The column name. Optional. Defaults to the field name. |
||
371 | * |
||
372 | * - <b>length</b> (integer, optional) |
||
373 | * The database length of the column. Optional. Default value taken from |
||
374 | * the type. |
||
375 | * |
||
376 | * - <b>id</b> (boolean, optional) |
||
377 | * Marks the field as the primary key of the entity. Multiple fields of an |
||
378 | * entity can have the id attribute, forming a composite key. |
||
379 | * |
||
380 | * - <b>nullable</b> (boolean, optional) |
||
381 | * Whether the column is nullable. Defaults to FALSE. |
||
382 | * |
||
383 | * - <b>columnDefinition</b> (string, optional, schema-only) |
||
384 | * The SQL fragment that is used when generating the DDL for the column. |
||
385 | * |
||
386 | * - <b>precision</b> (integer, optional, schema-only) |
||
387 | * The precision of a decimal column. Only valid if the column type is decimal. |
||
388 | * |
||
389 | * - <b>scale</b> (integer, optional, schema-only) |
||
390 | * The scale of a decimal column. Only valid if the column type is decimal. |
||
391 | * |
||
392 | * - <b>'unique'</b> (string, optional, schema-only) |
||
393 | * Whether a unique constraint should be generated for the column. |
||
394 | * |
||
395 | * @var array |
||
396 | */ |
||
397 | public $fieldMappings = array(); |
||
398 | |||
399 | /** |
||
400 | * READ-ONLY: An array of field names. Used to look up field names from column names. |
||
401 | * Keys are column names and values are field names. |
||
402 | * |
||
403 | * @var array |
||
404 | */ |
||
405 | public $fieldNames = array(); |
||
406 | |||
407 | /** |
||
408 | * READ-ONLY: A map of field names to column names. Keys are field names and values column names. |
||
409 | * Used to look up column names from field names. |
||
410 | * This is the reverse lookup map of $_fieldNames. |
||
411 | * |
||
412 | * @var array |
||
413 | * |
||
414 | * @deprecated 3.0 Remove this. |
||
415 | */ |
||
416 | public $columnNames = array(); |
||
417 | |||
418 | /** |
||
419 | * READ-ONLY: The discriminator value of this class. |
||
420 | * |
||
421 | * <b>This does only apply to the JOINED and SINGLE_TABLE inheritance mapping strategies |
||
422 | * where a discriminator column is used.</b> |
||
423 | * |
||
424 | * @var mixed |
||
425 | * |
||
426 | * @see discriminatorColumn |
||
427 | */ |
||
428 | public $discriminatorValue; |
||
429 | |||
430 | /** |
||
431 | * READ-ONLY: The discriminator map of all mapped classes in the hierarchy. |
||
432 | * |
||
433 | * <b>This does only apply to the JOINED and SINGLE_TABLE inheritance mapping strategies |
||
434 | * where a discriminator column is used.</b> |
||
435 | * |
||
436 | * @var mixed |
||
437 | * |
||
438 | * @see discriminatorColumn |
||
439 | */ |
||
440 | public $discriminatorMap = array(); |
||
441 | |||
442 | /** |
||
443 | * READ-ONLY: The definition of the discriminator column used in JOINED and SINGLE_TABLE |
||
444 | * inheritance mappings. |
||
445 | * |
||
446 | * @var array |
||
447 | */ |
||
448 | public $discriminatorColumn; |
||
449 | |||
450 | /** |
||
451 | * READ-ONLY: The primary table definition. The definition is an array with the |
||
452 | * following entries: |
||
453 | * |
||
454 | * name => <tableName> |
||
455 | * schema => <schemaName> |
||
456 | * indexes => array |
||
457 | * uniqueConstraints => array |
||
458 | * |
||
459 | * @var array |
||
460 | */ |
||
461 | public $table; |
||
462 | |||
463 | /** |
||
464 | * READ-ONLY: The registered lifecycle callbacks for entities of this class. |
||
465 | * |
||
466 | * @var array |
||
467 | */ |
||
468 | public $lifecycleCallbacks = array(); |
||
469 | |||
470 | /** |
||
471 | * READ-ONLY: The registered entity listeners. |
||
472 | * |
||
473 | * @var array |
||
474 | */ |
||
475 | public $entityListeners = array(); |
||
476 | |||
477 | /** |
||
478 | * READ-ONLY: The association mappings of this class. |
||
479 | * |
||
480 | * The mapping definition array supports the following keys: |
||
481 | * |
||
482 | * - <b>fieldName</b> (string) |
||
483 | * The name of the field in the entity the association is mapped to. |
||
484 | * |
||
485 | * - <b>targetEntity</b> (string) |
||
486 | * The class name of the target entity. If it is fully-qualified it is used as is. |
||
487 | * If it is a simple, unqualified class name the namespace is assumed to be the same |
||
488 | * as the namespace of the source entity. |
||
489 | * |
||
490 | * - <b>mappedBy</b> (string, required for bidirectional associations) |
||
491 | * The name of the field that completes the bidirectional association on the owning side. |
||
492 | * This key must be specified on the inverse side of a bidirectional association. |
||
493 | * |
||
494 | * - <b>inversedBy</b> (string, required for bidirectional associations) |
||
495 | * The name of the field that completes the bidirectional association on the inverse side. |
||
496 | * This key must be specified on the owning side of a bidirectional association. |
||
497 | * |
||
498 | * - <b>cascade</b> (array, optional) |
||
499 | * The names of persistence operations to cascade on the association. The set of possible |
||
500 | * values are: "persist", "remove", "detach", "merge", "refresh", "all" (implies all others). |
||
501 | * |
||
502 | * - <b>orderBy</b> (array, one-to-many/many-to-many only) |
||
503 | * A map of field names (of the target entity) to sorting directions (ASC/DESC). |
||
504 | * Example: array('priority' => 'desc') |
||
505 | * |
||
506 | * - <b>fetch</b> (integer, optional) |
||
507 | * The fetching strategy to use for the association, usually defaults to FETCH_LAZY. |
||
508 | * Possible values are: ClassMetadata::FETCH_EAGER, ClassMetadata::FETCH_LAZY. |
||
509 | * |
||
510 | * - <b>joinTable</b> (array, optional, many-to-many only) |
||
511 | * Specification of the join table and its join columns (foreign keys). |
||
512 | * Only valid for many-to-many mappings. Note that one-to-many associations can be mapped |
||
513 | * through a join table by simply mapping the association as many-to-many with a unique |
||
514 | * constraint on the join table. |
||
515 | * |
||
516 | * - <b>indexBy</b> (string, optional, to-many only) |
||
517 | * Specification of a field on target-entity that is used to index the collection by. |
||
518 | * This field HAS to be either the primary key or a unique column. Otherwise the collection |
||
519 | * does not contain all the entities that are actually related. |
||
520 | * |
||
521 | * A join table definition has the following structure: |
||
522 | * <pre> |
||
523 | * array( |
||
524 | * 'name' => <join table name>, |
||
525 | * 'joinColumns' => array(<join column mapping from join table to source table>), |
||
526 | * 'inverseJoinColumns' => array(<join column mapping from join table to target table>) |
||
527 | * ) |
||
528 | * </pre> |
||
529 | * |
||
530 | * @var array |
||
531 | */ |
||
532 | public $associationMappings = array(); |
||
533 | |||
534 | /** |
||
535 | * READ-ONLY: Flag indicating whether the identifier/primary key of the class is composite. |
||
536 | * |
||
537 | * @var boolean |
||
538 | */ |
||
539 | public $isIdentifierComposite = false; |
||
540 | |||
541 | /** |
||
542 | * READ-ONLY: Flag indicating whether the identifier/primary key contains at least one foreign key association. |
||
543 | * |
||
544 | * This flag is necessary because some code blocks require special treatment of this cases. |
||
545 | * |
||
546 | * @var boolean |
||
547 | */ |
||
548 | public $containsForeignIdentifier = false; |
||
549 | |||
550 | /** |
||
551 | * READ-ONLY: The ID generator used for generating IDs for this class. |
||
552 | * |
||
553 | * @var \Doctrine\ORM\Id\AbstractIdGenerator |
||
554 | * |
||
555 | * @todo Remove! |
||
556 | */ |
||
557 | public $idGenerator; |
||
558 | |||
559 | /** |
||
560 | * READ-ONLY: The definition of the sequence generator of this class. Only used for the |
||
561 | * SEQUENCE generation strategy. |
||
562 | * |
||
563 | * The definition has the following structure: |
||
564 | * <code> |
||
565 | * array( |
||
566 | * 'sequenceName' => 'name', |
||
567 | * 'allocationSize' => 20, |
||
568 | * 'initialValue' => 1 |
||
569 | * ) |
||
570 | * </code> |
||
571 | * |
||
572 | * @var array |
||
573 | * |
||
574 | * @todo Merge with tableGeneratorDefinition into generic generatorDefinition |
||
575 | */ |
||
576 | public $sequenceGeneratorDefinition; |
||
577 | |||
578 | /** |
||
579 | * READ-ONLY: The definition of the table generator of this class. Only used for the |
||
580 | * TABLE generation strategy. |
||
581 | * |
||
582 | * @var array |
||
583 | * |
||
584 | * @todo Merge with tableGeneratorDefinition into generic generatorDefinition |
||
585 | */ |
||
586 | public $tableGeneratorDefinition; |
||
587 | |||
588 | /** |
||
589 | * READ-ONLY: The policy used for change-tracking on entities of this class. |
||
590 | * |
||
591 | * @var integer |
||
592 | */ |
||
593 | public $changeTrackingPolicy = self::CHANGETRACKING_DEFERRED_IMPLICIT; |
||
594 | |||
595 | /** |
||
596 | * READ-ONLY: A flag for whether or not instances of this class are to be versioned |
||
597 | * with optimistic locking. |
||
598 | * |
||
599 | * @var boolean |
||
600 | */ |
||
601 | public $isVersioned; |
||
602 | |||
603 | /** |
||
604 | * READ-ONLY: The name of the field which is used for versioning in optimistic locking (if any). |
||
605 | * |
||
606 | * @var mixed |
||
607 | */ |
||
608 | public $versionField; |
||
609 | |||
610 | /** |
||
611 | * @var array |
||
612 | */ |
||
613 | public $cache = null; |
||
614 | |||
615 | /** |
||
616 | * The ReflectionClass instance of the mapped class. |
||
617 | * |
||
618 | * @var ReflectionClass |
||
619 | */ |
||
620 | public $reflClass; |
||
621 | |||
622 | /** |
||
623 | * Is this entity marked as "read-only"? |
||
624 | * |
||
625 | * That means it is never considered for change-tracking in the UnitOfWork. It is a very helpful performance |
||
626 | * optimization for entities that are immutable, either in your domain or through the relation database |
||
627 | * (coming from a view, or a history table for example). |
||
628 | * |
||
629 | * @var bool |
||
630 | */ |
||
631 | public $isReadOnly = false; |
||
632 | |||
633 | /** |
||
634 | * NamingStrategy determining the default column and table names. |
||
635 | * |
||
636 | * @var \Doctrine\ORM\Mapping\NamingStrategy |
||
637 | */ |
||
638 | protected $namingStrategy; |
||
639 | |||
640 | /** |
||
641 | * The ReflectionProperty instances of the mapped class. |
||
642 | * |
||
643 | * @var \ReflectionProperty[] |
||
644 | */ |
||
645 | public $reflFields = array(); |
||
646 | |||
647 | /** |
||
648 | * @var \Doctrine\Instantiator\InstantiatorInterface|null |
||
649 | */ |
||
650 | private $instantiator; |
||
651 | |||
652 | /** |
||
653 | * Initializes a new ClassMetadata instance that will hold the object-relational mapping |
||
654 | * metadata of the class with the given name. |
||
655 | * |
||
656 | * @param string $entityName The name of the entity class the new instance is used for. |
||
657 | * @param NamingStrategy|null $namingStrategy |
||
658 | */ |
||
659 | 647 | public function __construct($entityName, NamingStrategy $namingStrategy = null) |
|
660 | { |
||
661 | 647 | $this->name = $entityName; |
|
662 | 647 | $this->rootEntityName = $entityName; |
|
663 | 647 | $this->namingStrategy = $namingStrategy ?: new DefaultNamingStrategy(); |
|
664 | 647 | $this->instantiator = new Instantiator(); |
|
665 | 647 | } |
|
666 | |||
667 | /** |
||
668 | * Gets the ReflectionProperties of the mapped class. |
||
669 | * |
||
670 | * @return array An array of ReflectionProperty instances. |
||
671 | */ |
||
672 | 224 | public function getReflectionProperties() |
|
673 | { |
||
674 | 224 | return $this->reflFields; |
|
675 | } |
||
676 | |||
677 | /** |
||
678 | * Gets a ReflectionProperty for a specific field of the mapped class. |
||
679 | * |
||
680 | * @param string $name |
||
681 | * |
||
682 | * @return \ReflectionProperty |
||
683 | */ |
||
684 | 1 | public function getReflectionProperty($name) |
|
685 | { |
||
686 | 1 | return $this->reflFields[$name]; |
|
687 | } |
||
688 | |||
689 | /** |
||
690 | * Gets the ReflectionProperty for the single identifier field. |
||
691 | * |
||
692 | * @return \ReflectionProperty |
||
693 | * |
||
694 | * @throws BadMethodCallException If the class has a composite identifier. |
||
695 | */ |
||
696 | public function getSingleIdReflectionProperty() |
||
704 | |||
705 | /** |
||
706 | * Extracts the identifier values of an entity of this class. |
||
707 | * |
||
708 | * For composite identifiers, the identifier values are returned as an array |
||
709 | * with the same order as the field order in {@link identifier}. |
||
710 | * |
||
711 | * @param object $entity |
||
712 | * |
||
713 | * @return array |
||
714 | */ |
||
715 | 465 | public function getIdentifierValues($entity) |
|
740 | |||
741 | /** |
||
742 | * Populates the entity identifier of an entity. |
||
743 | * |
||
744 | * @param object $entity |
||
745 | * @param array $id |
||
746 | * |
||
747 | * @return void |
||
748 | * |
||
749 | * @todo Rename to assignIdentifier() |
||
750 | */ |
||
751 | 6 | public function setIdentifierValues($entity, array $id) |
|
757 | |||
758 | /** |
||
759 | * Sets the specified field to the specified value on the given entity. |
||
760 | * |
||
761 | * @param object $entity |
||
762 | * @param string $field |
||
763 | * @param mixed $value |
||
764 | * |
||
765 | * @return void |
||
766 | */ |
||
767 | 231 | public function setFieldValue($entity, $field, $value) |
|
771 | |||
772 | /** |
||
773 | * Gets the specified field's value off the given entity. |
||
774 | * |
||
775 | * @param object $entity |
||
776 | * @param string $field |
||
777 | * |
||
778 | * @return mixed |
||
779 | */ |
||
780 | 306 | public function getFieldValue($entity, $field) |
|
784 | |||
785 | /** |
||
786 | * Creates a string representation of this instance. |
||
787 | * |
||
788 | * @return string The string representation of this instance. |
||
789 | * |
||
790 | * @todo Construct meaningful string representation. |
||
791 | */ |
||
792 | public function __toString() |
||
796 | |||
797 | /** |
||
798 | * Determines which fields get serialized. |
||
799 | * |
||
800 | * It is only serialized what is necessary for best unserialization performance. |
||
801 | * That means any metadata properties that are not set or empty or simply have |
||
802 | * their default value are NOT serialized. |
||
803 | * |
||
804 | * Parts that are also NOT serialized because they can not be properly unserialized: |
||
805 | * - reflClass (ReflectionClass) |
||
806 | * - reflFields (ReflectionProperty array) |
||
807 | * |
||
808 | * @return array The names of all the fields that should be serialized. |
||
809 | */ |
||
810 | 6 | public function __sleep() |
|
904 | |||
905 | /** |
||
906 | * Creates a new instance of the mapped class, without invoking the constructor. |
||
907 | * |
||
908 | * @return object |
||
909 | */ |
||
910 | 672 | public function newInstance() |
|
914 | |||
915 | /** |
||
916 | * Restores some state that can not be serialized/unserialized. |
||
917 | * |
||
918 | * @param \Doctrine\Common\Persistence\Mapping\ReflectionService $reflService |
||
919 | * |
||
920 | * @return void |
||
921 | */ |
||
922 | 2007 | public function wakeupReflection($reflService) |
|
974 | |||
975 | /** |
||
976 | * Initializes a new ClassMetadata instance that will hold the object-relational mapping |
||
977 | * metadata of the class with the given name. |
||
978 | * |
||
979 | * @param \Doctrine\Common\Persistence\Mapping\ReflectionService $reflService The reflection service. |
||
980 | * |
||
981 | * @return void |
||
982 | */ |
||
983 | 611 | public function initializeReflection($reflService) |
|
994 | |||
995 | /** |
||
996 | * Validates Identifier. |
||
997 | * |
||
998 | * @return void |
||
999 | * |
||
1000 | * @throws MappingException |
||
1001 | */ |
||
1002 | 400 | public function validateIdentifier() |
|
1017 | |||
1018 | /** |
||
1019 | * Validates association targets actually exist. |
||
1020 | * |
||
1021 | * @return void |
||
1022 | * |
||
1023 | * @throws MappingException |
||
1024 | */ |
||
1025 | 401 | public function validateAssociations() |
|
1033 | |||
1034 | /** |
||
1035 | * Validates lifecycle callbacks. |
||
1036 | * |
||
1037 | * @param \Doctrine\Common\Persistence\Mapping\ReflectionService $reflService |
||
1038 | * |
||
1039 | * @return void |
||
1040 | * |
||
1041 | * @throws MappingException |
||
1042 | */ |
||
1043 | 401 | public function validateLifecycleCallbacks($reflService) |
|
1053 | |||
1054 | /** |
||
1055 | * {@inheritDoc} |
||
1056 | */ |
||
1057 | 529 | public function getReflectionClass() |
|
1061 | |||
1062 | /** |
||
1063 | * @param array $cache |
||
1064 | * |
||
1065 | * @return void |
||
1066 | */ |
||
1067 | 21 | public function enableCache(array $cache) |
|
1079 | |||
1080 | /** |
||
1081 | * @param string $fieldName |
||
1082 | * @param array $cache |
||
1083 | * |
||
1084 | * @return void |
||
1085 | */ |
||
1086 | 2 | public function enableAssociationCache($fieldName, array $cache) |
|
1090 | |||
1091 | /** |
||
1092 | * @param string $fieldName |
||
1093 | * @param array $cache |
||
1094 | * |
||
1095 | * @return array |
||
1096 | */ |
||
1097 | 17 | public function getAssociationCacheDefaults($fieldName, array $cache) |
|
1111 | |||
1112 | /** |
||
1113 | * Sets the change tracking policy used by this class. |
||
1114 | * |
||
1115 | * @param integer $policy |
||
1116 | * |
||
1117 | * @return void |
||
1118 | */ |
||
1119 | 139 | public function setChangeTrackingPolicy($policy) |
|
1123 | |||
1124 | /** |
||
1125 | * Whether the change tracking policy of this class is "deferred explicit". |
||
1126 | * |
||
1127 | * @return boolean |
||
1128 | */ |
||
1129 | 267 | public function isChangeTrackingDeferredExplicit() |
|
1133 | |||
1134 | /** |
||
1135 | * Whether the change tracking policy of this class is "deferred implicit". |
||
1136 | * |
||
1137 | * @return boolean |
||
1138 | */ |
||
1139 | 459 | public function isChangeTrackingDeferredImplicit() |
|
1143 | |||
1144 | /** |
||
1145 | * Whether the change tracking policy of this class is "notify". |
||
1146 | * |
||
1147 | * @return boolean |
||
1148 | */ |
||
1149 | 290 | public function isChangeTrackingNotify() |
|
1153 | |||
1154 | /** |
||
1155 | * Checks whether a field is part of the identifier/primary key field(s). |
||
1156 | * |
||
1157 | * @param string $fieldName The field name. |
||
1158 | * |
||
1159 | * @return boolean TRUE if the field is part of the table identifier/primary key field(s), |
||
1160 | * FALSE otherwise. |
||
1161 | */ |
||
1162 | 1070 | public function isIdentifier($fieldName) |
|
1174 | |||
1175 | /** |
||
1176 | * Checks if the field is unique. |
||
1177 | * |
||
1178 | * @param string $fieldName The field name. |
||
1179 | * |
||
1180 | * @return boolean TRUE if the field is unique, FALSE otherwise. |
||
1181 | */ |
||
1182 | public function isUniqueField($fieldName) |
||
1192 | |||
1193 | /** |
||
1194 | * Checks if the field is not null. |
||
1195 | * |
||
1196 | * @param string $fieldName The field name. |
||
1197 | * |
||
1198 | * @return boolean TRUE if the field is not null, FALSE otherwise. |
||
1199 | */ |
||
1200 | 1 | public function isNullable($fieldName) |
|
1210 | |||
1211 | /** |
||
1212 | * Gets a column name for a field name. |
||
1213 | * If the column name for the field cannot be found, the given field name |
||
1214 | * is returned. |
||
1215 | * |
||
1216 | * @param string $fieldName The field name. |
||
1217 | * |
||
1218 | * @return string The column name. |
||
1219 | */ |
||
1220 | 16 | public function getColumnName($fieldName) |
|
1226 | |||
1227 | /** |
||
1228 | * Gets the mapping of a (regular) field that holds some data but not a |
||
1229 | * reference to another object. |
||
1230 | * |
||
1231 | * @param string $fieldName The field name. |
||
1232 | * |
||
1233 | * @return array The field mapping. |
||
1234 | * |
||
1235 | * @throws MappingException |
||
1236 | */ |
||
1237 | 199 | public function getFieldMapping($fieldName) |
|
1245 | |||
1246 | /** |
||
1247 | * Gets the mapping of an association. |
||
1248 | * |
||
1249 | * @see ClassMetadataInfo::$associationMappings |
||
1250 | * |
||
1251 | * @param string $fieldName The field name that represents the association in |
||
1252 | * the object model. |
||
1253 | * |
||
1254 | * @return array The mapping. |
||
1255 | * |
||
1256 | * @throws MappingException |
||
1257 | */ |
||
1258 | 485 | public function getAssociationMapping($fieldName) |
|
1266 | |||
1267 | /** |
||
1268 | * Gets all association mappings of the class. |
||
1269 | * |
||
1270 | * @return array |
||
1271 | */ |
||
1272 | public function getAssociationMappings() |
||
1276 | |||
1277 | /** |
||
1278 | * Gets the field name for a column name. |
||
1279 | * If no field name can be found the column name is returned. |
||
1280 | * |
||
1281 | * @param string $columnName The column name. |
||
1282 | * |
||
1283 | * @return string The column alias. |
||
1284 | */ |
||
1285 | 237 | public function getFieldName($columnName) |
|
1291 | |||
1292 | /** |
||
1293 | * Gets the named query. |
||
1294 | * |
||
1295 | * @see ClassMetadataInfo::$namedQueries |
||
1296 | * |
||
1297 | * @param string $queryName The query name. |
||
1298 | * |
||
1299 | * @return string |
||
1300 | * |
||
1301 | * @throws MappingException |
||
1302 | */ |
||
1303 | 4 | public function getNamedQuery($queryName) |
|
1311 | |||
1312 | /** |
||
1313 | * Gets all named queries of the class. |
||
1314 | * |
||
1315 | * @return array |
||
1316 | */ |
||
1317 | 7 | public function getNamedQueries() |
|
1321 | |||
1322 | /** |
||
1323 | * Gets the named native query. |
||
1324 | * |
||
1325 | * @see ClassMetadataInfo::$namedNativeQueries |
||
1326 | * |
||
1327 | * @param string $queryName The query name. |
||
1328 | * |
||
1329 | * @return array |
||
1330 | * |
||
1331 | * @throws MappingException |
||
1332 | */ |
||
1333 | 17 | public function getNamedNativeQuery($queryName) |
|
1341 | |||
1342 | /** |
||
1343 | * Gets all named native queries of the class. |
||
1344 | * |
||
1345 | * @return array |
||
1346 | */ |
||
1347 | 2 | public function getNamedNativeQueries() |
|
1351 | |||
1352 | /** |
||
1353 | * Gets the result set mapping. |
||
1354 | * |
||
1355 | * @see ClassMetadataInfo::$sqlResultSetMappings |
||
1356 | * |
||
1357 | * @param string $name The result set mapping name. |
||
1358 | * |
||
1359 | * @return array |
||
1360 | * |
||
1361 | * @throws MappingException |
||
1362 | */ |
||
1363 | 21 | public function getSqlResultSetMapping($name) |
|
1371 | |||
1372 | /** |
||
1373 | * Gets all sql result set mappings of the class. |
||
1374 | * |
||
1375 | * @return array |
||
1376 | */ |
||
1377 | 8 | public function getSqlResultSetMappings() |
|
1381 | |||
1382 | /** |
||
1383 | * Validates & completes the given field mapping. |
||
1384 | * |
||
1385 | * @param array $mapping The field mapping to validate & complete. |
||
1386 | * |
||
1387 | * @return array The validated and completed field mapping. |
||
1388 | * |
||
1389 | * @throws MappingException |
||
1390 | */ |
||
1391 | 528 | protected function _validateAndCompleteFieldMapping(array &$mapping) |
|
1445 | |||
1446 | /** |
||
1447 | * Validates & completes the basic mapping information that is common to all |
||
1448 | * association mappings (one-to-one, many-ot-one, one-to-many, many-to-many). |
||
1449 | * |
||
1450 | * @param array $mapping The mapping. |
||
1451 | * |
||
1452 | * @return array The updated mapping. |
||
1453 | * |
||
1454 | * @throws MappingException If something is wrong with the mapping. |
||
1455 | */ |
||
1456 | 350 | protected function _validateAndCompleteAssociationMapping(array $mapping) |
|
1568 | |||
1569 | /** |
||
1570 | * Validates & completes a one-to-one association mapping. |
||
1571 | * |
||
1572 | * @param array $mapping The mapping to validate & complete. |
||
1573 | * |
||
1574 | * @return array The validated & completed mapping. |
||
1575 | * |
||
1576 | * @throws RuntimeException |
||
1577 | * @throws MappingException |
||
1578 | */ |
||
1579 | 297 | protected function _validateAndCompleteOneToOneMapping(array $mapping) |
|
1661 | |||
1662 | /** |
||
1663 | * Validates & completes a one-to-many association mapping. |
||
1664 | * |
||
1665 | * @param array $mapping The mapping to validate and complete. |
||
1666 | * |
||
1667 | * @return array The validated and completed mapping. |
||
1668 | * |
||
1669 | * @throws MappingException |
||
1670 | * @throws InvalidArgumentException |
||
1671 | */ |
||
1672 | 128 | protected function _validateAndCompleteOneToManyMapping(array $mapping) |
|
1692 | |||
1693 | /** |
||
1694 | * Validates & completes a many-to-many association mapping. |
||
1695 | * |
||
1696 | * @param array $mapping The mapping to validate & complete. |
||
1697 | * |
||
1698 | * @return array The validated & completed mapping. |
||
1699 | * |
||
1700 | * @throws \InvalidArgumentException |
||
1701 | */ |
||
1702 | 149 | protected function _validateAndCompleteManyToManyMapping(array $mapping) |
|
1802 | |||
1803 | /** |
||
1804 | * {@inheritDoc} |
||
1805 | */ |
||
1806 | 596 | public function getIdentifierFieldNames() |
|
1810 | |||
1811 | /** |
||
1812 | * Gets the name of the single id field. Note that this only works on |
||
1813 | * entity classes that have a single-field pk. |
||
1814 | * |
||
1815 | * @return string |
||
1816 | * |
||
1817 | * @throws MappingException If the class has a composite primary key. |
||
1818 | */ |
||
1819 | 396 | public function getSingleIdentifierFieldName() |
|
1827 | |||
1828 | /** |
||
1829 | * Gets the column name of the single id column. Note that this only works on |
||
1830 | * entity classes that have a single-field pk. |
||
1831 | * |
||
1832 | * @return string |
||
1833 | * |
||
1834 | * @throws MappingException If the class has a composite primary key. |
||
1835 | */ |
||
1836 | 3 | public function getSingleIdentifierColumnName() |
|
1840 | |||
1841 | /** |
||
1842 | * INTERNAL: |
||
1843 | * Sets the mapped identifier/primary key fields of this class. |
||
1844 | * Mainly used by the ClassMetadataFactory to assign inherited identifiers. |
||
1845 | * |
||
1846 | * @param array $identifier |
||
1847 | * |
||
1848 | * @return void |
||
1849 | */ |
||
1850 | 124 | public function setIdentifier(array $identifier) |
|
1855 | |||
1856 | /** |
||
1857 | * {@inheritDoc} |
||
1858 | */ |
||
1859 | 62 | public function getIdentifier() |
|
1863 | |||
1864 | /** |
||
1865 | * {@inheritDoc} |
||
1866 | */ |
||
1867 | 292 | public function hasField($fieldName) |
|
1871 | |||
1872 | /** |
||
1873 | * Gets an array containing all the column names. |
||
1874 | * |
||
1875 | * @param array|null $fieldNames |
||
1876 | * |
||
1877 | * @return array |
||
1878 | */ |
||
1879 | 43 | public function getColumnNames(array $fieldNames = null) |
|
1887 | |||
1888 | /** |
||
1889 | * Returns an array with all the identifier column names. |
||
1890 | * |
||
1891 | * @return array |
||
1892 | */ |
||
1893 | 322 | public function getIdentifierColumnNames() |
|
1913 | |||
1914 | /** |
||
1915 | * Sets the type of Id generator to use for the mapped class. |
||
1916 | * |
||
1917 | * @param int $generatorType |
||
1918 | * |
||
1919 | * @return void |
||
1920 | */ |
||
1921 | 457 | public function setIdGeneratorType($generatorType) |
|
1925 | |||
1926 | /** |
||
1927 | * Checks whether the mapped class uses an Id generator. |
||
1928 | * |
||
1929 | * @return boolean TRUE if the mapped class uses an Id generator, FALSE otherwise. |
||
1930 | */ |
||
1931 | 392 | public function usesIdGenerator() |
|
1935 | |||
1936 | /** |
||
1937 | * @return boolean |
||
1938 | */ |
||
1939 | 1324 | public function isInheritanceTypeNone() |
|
1943 | |||
1944 | /** |
||
1945 | * Checks whether the mapped class uses the JOINED inheritance mapping strategy. |
||
1946 | * |
||
1947 | * @return boolean TRUE if the class participates in a JOINED inheritance mapping, |
||
1948 | * FALSE otherwise. |
||
1949 | */ |
||
1950 | 1052 | public function isInheritanceTypeJoined() |
|
1954 | |||
1955 | /** |
||
1956 | * Checks whether the mapped class uses the SINGLE_TABLE inheritance mapping strategy. |
||
1957 | * |
||
1958 | * @return boolean TRUE if the class participates in a SINGLE_TABLE inheritance mapping, |
||
1959 | * FALSE otherwise. |
||
1960 | */ |
||
1961 | 1224 | public function isInheritanceTypeSingleTable() |
|
1965 | |||
1966 | /** |
||
1967 | * Checks whether the mapped class uses the TABLE_PER_CLASS inheritance mapping strategy. |
||
1968 | * |
||
1969 | * @return boolean TRUE if the class participates in a TABLE_PER_CLASS inheritance mapping, |
||
1970 | * FALSE otherwise. |
||
1971 | */ |
||
1972 | 260 | public function isInheritanceTypeTablePerClass() |
|
1976 | |||
1977 | /** |
||
1978 | * Checks whether the class uses an identity column for the Id generation. |
||
1979 | * |
||
1980 | * @return boolean TRUE if the class uses the IDENTITY generator, FALSE otherwise. |
||
1981 | */ |
||
1982 | 1063 | public function isIdGeneratorIdentity() |
|
1986 | |||
1987 | /** |
||
1988 | * Checks whether the class uses a sequence for id generation. |
||
1989 | * |
||
1990 | * @return boolean TRUE if the class uses the SEQUENCE generator, FALSE otherwise. |
||
1991 | */ |
||
1992 | 313 | public function isIdGeneratorSequence() |
|
1996 | |||
1997 | /** |
||
1998 | * Checks whether the class uses a table for id generation. |
||
1999 | * |
||
2000 | * @return boolean TRUE if the class uses the TABLE generator, FALSE otherwise. |
||
2001 | */ |
||
2002 | 80 | public function isIdGeneratorTable() |
|
2006 | |||
2007 | /** |
||
2008 | * Checks whether the class has a natural identifier/pk (which means it does |
||
2009 | * not use any Id generator. |
||
2010 | * |
||
2011 | * @return boolean |
||
2012 | */ |
||
2013 | 73 | public function isIdentifierNatural() |
|
2017 | |||
2018 | /** |
||
2019 | * Checks whether the class use a UUID for id generation. |
||
2020 | * |
||
2021 | * @return boolean |
||
2022 | */ |
||
2023 | public function isIdentifierUuid() |
||
2027 | |||
2028 | /** |
||
2029 | * Gets the type of a field. |
||
2030 | * |
||
2031 | * @param string $fieldName |
||
2032 | * |
||
2033 | * @return \Doctrine\DBAL\Types\Type|string|null |
||
2034 | * |
||
2035 | * @todo 3.0 Remove this. PersisterHelper should fix it somehow |
||
2036 | */ |
||
2037 | 38 | public function getTypeOfField($fieldName) |
|
2043 | |||
2044 | /** |
||
2045 | * Gets the type of a column. |
||
2046 | * |
||
2047 | * @param string $columnName |
||
2048 | * |
||
2049 | * @return \Doctrine\DBAL\Types\Type|string|null |
||
2050 | * |
||
2051 | * @deprecated 3.0 remove this. this method is bogous and unreliable, since it cannot resolve the type of a column |
||
2052 | * that is derived by a referenced field on a different entity. |
||
2053 | */ |
||
2054 | public function getTypeOfColumn($columnName) |
||
2055 | { |
||
2056 | return $this->getTypeOfField($this->getFieldName($columnName)); |
||
2057 | } |
||
2058 | |||
2059 | /** |
||
2060 | * Gets the name of the primary table. |
||
2061 | * |
||
2062 | * @return string |
||
2063 | */ |
||
2064 | 1465 | public function getTableName() |
|
2068 | |||
2069 | /** |
||
2070 | * Gets primary table's schema name. |
||
2071 | * |
||
2072 | * @return string|null |
||
2073 | */ |
||
2074 | 13 | public function getSchemaName() |
|
2078 | |||
2079 | /** |
||
2080 | * Gets the table name to use for temporary identifier tables of this class. |
||
2081 | * |
||
2082 | * @return string |
||
2083 | */ |
||
2084 | 7 | public function getTemporaryIdTableName() |
|
2089 | |||
2090 | /** |
||
2091 | * Sets the mapped subclasses of this class. |
||
2092 | * |
||
2093 | * @param array $subclasses The names of all mapped subclasses. |
||
2094 | * |
||
2095 | * @return void |
||
2096 | */ |
||
2097 | 2 | public function setSubclasses(array $subclasses) |
|
2103 | |||
2104 | /** |
||
2105 | * Sets the parent class names. |
||
2106 | * Assumes that the class names in the passed array are in the order: |
||
2107 | * directParent -> directParentParent -> directParentParentParent ... -> root. |
||
2108 | * |
||
2109 | * @param array $classNames |
||
2110 | * |
||
2111 | * @return void |
||
2112 | */ |
||
2113 | 409 | public function setParentClasses(array $classNames) |
|
2121 | |||
2122 | /** |
||
2123 | * Sets the inheritance type used by the class and its subclasses. |
||
2124 | * |
||
2125 | * @param integer $type |
||
2126 | * |
||
2127 | * @return void |
||
2128 | * |
||
2129 | * @throws MappingException |
||
2130 | */ |
||
2131 | 170 | public function setInheritanceType($type) |
|
2139 | |||
2140 | /** |
||
2141 | * Sets the association to override association mapping of property for an entity relationship. |
||
2142 | * |
||
2143 | * @param string $fieldName |
||
2144 | * @param array $overrideMapping |
||
2145 | * |
||
2146 | * @return void |
||
2147 | * |
||
2148 | * @throws MappingException |
||
2149 | */ |
||
2150 | 20 | public function setAssociationOverride($fieldName, array $overrideMapping) |
|
2193 | |||
2194 | /** |
||
2195 | * Sets the override for a mapped field. |
||
2196 | * |
||
2197 | * @param string $fieldName |
||
2198 | * @param array $overrideMapping |
||
2199 | * |
||
2200 | * @return void |
||
2201 | * |
||
2202 | * @throws MappingException |
||
2203 | */ |
||
2204 | 15 | public function setAttributeOverride($fieldName, array $overrideMapping) |
|
2236 | |||
2237 | /** |
||
2238 | * Checks whether a mapped field is inherited from an entity superclass. |
||
2239 | * |
||
2240 | * @param string $fieldName |
||
2241 | * |
||
2242 | * @return bool TRUE if the field is inherited, FALSE otherwise. |
||
2243 | */ |
||
2244 | 369 | public function isInheritedField($fieldName) |
|
2248 | |||
2249 | /** |
||
2250 | * Checks if this entity is the root in any entity-inheritance-hierarchy. |
||
2251 | * |
||
2252 | * @return bool |
||
2253 | */ |
||
2254 | 408 | public function isRootEntity() |
|
2258 | |||
2259 | /** |
||
2260 | * Checks whether a mapped association field is inherited from a superclass. |
||
2261 | * |
||
2262 | * @param string $fieldName |
||
2263 | * |
||
2264 | * @return boolean TRUE if the field is inherited, FALSE otherwise. |
||
2265 | */ |
||
2266 | 348 | public function isInheritedAssociation($fieldName) |
|
2270 | |||
2271 | 348 | public function isInheritedEmbeddedClass($fieldName) |
|
2275 | |||
2276 | /** |
||
2277 | * Sets the name of the primary table the class is mapped to. |
||
2278 | * |
||
2279 | * @param string $tableName The table name. |
||
2280 | * |
||
2281 | * @return void |
||
2282 | * |
||
2283 | * @deprecated Use {@link setPrimaryTable}. |
||
2284 | */ |
||
2285 | 5 | public function setTableName($tableName) |
|
2286 | { |
||
2287 | 5 | $this->table['name'] = $tableName; |
|
2288 | 5 | } |
|
2289 | |||
2290 | /** |
||
2291 | * Sets the primary table definition. The provided array supports the |
||
2292 | * following structure: |
||
2293 | * |
||
2294 | * name => <tableName> (optional, defaults to class name) |
||
2295 | * indexes => array of indexes (optional) |
||
2296 | * uniqueConstraints => array of constraints (optional) |
||
2297 | * |
||
2298 | * If a key is omitted, the current value is kept. |
||
2299 | * |
||
2300 | * @param array $table The table description. |
||
2301 | * |
||
2302 | * @return void |
||
2303 | */ |
||
2304 | 324 | public function setPrimaryTable(array $table) |
|
2336 | |||
2337 | /** |
||
2338 | * Checks whether the given type identifies an inheritance type. |
||
2339 | * |
||
2340 | * @param integer $type |
||
2341 | * |
||
2342 | * @return boolean TRUE if the given type identifies an inheritance type, FALSe otherwise. |
||
2343 | */ |
||
2344 | 170 | private function _isInheritanceType($type) |
|
2351 | |||
2352 | /** |
||
2353 | * Adds a mapped field to the class. |
||
2354 | * |
||
2355 | * @param array $mapping The field mapping. |
||
2356 | * |
||
2357 | * @return void |
||
2358 | * |
||
2359 | * @throws MappingException |
||
2360 | */ |
||
2361 | 528 | public function mapField(array $mapping) |
|
2368 | |||
2369 | /** |
||
2370 | * INTERNAL: |
||
2371 | * Adds an association mapping without completing/validating it. |
||
2372 | * This is mainly used to add inherited association mappings to derived classes. |
||
2373 | * |
||
2374 | * @param array $mapping |
||
2375 | * |
||
2376 | * @return void |
||
2377 | * |
||
2378 | * @throws MappingException |
||
2379 | */ |
||
2380 | 48 | public function addInheritedAssociationMapping(array $mapping/*, $owningClassName = null*/) |
|
2387 | |||
2388 | /** |
||
2389 | * INTERNAL: |
||
2390 | * Adds a field mapping without completing/validating it. |
||
2391 | * This is mainly used to add inherited field mappings to derived classes. |
||
2392 | * |
||
2393 | * @param array $fieldMapping |
||
2394 | * |
||
2395 | * @return void |
||
2396 | */ |
||
2397 | 108 | public function addInheritedFieldMapping(array $fieldMapping) |
|
2403 | |||
2404 | /** |
||
2405 | * INTERNAL: |
||
2406 | * Adds a named query to this class. |
||
2407 | * |
||
2408 | * @param array $queryMapping |
||
2409 | * |
||
2410 | * @return void |
||
2411 | * |
||
2412 | * @throws MappingException |
||
2413 | */ |
||
2414 | 29 | public function addNamedQuery(array $queryMapping) |
|
2438 | |||
2439 | /** |
||
2440 | * INTERNAL: |
||
2441 | * Adds a named native query to this class. |
||
2442 | * |
||
2443 | * @param array $queryMapping |
||
2444 | * |
||
2445 | * @return void |
||
2446 | * |
||
2447 | * @throws MappingException |
||
2448 | */ |
||
2449 | 39 | public function addNamedNativeQuery(array $queryMapping) |
|
2482 | |||
2483 | /** |
||
2484 | * INTERNAL: |
||
2485 | * Adds a sql result set mapping to this class. |
||
2486 | * |
||
2487 | * @param array $resultMapping |
||
2488 | * |
||
2489 | * @return void |
||
2490 | * |
||
2491 | * @throws MappingException |
||
2492 | */ |
||
2493 | 39 | public function addSqlResultSetMapping(array $resultMapping) |
|
2543 | |||
2544 | /** |
||
2545 | * Adds a one-to-one mapping. |
||
2546 | * |
||
2547 | * @param array $mapping The mapping. |
||
2548 | * |
||
2549 | * @return void |
||
2550 | */ |
||
2551 | 167 | public function mapOneToOne(array $mapping) |
|
2559 | |||
2560 | /** |
||
2561 | * Adds a one-to-many mapping. |
||
2562 | * |
||
2563 | * @param array $mapping The mapping. |
||
2564 | * |
||
2565 | * @return void |
||
2566 | */ |
||
2567 | 128 | public function mapOneToMany(array $mapping) |
|
2575 | |||
2576 | /** |
||
2577 | * Adds a many-to-one mapping. |
||
2578 | * |
||
2579 | * @param array $mapping The mapping. |
||
2580 | * |
||
2581 | * @return void |
||
2582 | */ |
||
2583 | 162 | public function mapManyToOne(array $mapping) |
|
2592 | |||
2593 | /** |
||
2594 | * Adds a many-to-many mapping. |
||
2595 | * |
||
2596 | * @param array $mapping The mapping. |
||
2597 | * |
||
2598 | * @return void |
||
2599 | */ |
||
2600 | 149 | public function mapManyToMany(array $mapping) |
|
2608 | |||
2609 | /** |
||
2610 | * Stores the association mapping. |
||
2611 | * |
||
2612 | * @param array $assocMapping |
||
2613 | * |
||
2614 | * @return void |
||
2615 | * |
||
2616 | * @throws MappingException |
||
2617 | */ |
||
2618 | 339 | protected function _storeAssociationMapping(array $assocMapping) |
|
2626 | |||
2627 | /** |
||
2628 | * Registers a custom repository class for the entity class. |
||
2629 | * |
||
2630 | * @param string $repositoryClassName The class name of the custom mapper. |
||
2631 | * |
||
2632 | * @return void |
||
2633 | */ |
||
2634 | 63 | public function setCustomRepositoryClass($repositoryClassName) |
|
2638 | |||
2639 | /** |
||
2640 | * Dispatches the lifecycle event of the given entity to the registered |
||
2641 | * lifecycle callbacks and lifecycle listeners. |
||
2642 | * |
||
2643 | * @deprecated Deprecated since version 2.4 in favor of \Doctrine\ORM\Event\ListenersInvoker |
||
2644 | * |
||
2645 | * @param string $lifecycleEvent The lifecycle event. |
||
2646 | * @param object $entity The Entity on which the event occurred. |
||
2647 | * |
||
2648 | * @return void |
||
2649 | */ |
||
2650 | 1 | public function invokeLifecycleCallbacks($lifecycleEvent, $entity) |
|
2651 | { |
||
2652 | 1 | foreach ($this->lifecycleCallbacks[$lifecycleEvent] as $callback) { |
|
2653 | 1 | $entity->$callback(); |
|
2654 | } |
||
2655 | 1 | } |
|
2656 | |||
2657 | /** |
||
2658 | * Whether the class has any attached lifecycle listeners or callbacks for a lifecycle event. |
||
2659 | * |
||
2660 | * @param string $lifecycleEvent |
||
2661 | * |
||
2662 | * @return boolean |
||
2663 | */ |
||
2664 | public function hasLifecycleCallbacks($lifecycleEvent) |
||
2668 | |||
2669 | /** |
||
2670 | * Gets the registered lifecycle callbacks for an event. |
||
2671 | * |
||
2672 | * @param string $event |
||
2673 | * |
||
2674 | * @return array |
||
2675 | */ |
||
2676 | public function getLifecycleCallbacks($event) |
||
2680 | |||
2681 | /** |
||
2682 | * Adds a lifecycle callback for entities of this class. |
||
2683 | * |
||
2684 | * @param string $callback |
||
2685 | * @param string $event |
||
2686 | * |
||
2687 | * @return void |
||
2688 | */ |
||
2689 | 41 | public function addLifecycleCallback($callback, $event) |
|
2697 | |||
2698 | /** |
||
2699 | * Sets the lifecycle callbacks for entities of this class. |
||
2700 | * Any previously registered callbacks are overwritten. |
||
2701 | * |
||
2702 | * @param array $callbacks |
||
2703 | * |
||
2704 | * @return void |
||
2705 | */ |
||
2706 | 123 | public function setLifecycleCallbacks(array $callbacks) |
|
2710 | |||
2711 | /** |
||
2712 | * Adds a entity listener for entities of this class. |
||
2713 | * |
||
2714 | * @param string $eventName The entity lifecycle event. |
||
2715 | * @param string $class The listener class. |
||
2716 | * @param string $method The listener callback method. |
||
2717 | * |
||
2718 | * @throws \Doctrine\ORM\Mapping\MappingException |
||
2719 | */ |
||
2720 | 35 | public function addEntityListener($eventName, $class, $method) |
|
2743 | |||
2744 | /** |
||
2745 | * Sets the discriminator column definition. |
||
2746 | * |
||
2747 | * @param array $columnDef |
||
2748 | * |
||
2749 | * @return void |
||
2750 | * |
||
2751 | * @throws MappingException |
||
2752 | * |
||
2753 | * @see getDiscriminatorColumn() |
||
2754 | */ |
||
2755 | 164 | public function setDiscriminatorColumn($columnDef) |
|
2781 | |||
2782 | /** |
||
2783 | * Sets the discriminator values used by this class. |
||
2784 | * Used for JOINED and SINGLE_TABLE inheritance mapping strategies. |
||
2785 | * |
||
2786 | * @param array $map |
||
2787 | * |
||
2788 | * @return void |
||
2789 | */ |
||
2790 | 157 | public function setDiscriminatorMap(array $map) |
|
2796 | |||
2797 | /** |
||
2798 | * Adds one entry of the discriminator map with a new class and corresponding name. |
||
2799 | * |
||
2800 | * @param string $name |
||
2801 | * @param string $className |
||
2802 | * |
||
2803 | * @return void |
||
2804 | * |
||
2805 | * @throws MappingException |
||
2806 | */ |
||
2807 | 104 | public function addDiscriminatorMapClass($name, $className) |
|
2828 | |||
2829 | /** |
||
2830 | * Checks whether the class has a named query with the given query name. |
||
2831 | * |
||
2832 | * @param string $queryName |
||
2833 | * |
||
2834 | * @return boolean |
||
2835 | */ |
||
2836 | 1 | public function hasNamedQuery($queryName) |
|
2840 | |||
2841 | /** |
||
2842 | * Checks whether the class has a named native query with the given query name. |
||
2843 | * |
||
2844 | * @param string $queryName |
||
2845 | * |
||
2846 | * @return boolean |
||
2847 | */ |
||
2848 | 1 | public function hasNamedNativeQuery($queryName) |
|
2852 | |||
2853 | /** |
||
2854 | * Checks whether the class has a named native query with the given query name. |
||
2855 | * |
||
2856 | * @param string $name |
||
2857 | * |
||
2858 | * @return boolean |
||
2859 | */ |
||
2860 | 1 | public function hasSqlResultSetMapping($name) |
|
2864 | |||
2865 | /** |
||
2866 | * {@inheritDoc} |
||
2867 | */ |
||
2868 | 342 | public function hasAssociation($fieldName) |
|
2872 | |||
2873 | /** |
||
2874 | * {@inheritDoc} |
||
2875 | */ |
||
2876 | 1 | public function isSingleValuedAssociation($fieldName) |
|
2881 | |||
2882 | /** |
||
2883 | * {@inheritDoc} |
||
2884 | */ |
||
2885 | 1026 | public function isCollectionValuedAssociation($fieldName) |
|
2890 | |||
2891 | /** |
||
2892 | * Is this an association that only has a single join column? |
||
2893 | * |
||
2894 | * @param string $fieldName |
||
2895 | * |
||
2896 | * @return bool |
||
2897 | */ |
||
2898 | 35 | public function isAssociationWithSingleJoinColumn($fieldName) |
|
2904 | |||
2905 | /** |
||
2906 | * Returns the single association join column (if any). |
||
2907 | * |
||
2908 | * @param string $fieldName |
||
2909 | * |
||
2910 | * @return string |
||
2911 | * |
||
2912 | * @throws MappingException |
||
2913 | */ |
||
2914 | 9 | public function getSingleAssociationJoinColumnName($fieldName) |
|
2922 | |||
2923 | /** |
||
2924 | * Returns the single association referenced join column name (if any). |
||
2925 | * |
||
2926 | * @param string $fieldName |
||
2927 | * |
||
2928 | * @return string |
||
2929 | * |
||
2930 | * @throws MappingException |
||
2931 | */ |
||
2932 | 9 | public function getSingleAssociationReferencedJoinColumnName($fieldName) |
|
2940 | |||
2941 | /** |
||
2942 | * Used to retrieve a fieldname for either field or association from a given column. |
||
2943 | * |
||
2944 | * This method is used in foreign-key as primary-key contexts. |
||
2945 | * |
||
2946 | * @param string $columnName |
||
2947 | * |
||
2948 | * @return string |
||
2949 | * |
||
2950 | * @throws MappingException |
||
2951 | */ |
||
2952 | 634 | public function getFieldForColumn($columnName) |
|
2968 | |||
2969 | /** |
||
2970 | * Sets the ID generator used to generate IDs for instances of this class. |
||
2971 | * |
||
2972 | * @param \Doctrine\ORM\Id\AbstractIdGenerator $generator |
||
2973 | * |
||
2974 | * @return void |
||
2975 | */ |
||
2976 | 411 | public function setIdGenerator($generator) |
|
2980 | |||
2981 | /** |
||
2982 | * Sets definition. |
||
2983 | * |
||
2984 | * @param array $definition |
||
2985 | * |
||
2986 | * @return void |
||
2987 | */ |
||
2988 | 12 | public function setCustomGeneratorDefinition(array $definition) |
|
2992 | |||
2993 | /** |
||
2994 | * Sets the definition of the sequence ID generator for this class. |
||
2995 | * |
||
2996 | * The definition must have the following structure: |
||
2997 | * <code> |
||
2998 | * array( |
||
2999 | * 'sequenceName' => 'name', |
||
3000 | * 'allocationSize' => 20, |
||
3001 | * 'initialValue' => 1 |
||
3002 | * 'quoted' => 1 |
||
3003 | * ) |
||
3004 | * </code> |
||
3005 | * |
||
3006 | * @param array $definition |
||
3007 | * |
||
3008 | * @return void |
||
3009 | * |
||
3010 | * @throws MappingException |
||
3011 | */ |
||
3012 | 23 | public function setSequenceGeneratorDefinition(array $definition) |
|
3025 | |||
3026 | /** |
||
3027 | * Sets the version field mapping used for versioning. Sets the default |
||
3028 | * value to use depending on the column type. |
||
3029 | * |
||
3030 | * @param array $mapping The version field mapping array. |
||
3031 | * |
||
3032 | * @return void |
||
3033 | * |
||
3034 | * @throws MappingException |
||
3035 | */ |
||
3036 | 25 | public function setVersionMapping(array &$mapping) |
|
3051 | |||
3052 | /** |
||
3053 | * Sets whether this class is to be versioned for optimistic locking. |
||
3054 | * |
||
3055 | * @param boolean $bool |
||
3056 | * |
||
3057 | * @return void |
||
3058 | */ |
||
3059 | 123 | public function setVersioned($bool) |
|
3063 | |||
3064 | /** |
||
3065 | * Sets the name of the field that is to be used for versioning if this class is |
||
3066 | * versioned for optimistic locking. |
||
3067 | * |
||
3068 | * @param string $versionField |
||
3069 | * |
||
3070 | * @return void |
||
3071 | */ |
||
3072 | 123 | public function setVersionField($versionField) |
|
3076 | |||
3077 | /** |
||
3078 | * Marks this class as read only, no change tracking is applied to it. |
||
3079 | * |
||
3080 | * @return void |
||
3081 | */ |
||
3082 | 3 | public function markReadOnly() |
|
3086 | |||
3087 | /** |
||
3088 | * {@inheritDoc} |
||
3089 | */ |
||
3090 | public function getFieldNames() |
||
3094 | |||
3095 | /** |
||
3096 | * {@inheritDoc} |
||
3097 | */ |
||
3098 | public function getAssociationNames() |
||
3102 | |||
3103 | /** |
||
3104 | * {@inheritDoc} |
||
3105 | * |
||
3106 | * @throws InvalidArgumentException |
||
3107 | */ |
||
3108 | 1 | public function getAssociationTargetClass($assocName) |
|
3116 | |||
3117 | /** |
||
3118 | * {@inheritDoc} |
||
3119 | */ |
||
3120 | 706 | public function getName() |
|
3124 | |||
3125 | /** |
||
3126 | * Gets the (possibly quoted) identifier column names for safe use in an SQL statement. |
||
3127 | * |
||
3128 | * @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy |
||
3129 | * |
||
3130 | * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform |
||
3131 | * |
||
3132 | * @return array |
||
3133 | */ |
||
3134 | public function getQuotedIdentifierColumnNames($platform) |
||
3135 | { |
||
3136 | $quotedColumnNames = array(); |
||
3137 | |||
3138 | foreach ($this->identifier as $idProperty) { |
||
3139 | if (isset($this->fieldMappings[$idProperty])) { |
||
3140 | $quotedColumnNames[] = isset($this->fieldMappings[$idProperty]['quoted']) |
||
3141 | ? $platform->quoteIdentifier($this->fieldMappings[$idProperty]['columnName']) |
||
3142 | : $this->fieldMappings[$idProperty]['columnName']; |
||
3143 | |||
3144 | continue; |
||
3145 | } |
||
3146 | |||
3147 | // Association defined as Id field |
||
3148 | $joinColumns = $this->associationMappings[$idProperty]['joinColumns']; |
||
3149 | $assocQuotedColumnNames = array_map( |
||
3150 | function ($joinColumn) use ($platform) { |
||
3151 | return isset($joinColumn['quoted']) |
||
3152 | ? $platform->quoteIdentifier($joinColumn['name']) |
||
3153 | : $joinColumn['name']; |
||
3154 | }, |
||
3155 | $joinColumns |
||
3156 | ); |
||
3157 | |||
3158 | $quotedColumnNames = array_merge($quotedColumnNames, $assocQuotedColumnNames); |
||
3159 | } |
||
3160 | |||
3161 | return $quotedColumnNames; |
||
3162 | } |
||
3163 | |||
3164 | /** |
||
3165 | * Gets the (possibly quoted) column name of a mapped field for safe use in an SQL statement. |
||
3166 | * |
||
3167 | * @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy |
||
3168 | * |
||
3169 | * @param string $field |
||
3170 | * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform |
||
3171 | * |
||
3172 | * @return string |
||
3173 | */ |
||
3174 | public function getQuotedColumnName($field, $platform) |
||
3175 | { |
||
3176 | return isset($this->fieldMappings[$field]['quoted']) |
||
3177 | ? $platform->quoteIdentifier($this->fieldMappings[$field]['columnName']) |
||
3178 | : $this->fieldMappings[$field]['columnName']; |
||
3179 | } |
||
3180 | |||
3181 | /** |
||
3182 | * Gets the (possibly quoted) primary table name of this class for safe use in an SQL statement. |
||
3183 | * |
||
3184 | * @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy |
||
3185 | * |
||
3186 | * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform |
||
3187 | * |
||
3188 | * @return string |
||
3189 | */ |
||
3190 | public function getQuotedTableName($platform) |
||
3191 | { |
||
3192 | return isset($this->table['quoted']) |
||
3193 | ? $platform->quoteIdentifier($this->table['name']) |
||
3194 | : $this->table['name']; |
||
3195 | } |
||
3196 | |||
3197 | /** |
||
3198 | * Gets the (possibly quoted) name of the join table. |
||
3199 | * |
||
3200 | * @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy |
||
3201 | * |
||
3202 | * @param array $assoc |
||
3203 | * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform |
||
3204 | * |
||
3205 | * @return string |
||
3206 | */ |
||
3207 | public function getQuotedJoinTableName(array $assoc, $platform) |
||
3208 | { |
||
3209 | return isset($assoc['joinTable']['quoted']) |
||
3210 | ? $platform->quoteIdentifier($assoc['joinTable']['name']) |
||
3211 | : $assoc['joinTable']['name']; |
||
3212 | } |
||
3213 | |||
3214 | /** |
||
3215 | * {@inheritDoc} |
||
3216 | */ |
||
3217 | 12 | public function isAssociationInverseSide($fieldName) |
|
3222 | |||
3223 | /** |
||
3224 | * {@inheritDoc} |
||
3225 | */ |
||
3226 | public function getAssociationMappedByTargetField($fieldName) |
||
3230 | |||
3231 | /** |
||
3232 | * @param string $targetClass |
||
3233 | * |
||
3234 | * @return array |
||
3235 | */ |
||
3236 | 2 | public function getAssociationsByTargetClass($targetClass) |
|
3248 | |||
3249 | /** |
||
3250 | * @param string|null $className |
||
3251 | * |
||
3252 | * @return string|null null if the input value is null |
||
3253 | */ |
||
3254 | 477 | public function fullyQualifiedClassName($className) |
|
3266 | |||
3267 | /** |
||
3268 | * @param string $name |
||
3269 | * |
||
3270 | * @return mixed |
||
3271 | */ |
||
3272 | 2 | public function getMetadataValue($name) |
|
3281 | |||
3282 | /** |
||
3283 | * Map Embedded Class |
||
3284 | * |
||
3285 | * @param array $mapping |
||
3286 | * |
||
3287 | * @throws MappingException |
||
3288 | * @return void |
||
3289 | */ |
||
3290 | 27 | public function mapEmbedded(array $mapping) |
|
3301 | |||
3302 | /** |
||
3303 | * Inline the embeddable class |
||
3304 | * |
||
3305 | * @param string $property |
||
3306 | * @param ClassMetadataInfo $embeddable |
||
3307 | */ |
||
3308 | 11 | public function inlineEmbeddable($property, ClassMetadataInfo $embeddable) |
|
3337 | |||
3338 | /** |
||
3339 | * @param string $fieldName |
||
3340 | * @throws MappingException |
||
3341 | */ |
||
3342 | 563 | private function assertFieldNotMapped($fieldName) |
|
3351 | |||
3352 | /** |
||
3353 | * Gets the sequence name based on class metadata. |
||
3354 | * |
||
3355 | * @param AbstractPlatform $platform |
||
3356 | * @return string |
||
3357 | * |
||
3358 | * @todo Sequence names should be computed in DBAL depending on the platform |
||
3359 | */ |
||
3360 | 3 | public function getSequenceName(AbstractPlatform $platform) |
|
3368 | |||
3369 | /** |
||
3370 | * Gets the sequence name prefix based on class metadata. |
||
3371 | * |
||
3372 | * @param AbstractPlatform $platform |
||
3373 | * @return string |
||
3374 | * |
||
3375 | * @todo Sequence names should be computed in DBAL depending on the platform |
||
3376 | */ |
||
3377 | 3 | public function getSequencePrefix(AbstractPlatform $platform) |
|
3393 | } |
||
3394 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: