vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php line 1090

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\ORM\Mapping;
  4. use BadMethodCallException;
  5. use DateInterval;
  6. use DateTime;
  7. use DateTimeImmutable;
  8. use Doctrine\DBAL\Platforms\AbstractPlatform;
  9. use Doctrine\DBAL\Types\Type;
  10. use Doctrine\DBAL\Types\Types;
  11. use Doctrine\Deprecations\Deprecation;
  12. use Doctrine\Instantiator\Instantiator;
  13. use Doctrine\Instantiator\InstantiatorInterface;
  14. use Doctrine\ORM\Cache\Exception\CacheException;
  15. use Doctrine\ORM\Cache\Exception\NonCacheableEntityAssociation;
  16. use Doctrine\ORM\Id\AbstractIdGenerator;
  17. use Doctrine\Persistence\Mapping\ClassMetadata;
  18. use Doctrine\Persistence\Mapping\ReflectionService;
  19. use InvalidArgumentException;
  20. use LogicException;
  21. use ReflectionClass;
  22. use ReflectionNamedType;
  23. use ReflectionProperty;
  24. use RuntimeException;
  25. use function array_diff;
  26. use function array_flip;
  27. use function array_intersect;
  28. use function array_keys;
  29. use function array_map;
  30. use function array_merge;
  31. use function array_pop;
  32. use function array_values;
  33. use function assert;
  34. use function class_exists;
  35. use function count;
  36. use function explode;
  37. use function gettype;
  38. use function in_array;
  39. use function interface_exists;
  40. use function is_array;
  41. use function is_subclass_of;
  42. use function ltrim;
  43. use function method_exists;
  44. use function spl_object_id;
  45. use function str_replace;
  46. use function strpos;
  47. use function strtolower;
  48. use function trait_exists;
  49. use function trim;
  50. use const PHP_VERSION_ID;
  51. /**
  52.  * A <tt>ClassMetadata</tt> instance holds all the object-relational mapping metadata
  53.  * of an entity and its associations.
  54.  *
  55.  * Once populated, ClassMetadata instances are usually cached in a serialized form.
  56.  *
  57.  * <b>IMPORTANT NOTE:</b>
  58.  *
  59.  * The fields of this class are only public for 2 reasons:
  60.  * 1) To allow fast READ access.
  61.  * 2) To drastically reduce the size of a serialized instance (private/protected members
  62.  *    get the whole class name, namespace inclusive, prepended to every property in
  63.  *    the serialized representation).
  64.  *
  65.  * @template-covariant T of object
  66.  * @template-implements ClassMetadata<T>
  67.  * @psalm-type FieldMapping = array{
  68.  *      type: string,
  69.  *      fieldName: string,
  70.  *      columnName: string,
  71.  *      length?: int,
  72.  *      id?: bool,
  73.  *      nullable?: bool,
  74.  *      columnDefinition?: string,
  75.  *      precision?: int,
  76.  *      scale?: int,
  77.  *      unique?: string,
  78.  *      inherited?: class-string,
  79.  *      originalClass?: class-string,
  80.  *      originalField?: string,
  81.  *      quoted?: bool,
  82.  *      requireSQLConversion?: bool,
  83.  *      declared?: class-string,
  84.  *      declaredField?: string,
  85.  *      options?: array<string, mixed>
  86.  * }
  87.  */
  88. class ClassMetadataInfo implements ClassMetadata
  89. {
  90.     /* The inheritance mapping types */
  91.     /**
  92.      * NONE means the class does not participate in an inheritance hierarchy
  93.      * and therefore does not need an inheritance mapping type.
  94.      */
  95.     public const INHERITANCE_TYPE_NONE 1;
  96.     /**
  97.      * JOINED means the class will be persisted according to the rules of
  98.      * <tt>Class Table Inheritance</tt>.
  99.      */
  100.     public const INHERITANCE_TYPE_JOINED 2;
  101.     /**
  102.      * SINGLE_TABLE means the class will be persisted according to the rules of
  103.      * <tt>Single Table Inheritance</tt>.
  104.      */
  105.     public const INHERITANCE_TYPE_SINGLE_TABLE 3;
  106.     /**
  107.      * TABLE_PER_CLASS means the class will be persisted according to the rules
  108.      * of <tt>Concrete Table Inheritance</tt>.
  109.      */
  110.     public const INHERITANCE_TYPE_TABLE_PER_CLASS 4;
  111.     /* The Id generator types. */
  112.     /**
  113.      * AUTO means the generator type will depend on what the used platform prefers.
  114.      * Offers full portability.
  115.      */
  116.     public const GENERATOR_TYPE_AUTO 1;
  117.     /**
  118.      * SEQUENCE means a separate sequence object will be used. Platforms that do
  119.      * not have native sequence support may emulate it. Full portability is currently
  120.      * not guaranteed.
  121.      */
  122.     public const GENERATOR_TYPE_SEQUENCE 2;
  123.     /**
  124.      * TABLE means a separate table is used for id generation.
  125.      * Offers full portability (in that it results in an exception being thrown
  126.      * no matter the platform).
  127.      *
  128.      * @deprecated no replacement planned
  129.      */
  130.     public const GENERATOR_TYPE_TABLE 3;
  131.     /**
  132.      * IDENTITY means an identity column is used for id generation. The database
  133.      * will fill in the id column on insertion. Platforms that do not support
  134.      * native identity columns may emulate them. Full portability is currently
  135.      * not guaranteed.
  136.      */
  137.     public const GENERATOR_TYPE_IDENTITY 4;
  138.     /**
  139.      * NONE means the class does not have a generated id. That means the class
  140.      * must have a natural, manually assigned id.
  141.      */
  142.     public const GENERATOR_TYPE_NONE 5;
  143.     /**
  144.      * UUID means that a UUID/GUID expression is used for id generation. Full
  145.      * portability is currently not guaranteed.
  146.      *
  147.      * @deprecated use an application-side generator instead
  148.      */
  149.     public const GENERATOR_TYPE_UUID 6;
  150.     /**
  151.      * CUSTOM means that customer will use own ID generator that supposedly work
  152.      */
  153.     public const GENERATOR_TYPE_CUSTOM 7;
  154.     /**
  155.      * DEFERRED_IMPLICIT means that changes of entities are calculated at commit-time
  156.      * by doing a property-by-property comparison with the original data. This will
  157.      * be done for all entities that are in MANAGED state at commit-time.
  158.      *
  159.      * This is the default change tracking policy.
  160.      */
  161.     public const CHANGETRACKING_DEFERRED_IMPLICIT 1;
  162.     /**
  163.      * DEFERRED_EXPLICIT means that changes of entities are calculated at commit-time
  164.      * by doing a property-by-property comparison with the original data. This will
  165.      * be done only for entities that were explicitly saved (through persist() or a cascade).
  166.      */
  167.     public const CHANGETRACKING_DEFERRED_EXPLICIT 2;
  168.     /**
  169.      * NOTIFY means that Doctrine relies on the entities sending out notifications
  170.      * when their properties change. Such entity classes must implement
  171.      * the <tt>NotifyPropertyChanged</tt> interface.
  172.      */
  173.     public const CHANGETRACKING_NOTIFY 3;
  174.     /**
  175.      * Specifies that an association is to be fetched when it is first accessed.
  176.      */
  177.     public const FETCH_LAZY 2;
  178.     /**
  179.      * Specifies that an association is to be fetched when the owner of the
  180.      * association is fetched.
  181.      */
  182.     public const FETCH_EAGER 3;
  183.     /**
  184.      * Specifies that an association is to be fetched lazy (on first access) and that
  185.      * commands such as Collection#count, Collection#slice are issued directly against
  186.      * the database if the collection is not yet initialized.
  187.      */
  188.     public const FETCH_EXTRA_LAZY 4;
  189.     /**
  190.      * Identifies a one-to-one association.
  191.      */
  192.     public const ONE_TO_ONE 1;
  193.     /**
  194.      * Identifies a many-to-one association.
  195.      */
  196.     public const MANY_TO_ONE 2;
  197.     /**
  198.      * Identifies a one-to-many association.
  199.      */
  200.     public const ONE_TO_MANY 4;
  201.     /**
  202.      * Identifies a many-to-many association.
  203.      */
  204.     public const MANY_TO_MANY 8;
  205.     /**
  206.      * Combined bitmask for to-one (single-valued) associations.
  207.      */
  208.     public const TO_ONE 3;
  209.     /**
  210.      * Combined bitmask for to-many (collection-valued) associations.
  211.      */
  212.     public const TO_MANY 12;
  213.     /**
  214.      * ReadOnly cache can do reads, inserts and deletes, cannot perform updates or employ any locks,
  215.      */
  216.     public const CACHE_USAGE_READ_ONLY 1;
  217.     /**
  218.      * Nonstrict Read Write Cache doesn’t employ any locks but can do inserts, update and deletes.
  219.      */
  220.     public const CACHE_USAGE_NONSTRICT_READ_WRITE 2;
  221.     /**
  222.      * Read Write Attempts to lock the entity before update/delete.
  223.      */
  224.     public const CACHE_USAGE_READ_WRITE 3;
  225.     /**
  226.      * READ-ONLY: The name of the entity class.
  227.      *
  228.      * @var string
  229.      * @psalm-var class-string<T>
  230.      */
  231.     public $name;
  232.     /**
  233.      * READ-ONLY: The namespace the entity class is contained in.
  234.      *
  235.      * @var string
  236.      * @todo Not really needed. Usage could be localized.
  237.      */
  238.     public $namespace;
  239.     /**
  240.      * READ-ONLY: The name of the entity class that is at the root of the mapped entity inheritance
  241.      * hierarchy. If the entity is not part of a mapped inheritance hierarchy this is the same
  242.      * as {@link $name}.
  243.      *
  244.      * @var string
  245.      * @psalm-var class-string
  246.      */
  247.     public $rootEntityName;
  248.     /**
  249.      * READ-ONLY: The definition of custom generator. Only used for CUSTOM
  250.      * generator type
  251.      *
  252.      * The definition has the following structure:
  253.      * <code>
  254.      * array(
  255.      *     'class' => 'ClassName',
  256.      * )
  257.      * </code>
  258.      *
  259.      * @todo Merge with tableGeneratorDefinition into generic generatorDefinition
  260.      * @var array<string, string>|null
  261.      */
  262.     public $customGeneratorDefinition;
  263.     /**
  264.      * The name of the custom repository class used for the entity class.
  265.      * (Optional).
  266.      *
  267.      * @var string|null
  268.      * @psalm-var ?class-string
  269.      */
  270.     public $customRepositoryClassName;
  271.     /**
  272.      * READ-ONLY: Whether this class describes the mapping of a mapped superclass.
  273.      *
  274.      * @var bool
  275.      */
  276.     public $isMappedSuperclass false;
  277.     /**
  278.      * READ-ONLY: Whether this class describes the mapping of an embeddable class.
  279.      *
  280.      * @var bool
  281.      */
  282.     public $isEmbeddedClass false;
  283.     /**
  284.      * READ-ONLY: The names of the parent classes (ancestors).
  285.      *
  286.      * @psalm-var list<class-string>
  287.      */
  288.     public $parentClasses = [];
  289.     /**
  290.      * READ-ONLY: The names of all subclasses (descendants).
  291.      *
  292.      * @psalm-var list<class-string>
  293.      */
  294.     public $subClasses = [];
  295.     /**
  296.      * READ-ONLY: The names of all embedded classes based on properties.
  297.      *
  298.      * @psalm-var array<string, mixed[]>
  299.      */
  300.     public $embeddedClasses = [];
  301.     /**
  302.      * READ-ONLY: The named queries allowed to be called directly from Repository.
  303.      *
  304.      * @psalm-var array<string, array<string, mixed>>
  305.      */
  306.     public $namedQueries = [];
  307.     /**
  308.      * READ-ONLY: The named native queries allowed to be called directly from Repository.
  309.      *
  310.      * A native SQL named query definition has the following structure:
  311.      * <pre>
  312.      * array(
  313.      *     'name'               => <query name>,
  314.      *     'query'              => <sql query>,
  315.      *     'resultClass'        => <class of the result>,
  316.      *     'resultSetMapping'   => <name of a SqlResultSetMapping>
  317.      * )
  318.      * </pre>
  319.      *
  320.      * @psalm-var array<string, array<string, mixed>>
  321.      */
  322.     public $namedNativeQueries = [];
  323.     /**
  324.      * READ-ONLY: The mappings of the results of native SQL queries.
  325.      *
  326.      * A native result mapping definition has the following structure:
  327.      * <pre>
  328.      * array(
  329.      *     'name'               => <result name>,
  330.      *     'entities'           => array(<entity result mapping>),
  331.      *     'columns'            => array(<column result mapping>)
  332.      * )
  333.      * </pre>
  334.      *
  335.      * @psalm-var array<string, array{
  336.      *                name: string,
  337.      *                entities: mixed[],
  338.      *                columns: mixed[]
  339.      *            }>
  340.      */
  341.     public $sqlResultSetMappings = [];
  342.     /**
  343.      * READ-ONLY: The field names of all fields that are part of the identifier/primary key
  344.      * of the mapped entity class.
  345.      *
  346.      * @psalm-var list<string>
  347.      */
  348.     public $identifier = [];
  349.     /**
  350.      * READ-ONLY: The inheritance mapping type used by the class.
  351.      *
  352.      * @var int
  353.      * @psalm-var self::$INHERITANCE_TYPE_*
  354.      */
  355.     public $inheritanceType self::INHERITANCE_TYPE_NONE;
  356.     /**
  357.      * READ-ONLY: The Id generator type used by the class.
  358.      *
  359.      * @var int
  360.      */
  361.     public $generatorType self::GENERATOR_TYPE_NONE;
  362.     /**
  363.      * READ-ONLY: The field mappings of the class.
  364.      * Keys are field names and values are mapping definitions.
  365.      *
  366.      * The mapping definition array has the following values:
  367.      *
  368.      * - <b>fieldName</b> (string)
  369.      * The name of the field in the Entity.
  370.      *
  371.      * - <b>type</b> (string)
  372.      * The type name of the mapped field. Can be one of Doctrine's mapping types
  373.      * or a custom mapping type.
  374.      *
  375.      * - <b>columnName</b> (string, optional)
  376.      * The column name. Optional. Defaults to the field name.
  377.      *
  378.      * - <b>length</b> (integer, optional)
  379.      * The database length of the column. Optional. Default value taken from
  380.      * the type.
  381.      *
  382.      * - <b>id</b> (boolean, optional)
  383.      * Marks the field as the primary key of the entity. Multiple fields of an
  384.      * entity can have the id attribute, forming a composite key.
  385.      *
  386.      * - <b>nullable</b> (boolean, optional)
  387.      * Whether the column is nullable. Defaults to FALSE.
  388.      *
  389.      * - <b>columnDefinition</b> (string, optional, schema-only)
  390.      * The SQL fragment that is used when generating the DDL for the column.
  391.      *
  392.      * - <b>precision</b> (integer, optional, schema-only)
  393.      * The precision of a decimal column. Only valid if the column type is decimal.
  394.      *
  395.      * - <b>scale</b> (integer, optional, schema-only)
  396.      * The scale of a decimal column. Only valid if the column type is decimal.
  397.      *
  398.      * - <b>'unique'</b> (string, optional, schema-only)
  399.      * Whether a unique constraint should be generated for the column.
  400.      *
  401.      * @var mixed[]
  402.      * @psalm-var array<string, FieldMapping>
  403.      */
  404.     public $fieldMappings = [];
  405.     /**
  406.      * READ-ONLY: An array of field names. Used to look up field names from column names.
  407.      * Keys are column names and values are field names.
  408.      *
  409.      * @psalm-var array<string, string>
  410.      */
  411.     public $fieldNames = [];
  412.     /**
  413.      * READ-ONLY: A map of field names to column names. Keys are field names and values column names.
  414.      * Used to look up column names from field names.
  415.      * This is the reverse lookup map of $_fieldNames.
  416.      *
  417.      * @deprecated 3.0 Remove this.
  418.      *
  419.      * @var mixed[]
  420.      */
  421.     public $columnNames = [];
  422.     /**
  423.      * READ-ONLY: The discriminator value of this class.
  424.      *
  425.      * <b>This does only apply to the JOINED and SINGLE_TABLE inheritance mapping strategies
  426.      * where a discriminator column is used.</b>
  427.      *
  428.      * @see discriminatorColumn
  429.      *
  430.      * @var mixed
  431.      */
  432.     public $discriminatorValue;
  433.     /**
  434.      * READ-ONLY: The discriminator map of all mapped classes in the hierarchy.
  435.      *
  436.      * <b>This does only apply to the JOINED and SINGLE_TABLE inheritance mapping strategies
  437.      * where a discriminator column is used.</b>
  438.      *
  439.      * @see discriminatorColumn
  440.      *
  441.      * @var mixed
  442.      */
  443.     public $discriminatorMap = [];
  444.     /**
  445.      * READ-ONLY: The definition of the discriminator column used in JOINED and SINGLE_TABLE
  446.      * inheritance mappings.
  447.      *
  448.      * @psalm-var array<string, mixed>|null
  449.      */
  450.     public $discriminatorColumn;
  451.     /**
  452.      * READ-ONLY: The primary table definition. The definition is an array with the
  453.      * following entries:
  454.      *
  455.      * name => <tableName>
  456.      * schema => <schemaName>
  457.      * indexes => array
  458.      * uniqueConstraints => array
  459.      *
  460.      * @var mixed[]
  461.      * @psalm-var array{
  462.      *               name: string,
  463.      *               schema: string,
  464.      *               indexes: array,
  465.      *               uniqueConstraints: array,
  466.      *               options: array<string, mixed>,
  467.      *               quoted?: bool
  468.      *           }
  469.      */
  470.     public $table;
  471.     /**
  472.      * READ-ONLY: The registered lifecycle callbacks for entities of this class.
  473.      *
  474.      * @psalm-var array<string, list<string>>
  475.      */
  476.     public $lifecycleCallbacks = [];
  477.     /**
  478.      * READ-ONLY: The registered entity listeners.
  479.      *
  480.      * @psalm-var array<string, list<array{class: class-string, method: string}>>
  481.      */
  482.     public $entityListeners = [];
  483.     /**
  484.      * READ-ONLY: The association mappings of this class.
  485.      *
  486.      * The mapping definition array supports the following keys:
  487.      *
  488.      * - <b>fieldName</b> (string)
  489.      * The name of the field in the entity the association is mapped to.
  490.      *
  491.      * - <b>targetEntity</b> (string)
  492.      * The class name of the target entity. If it is fully-qualified it is used as is.
  493.      * If it is a simple, unqualified class name the namespace is assumed to be the same
  494.      * as the namespace of the source entity.
  495.      *
  496.      * - <b>mappedBy</b> (string, required for bidirectional associations)
  497.      * The name of the field that completes the bidirectional association on the owning side.
  498.      * This key must be specified on the inverse side of a bidirectional association.
  499.      *
  500.      * - <b>inversedBy</b> (string, required for bidirectional associations)
  501.      * The name of the field that completes the bidirectional association on the inverse side.
  502.      * This key must be specified on the owning side of a bidirectional association.
  503.      *
  504.      * - <b>cascade</b> (array, optional)
  505.      * The names of persistence operations to cascade on the association. The set of possible
  506.      * values are: "persist", "remove", "detach", "merge", "refresh", "all" (implies all others).
  507.      *
  508.      * - <b>orderBy</b> (array, one-to-many/many-to-many only)
  509.      * A map of field names (of the target entity) to sorting directions (ASC/DESC).
  510.      * Example: array('priority' => 'desc')
  511.      *
  512.      * - <b>fetch</b> (integer, optional)
  513.      * The fetching strategy to use for the association, usually defaults to FETCH_LAZY.
  514.      * Possible values are: ClassMetadata::FETCH_EAGER, ClassMetadata::FETCH_LAZY.
  515.      *
  516.      * - <b>joinTable</b> (array, optional, many-to-many only)
  517.      * Specification of the join table and its join columns (foreign keys).
  518.      * Only valid for many-to-many mappings. Note that one-to-many associations can be mapped
  519.      * through a join table by simply mapping the association as many-to-many with a unique
  520.      * constraint on the join table.
  521.      *
  522.      * - <b>indexBy</b> (string, optional, to-many only)
  523.      * Specification of a field on target-entity that is used to index the collection by.
  524.      * This field HAS to be either the primary key or a unique column. Otherwise the collection
  525.      * does not contain all the entities that are actually related.
  526.      *
  527.      * A join table definition has the following structure:
  528.      * <pre>
  529.      * array(
  530.      *     'name' => <join table name>,
  531.      *      'joinColumns' => array(<join column mapping from join table to source table>),
  532.      *      'inverseJoinColumns' => array(<join column mapping from join table to target table>)
  533.      * )
  534.      * </pre>
  535.      *
  536.      * @psalm-var array<string, array<string, mixed>>
  537.      */
  538.     public $associationMappings = [];
  539.     /**
  540.      * READ-ONLY: Flag indicating whether the identifier/primary key of the class is composite.
  541.      *
  542.      * @var bool
  543.      */
  544.     public $isIdentifierComposite false;
  545.     /**
  546.      * READ-ONLY: Flag indicating whether the identifier/primary key contains at least one foreign key association.
  547.      *
  548.      * This flag is necessary because some code blocks require special treatment of this cases.
  549.      *
  550.      * @var bool
  551.      */
  552.     public $containsForeignIdentifier false;
  553.     /**
  554.      * READ-ONLY: The ID generator used for generating IDs for this class.
  555.      *
  556.      * @var AbstractIdGenerator
  557.      * @todo Remove!
  558.      */
  559.     public $idGenerator;
  560.     /**
  561.      * READ-ONLY: The definition of the sequence generator of this class. Only used for the
  562.      * SEQUENCE generation strategy.
  563.      *
  564.      * The definition has the following structure:
  565.      * <code>
  566.      * array(
  567.      *     'sequenceName' => 'name',
  568.      *     'allocationSize' => '20',
  569.      *     'initialValue' => '1'
  570.      * )
  571.      * </code>
  572.      *
  573.      * @var array<string, mixed>
  574.      * @psalm-var array{sequenceName: string, allocationSize: string, initialValue: string, quoted?: mixed}
  575.      * @todo Merge with tableGeneratorDefinition into generic generatorDefinition
  576.      */
  577.     public $sequenceGeneratorDefinition;
  578.     /**
  579.      * READ-ONLY: The definition of the table generator of this class. Only used for the
  580.      * TABLE generation strategy.
  581.      *
  582.      * @deprecated
  583.      *
  584.      * @var array<string, mixed>
  585.      */
  586.     public $tableGeneratorDefinition;
  587.     /**
  588.      * READ-ONLY: The policy used for change-tracking on entities of this class.
  589.      *
  590.      * @var int
  591.      */
  592.     public $changeTrackingPolicy self::CHANGETRACKING_DEFERRED_IMPLICIT;
  593.     /**
  594.      * READ-ONLY: A flag for whether or not instances of this class are to be versioned
  595.      * with optimistic locking.
  596.      *
  597.      * @var bool
  598.      */
  599.     public $isVersioned;
  600.     /**
  601.      * READ-ONLY: The name of the field which is used for versioning in optimistic locking (if any).
  602.      *
  603.      * @var mixed
  604.      */
  605.     public $versionField;
  606.     /** @var mixed[] */
  607.     public $cache null;
  608.     /**
  609.      * The ReflectionClass instance of the mapped class.
  610.      *
  611.      * @var ReflectionClass|null
  612.      */
  613.     public $reflClass;
  614.     /**
  615.      * Is this entity marked as "read-only"?
  616.      *
  617.      * That means it is never considered for change-tracking in the UnitOfWork. It is a very helpful performance
  618.      * optimization for entities that are immutable, either in your domain or through the relation database
  619.      * (coming from a view, or a history table for example).
  620.      *
  621.      * @var bool
  622.      */
  623.     public $isReadOnly false;
  624.     /**
  625.      * NamingStrategy determining the default column and table names.
  626.      *
  627.      * @var NamingStrategy
  628.      */
  629.     protected $namingStrategy;
  630.     /**
  631.      * The ReflectionProperty instances of the mapped class.
  632.      *
  633.      * @var ReflectionProperty[]|null[]
  634.      */
  635.     public $reflFields = [];
  636.     /** @var InstantiatorInterface|null */
  637.     private $instantiator;
  638.     /**
  639.      * Initializes a new ClassMetadata instance that will hold the object-relational mapping
  640.      * metadata of the class with the given name.
  641.      *
  642.      * @param string $entityName The name of the entity class the new instance is used for.
  643.      * @psalm-param class-string<T> $entityName
  644.      */
  645.     public function __construct($entityName, ?NamingStrategy $namingStrategy null)
  646.     {
  647.         $this->name           $entityName;
  648.         $this->rootEntityName $entityName;
  649.         $this->namingStrategy $namingStrategy ?: new DefaultNamingStrategy();
  650.         $this->instantiator   = new Instantiator();
  651.     }
  652.     /**
  653.      * Gets the ReflectionProperties of the mapped class.
  654.      *
  655.      * @return ReflectionProperty[]|null[] An array of ReflectionProperty instances.
  656.      * @psalm-return array<ReflectionProperty|null>
  657.      */
  658.     public function getReflectionProperties()
  659.     {
  660.         return $this->reflFields;
  661.     }
  662.     /**
  663.      * Gets a ReflectionProperty for a specific field of the mapped class.
  664.      *
  665.      * @param string $name
  666.      *
  667.      * @return ReflectionProperty
  668.      */
  669.     public function getReflectionProperty($name)
  670.     {
  671.         return $this->reflFields[$name];
  672.     }
  673.     /**
  674.      * Gets the ReflectionProperty for the single identifier field.
  675.      *
  676.      * @return ReflectionProperty
  677.      *
  678.      * @throws BadMethodCallException If the class has a composite identifier.
  679.      */
  680.     public function getSingleIdReflectionProperty()
  681.     {
  682.         if ($this->isIdentifierComposite) {
  683.             throw new BadMethodCallException('Class ' $this->name ' has a composite identifier.');
  684.         }
  685.         return $this->reflFields[$this->identifier[0]];
  686.     }
  687.     /**
  688.      * Extracts the identifier values of an entity of this class.
  689.      *
  690.      * For composite identifiers, the identifier values are returned as an array
  691.      * with the same order as the field order in {@link identifier}.
  692.      *
  693.      * @param object $entity
  694.      *
  695.      * @return array<string, mixed>
  696.      */
  697.     public function getIdentifierValues($entity)
  698.     {
  699.         if ($this->isIdentifierComposite) {
  700.             $id = [];
  701.             foreach ($this->identifier as $idField) {
  702.                 $value $this->reflFields[$idField]->getValue($entity);
  703.                 if ($value !== null) {
  704.                     $id[$idField] = $value;
  705.                 }
  706.             }
  707.             return $id;
  708.         }
  709.         $id    $this->identifier[0];
  710.         $value $this->reflFields[$id]->getValue($entity);
  711.         if ($value === null) {
  712.             return [];
  713.         }
  714.         return [$id => $value];
  715.     }
  716.     /**
  717.      * Populates the entity identifier of an entity.
  718.      *
  719.      * @param object $entity
  720.      * @psalm-param array<string, mixed> $id
  721.      *
  722.      * @return void
  723.      *
  724.      * @todo Rename to assignIdentifier()
  725.      */
  726.     public function setIdentifierValues($entity, array $id)
  727.     {
  728.         foreach ($id as $idField => $idValue) {
  729.             $this->reflFields[$idField]->setValue($entity$idValue);
  730.         }
  731.     }
  732.     /**
  733.      * Sets the specified field to the specified value on the given entity.
  734.      *
  735.      * @param object $entity
  736.      * @param string $field
  737.      * @param mixed  $value
  738.      *
  739.      * @return void
  740.      */
  741.     public function setFieldValue($entity$field$value)
  742.     {
  743.         $this->reflFields[$field]->setValue($entity$value);
  744.     }
  745.     /**
  746.      * Gets the specified field's value off the given entity.
  747.      *
  748.      * @param object $entity
  749.      * @param string $field
  750.      *
  751.      * @return mixed
  752.      */
  753.     public function getFieldValue($entity$field)
  754.     {
  755.         return $this->reflFields[$field]->getValue($entity);
  756.     }
  757.     /**
  758.      * Creates a string representation of this instance.
  759.      *
  760.      * @return string The string representation of this instance.
  761.      *
  762.      * @todo Construct meaningful string representation.
  763.      */
  764.     public function __toString()
  765.     {
  766.         return self::class . '@' spl_object_id($this);
  767.     }
  768.     /**
  769.      * Determines which fields get serialized.
  770.      *
  771.      * It is only serialized what is necessary for best unserialization performance.
  772.      * That means any metadata properties that are not set or empty or simply have
  773.      * their default value are NOT serialized.
  774.      *
  775.      * Parts that are also NOT serialized because they can not be properly unserialized:
  776.      *      - reflClass (ReflectionClass)
  777.      *      - reflFields (ReflectionProperty array)
  778.      *
  779.      * @return string[] The names of all the fields that should be serialized.
  780.      */
  781.     public function __sleep()
  782.     {
  783.         // This metadata is always serialized/cached.
  784.         $serialized = [
  785.             'associationMappings',
  786.             'columnNames'//TODO: 3.0 Remove this. Can use fieldMappings[$fieldName]['columnName']
  787.             'fieldMappings',
  788.             'fieldNames',
  789.             'embeddedClasses',
  790.             'identifier',
  791.             'isIdentifierComposite'// TODO: REMOVE
  792.             'name',
  793.             'namespace'// TODO: REMOVE
  794.             'table',
  795.             'rootEntityName',
  796.             'idGenerator'//TODO: Does not really need to be serialized. Could be moved to runtime.
  797.         ];
  798.         // The rest of the metadata is only serialized if necessary.
  799.         if ($this->changeTrackingPolicy !== self::CHANGETRACKING_DEFERRED_IMPLICIT) {
  800.             $serialized[] = 'changeTrackingPolicy';
  801.         }
  802.         if ($this->customRepositoryClassName) {
  803.             $serialized[] = 'customRepositoryClassName';
  804.         }
  805.         if ($this->inheritanceType !== self::INHERITANCE_TYPE_NONE) {
  806.             $serialized[] = 'inheritanceType';
  807.             $serialized[] = 'discriminatorColumn';
  808.             $serialized[] = 'discriminatorValue';
  809.             $serialized[] = 'discriminatorMap';
  810.             $serialized[] = 'parentClasses';
  811.             $serialized[] = 'subClasses';
  812.         }
  813.         if ($this->generatorType !== self::GENERATOR_TYPE_NONE) {
  814.             $serialized[] = 'generatorType';
  815.             if ($this->generatorType === self::GENERATOR_TYPE_SEQUENCE) {
  816.                 $serialized[] = 'sequenceGeneratorDefinition';
  817.             }
  818.         }
  819.         if ($this->isMappedSuperclass) {
  820.             $serialized[] = 'isMappedSuperclass';
  821.         }
  822.         if ($this->isEmbeddedClass) {
  823.             $serialized[] = 'isEmbeddedClass';
  824.         }
  825.         if ($this->containsForeignIdentifier) {
  826.             $serialized[] = 'containsForeignIdentifier';
  827.         }
  828.         if ($this->isVersioned) {
  829.             $serialized[] = 'isVersioned';
  830.             $serialized[] = 'versionField';
  831.         }
  832.         if ($this->lifecycleCallbacks) {
  833.             $serialized[] = 'lifecycleCallbacks';
  834.         }
  835.         if ($this->entityListeners) {
  836.             $serialized[] = 'entityListeners';
  837.         }
  838.         if ($this->namedQueries) {
  839.             $serialized[] = 'namedQueries';
  840.         }
  841.         if ($this->namedNativeQueries) {
  842.             $serialized[] = 'namedNativeQueries';
  843.         }
  844.         if ($this->sqlResultSetMappings) {
  845.             $serialized[] = 'sqlResultSetMappings';
  846.         }
  847.         if ($this->isReadOnly) {
  848.             $serialized[] = 'isReadOnly';
  849.         }
  850.         if ($this->customGeneratorDefinition) {
  851.             $serialized[] = 'customGeneratorDefinition';
  852.         }
  853.         if ($this->cache) {
  854.             $serialized[] = 'cache';
  855.         }
  856.         return $serialized;
  857.     }
  858.     /**
  859.      * Creates a new instance of the mapped class, without invoking the constructor.
  860.      *
  861.      * @return object
  862.      */
  863.     public function newInstance()
  864.     {
  865.         return $this->instantiator->instantiate($this->name);
  866.     }
  867.     /**
  868.      * Restores some state that can not be serialized/unserialized.
  869.      *
  870.      * @param ReflectionService $reflService
  871.      *
  872.      * @return void
  873.      */
  874.     public function wakeupReflection($reflService)
  875.     {
  876.         // Restore ReflectionClass and properties
  877.         $this->reflClass    $reflService->getClass($this->name);
  878.         $this->instantiator $this->instantiator ?: new Instantiator();
  879.         $parentReflFields = [];
  880.         foreach ($this->embeddedClasses as $property => $embeddedClass) {
  881.             if (isset($embeddedClass['declaredField'])) {
  882.                 $childProperty $reflService->getAccessibleProperty(
  883.                     $this->embeddedClasses[$embeddedClass['declaredField']]['class'],
  884.                     $embeddedClass['originalField']
  885.                 );
  886.                 assert($childProperty !== null);
  887.                 $parentReflFields[$property] = new ReflectionEmbeddedProperty(
  888.                     $parentReflFields[$embeddedClass['declaredField']],
  889.                     $childProperty,
  890.                     $this->embeddedClasses[$embeddedClass['declaredField']]['class']
  891.                 );
  892.                 continue;
  893.             }
  894.             $fieldRefl $reflService->getAccessibleProperty(
  895.                 $embeddedClass['declared'] ?? $this->name,
  896.                 $property
  897.             );
  898.             $parentReflFields[$property] = $fieldRefl;
  899.             $this->reflFields[$property] = $fieldRefl;
  900.         }
  901.         foreach ($this->fieldMappings as $field => $mapping) {
  902.             if (isset($mapping['declaredField']) && isset($parentReflFields[$mapping['declaredField']])) {
  903.                 $this->reflFields[$field] = new ReflectionEmbeddedProperty(
  904.                     $parentReflFields[$mapping['declaredField']],
  905.                     $reflService->getAccessibleProperty($mapping['originalClass'], $mapping['originalField']),
  906.                     $mapping['originalClass']
  907.                 );
  908.                 continue;
  909.             }
  910.             $this->reflFields[$field] = isset($mapping['declared'])
  911.                 ? $reflService->getAccessibleProperty($mapping['declared'], $field)
  912.                 : $reflService->getAccessibleProperty($this->name$field);
  913.         }
  914.         foreach ($this->associationMappings as $field => $mapping) {
  915.             $this->reflFields[$field] = isset($mapping['declared'])
  916.                 ? $reflService->getAccessibleProperty($mapping['declared'], $field)
  917.                 : $reflService->getAccessibleProperty($this->name$field);
  918.         }
  919.     }
  920.     /**
  921.      * Initializes a new ClassMetadata instance that will hold the object-relational mapping
  922.      * metadata of the class with the given name.
  923.      *
  924.      * @param ReflectionService $reflService The reflection service.
  925.      *
  926.      * @return void
  927.      */
  928.     public function initializeReflection($reflService)
  929.     {
  930.         $this->reflClass $reflService->getClass($this->name);
  931.         $this->namespace $reflService->getClassNamespace($this->name);
  932.         if ($this->reflClass) {
  933.             $this->name $this->rootEntityName $this->reflClass->getName();
  934.         }
  935.         $this->table['name'] = $this->namingStrategy->classToTableName($this->name);
  936.     }
  937.     /**
  938.      * Validates Identifier.
  939.      *
  940.      * @return void
  941.      *
  942.      * @throws MappingException
  943.      */
  944.     public function validateIdentifier()
  945.     {
  946.         if ($this->isMappedSuperclass || $this->isEmbeddedClass) {
  947.             return;
  948.         }
  949.         // Verify & complete identifier mapping
  950.         if (! $this->identifier) {
  951.             throw MappingException::identifierRequired($this->name);
  952.         }
  953.         if ($this->usesIdGenerator() && $this->isIdentifierComposite) {
  954.             throw MappingException::compositeKeyAssignedIdGeneratorRequired($this->name);
  955.         }
  956.     }
  957.     /**
  958.      * Validates association targets actually exist.
  959.      *
  960.      * @return void
  961.      *
  962.      * @throws MappingException
  963.      */
  964.     public function validateAssociations()
  965.     {
  966.         foreach ($this->associationMappings as $mapping) {
  967.             if (
  968.                 ! class_exists($mapping['targetEntity'])
  969.                 && ! interface_exists($mapping['targetEntity'])
  970.                 && ! trait_exists($mapping['targetEntity'])
  971.             ) {
  972.                 throw MappingException::invalidTargetEntityClass($mapping['targetEntity'], $this->name$mapping['fieldName']);
  973.             }
  974.         }
  975.     }
  976.     /**
  977.      * Validates lifecycle callbacks.
  978.      *
  979.      * @param ReflectionService $reflService
  980.      *
  981.      * @return void
  982.      *
  983.      * @throws MappingException
  984.      */
  985.     public function validateLifecycleCallbacks($reflService)
  986.     {
  987.         foreach ($this->lifecycleCallbacks as $callbacks) {
  988.             foreach ($callbacks as $callbackFuncName) {
  989.                 if (! $reflService->hasPublicMethod($this->name$callbackFuncName)) {
  990.                     throw MappingException::lifecycleCallbackMethodNotFound($this->name$callbackFuncName);
  991.                 }
  992.             }
  993.         }
  994.     }
  995.     /**
  996.      * {@inheritDoc}
  997.      */
  998.     public function getReflectionClass()
  999.     {
  1000.         return $this->reflClass;
  1001.     }
  1002.     /**
  1003.      * @psalm-param array{usage?: mixed, region?: mixed} $cache
  1004.      *
  1005.      * @return void
  1006.      */
  1007.     public function enableCache(array $cache)
  1008.     {
  1009.         if (! isset($cache['usage'])) {
  1010.             $cache['usage'] = self::CACHE_USAGE_READ_ONLY;
  1011.         }
  1012.         if (! isset($cache['region'])) {
  1013.             $cache['region'] = strtolower(str_replace('\\''_'$this->rootEntityName));
  1014.         }
  1015.         $this->cache $cache;
  1016.     }
  1017.     /**
  1018.      * @param string $fieldName
  1019.      * @psalm-param array{usage?: int, region?: string} $cache
  1020.      *
  1021.      * @return void
  1022.      */
  1023.     public function enableAssociationCache($fieldName, array $cache)
  1024.     {
  1025.         $this->associationMappings[$fieldName]['cache'] = $this->getAssociationCacheDefaults($fieldName$cache);
  1026.     }
  1027.     /**
  1028.      * @param string $fieldName
  1029.      * @param array  $cache
  1030.      * @psalm-param array{usage?: int, region?: string|null} $cache
  1031.      *
  1032.      * @return int[]|string[]
  1033.      * @psalm-return array{usage: int, region: string|null}
  1034.      */
  1035.     public function getAssociationCacheDefaults($fieldName, array $cache)
  1036.     {
  1037.         if (! isset($cache['usage'])) {
  1038.             $cache['usage'] = $this->cache['usage'] ?? self::CACHE_USAGE_READ_ONLY;
  1039.         }
  1040.         if (! isset($cache['region'])) {
  1041.             $cache['region'] = strtolower(str_replace('\\''_'$this->rootEntityName)) . '__' $fieldName;
  1042.         }
  1043.         return $cache;
  1044.     }
  1045.     /**
  1046.      * Sets the change tracking policy used by this class.
  1047.      *
  1048.      * @param int $policy
  1049.      *
  1050.      * @return void
  1051.      */
  1052.     public function setChangeTrackingPolicy($policy)
  1053.     {
  1054.         $this->changeTrackingPolicy $policy;
  1055.     }
  1056.     /**
  1057.      * Whether the change tracking policy of this class is "deferred explicit".
  1058.      *
  1059.      * @return bool
  1060.      */
  1061.     public function isChangeTrackingDeferredExplicit()
  1062.     {
  1063.         return $this->changeTrackingPolicy === self::CHANGETRACKING_DEFERRED_EXPLICIT;
  1064.     }
  1065.     /**
  1066.      * Whether the change tracking policy of this class is "deferred implicit".
  1067.      *
  1068.      * @return bool
  1069.      */
  1070.     public function isChangeTrackingDeferredImplicit()
  1071.     {
  1072.         return $this->changeTrackingPolicy === self::CHANGETRACKING_DEFERRED_IMPLICIT;
  1073.     }
  1074.     /**
  1075.      * Whether the change tracking policy of this class is "notify".
  1076.      *
  1077.      * @return bool
  1078.      */
  1079.     public function isChangeTrackingNotify()
  1080.     {
  1081.         return $this->changeTrackingPolicy === self::CHANGETRACKING_NOTIFY;
  1082.     }
  1083.     /**
  1084.      * Checks whether a field is part of the identifier/primary key field(s).
  1085.      *
  1086.      * @param string $fieldName The field name.
  1087.      *
  1088.      * @return bool TRUE if the field is part of the table identifier/primary key field(s),
  1089.      * FALSE otherwise.
  1090.      */
  1091.     public function isIdentifier($fieldName)
  1092.     {
  1093.         if (! $this->identifier) {
  1094.             return false;
  1095.         }
  1096.         if (! $this->isIdentifierComposite) {
  1097.             return $fieldName === $this->identifier[0];
  1098.         }
  1099.         return in_array($fieldName$this->identifiertrue);
  1100.     }
  1101.     /**
  1102.      * Checks if the field is unique.
  1103.      *
  1104.      * @param string $fieldName The field name.
  1105.      *
  1106.      * @return bool TRUE if the field is unique, FALSE otherwise.
  1107.      */
  1108.     public function isUniqueField($fieldName)
  1109.     {
  1110.         $mapping $this->getFieldMapping($fieldName);
  1111.         return $mapping !== false && isset($mapping['unique']) && $mapping['unique'];
  1112.     }
  1113.     /**
  1114.      * Checks if the field is not null.
  1115.      *
  1116.      * @param string $fieldName The field name.
  1117.      *
  1118.      * @return bool TRUE if the field is not null, FALSE otherwise.
  1119.      */
  1120.     public function isNullable($fieldName)
  1121.     {
  1122.         $mapping $this->getFieldMapping($fieldName);
  1123.         return $mapping !== false && isset($mapping['nullable']) && $mapping['nullable'];
  1124.     }
  1125.     /**
  1126.      * Gets a column name for a field name.
  1127.      * If the column name for the field cannot be found, the given field name
  1128.      * is returned.
  1129.      *
  1130.      * @param string $fieldName The field name.
  1131.      *
  1132.      * @return string The column name.
  1133.      */
  1134.     public function getColumnName($fieldName)
  1135.     {
  1136.         return $this->columnNames[$fieldName] ?? $fieldName;
  1137.     }
  1138.     /**
  1139.      * Gets the mapping of a (regular) field that holds some data but not a
  1140.      * reference to another object.
  1141.      *
  1142.      * @param string $fieldName The field name.
  1143.      *
  1144.      * @return mixed[] The field mapping.
  1145.      * @psalm-return FieldMapping
  1146.      *
  1147.      * @throws MappingException
  1148.      */
  1149.     public function getFieldMapping($fieldName)
  1150.     {
  1151.         if (! isset($this->fieldMappings[$fieldName])) {
  1152.             throw MappingException::mappingNotFound($this->name$fieldName);
  1153.         }
  1154.         return $this->fieldMappings[$fieldName];
  1155.     }
  1156.     /**
  1157.      * Gets the mapping of an association.
  1158.      *
  1159.      * @see ClassMetadataInfo::$associationMappings
  1160.      *
  1161.      * @param string $fieldName The field name that represents the association in
  1162.      *                          the object model.
  1163.      *
  1164.      * @return mixed[] The mapping.
  1165.      * @psalm-return array<string, mixed>
  1166.      *
  1167.      * @throws MappingException
  1168.      */
  1169.     public function getAssociationMapping($fieldName)
  1170.     {
  1171.         if (! isset($this->associationMappings[$fieldName])) {
  1172.             throw MappingException::mappingNotFound($this->name$fieldName);
  1173.         }
  1174.         return $this->associationMappings[$fieldName];
  1175.     }
  1176.     /**
  1177.      * Gets all association mappings of the class.
  1178.      *
  1179.      * @psalm-return array<string, array<string, mixed>>
  1180.      */
  1181.     public function getAssociationMappings()
  1182.     {
  1183.         return $this->associationMappings;
  1184.     }
  1185.     /**
  1186.      * Gets the field name for a column name.
  1187.      * If no field name can be found the column name is returned.
  1188.      *
  1189.      * @param string $columnName The column name.
  1190.      *
  1191.      * @return string The column alias.
  1192.      */
  1193.     public function getFieldName($columnName)
  1194.     {
  1195.         return $this->fieldNames[$columnName] ?? $columnName;
  1196.     }
  1197.     /**
  1198.      * Gets the named query.
  1199.      *
  1200.      * @see ClassMetadataInfo::$namedQueries
  1201.      *
  1202.      * @param string $queryName The query name.
  1203.      *
  1204.      * @return string
  1205.      *
  1206.      * @throws MappingException
  1207.      */
  1208.     public function getNamedQuery($queryName)
  1209.     {
  1210.         if (! isset($this->namedQueries[$queryName])) {
  1211.             throw MappingException::queryNotFound($this->name$queryName);
  1212.         }
  1213.         return $this->namedQueries[$queryName]['dql'];
  1214.     }
  1215.     /**
  1216.      * Gets all named queries of the class.
  1217.      *
  1218.      * @return mixed[][]
  1219.      * @psalm-return array<string, array<string, mixed>>
  1220.      */
  1221.     public function getNamedQueries()
  1222.     {
  1223.         return $this->namedQueries;
  1224.     }
  1225.     /**
  1226.      * Gets the named native query.
  1227.      *
  1228.      * @see ClassMetadataInfo::$namedNativeQueries
  1229.      *
  1230.      * @param string $queryName The query name.
  1231.      *
  1232.      * @return mixed[]
  1233.      * @psalm-return array<string, mixed>
  1234.      *
  1235.      * @throws MappingException
  1236.      */
  1237.     public function getNamedNativeQuery($queryName)
  1238.     {
  1239.         if (! isset($this->namedNativeQueries[$queryName])) {
  1240.             throw MappingException::queryNotFound($this->name$queryName);
  1241.         }
  1242.         return $this->namedNativeQueries[$queryName];
  1243.     }
  1244.     /**
  1245.      * Gets all named native queries of the class.
  1246.      *
  1247.      * @psalm-return array<string, array<string, mixed>>
  1248.      */
  1249.     public function getNamedNativeQueries()
  1250.     {
  1251.         return $this->namedNativeQueries;
  1252.     }
  1253.     /**
  1254.      * Gets the result set mapping.
  1255.      *
  1256.      * @see ClassMetadataInfo::$sqlResultSetMappings
  1257.      *
  1258.      * @param string $name The result set mapping name.
  1259.      *
  1260.      * @return mixed[]
  1261.      * @psalm-return array{name: string, entities: array, columns: array}
  1262.      *
  1263.      * @throws MappingException
  1264.      */
  1265.     public function getSqlResultSetMapping($name)
  1266.     {
  1267.         if (! isset($this->sqlResultSetMappings[$name])) {
  1268.             throw MappingException::resultMappingNotFound($this->name$name);
  1269.         }
  1270.         return $this->sqlResultSetMappings[$name];
  1271.     }
  1272.     /**
  1273.      * Gets all sql result set mappings of the class.
  1274.      *
  1275.      * @return mixed[]
  1276.      * @psalm-return array<string, array{name: string, entities: array, columns: array}>
  1277.      */
  1278.     public function getSqlResultSetMappings()
  1279.     {
  1280.         return $this->sqlResultSetMappings;
  1281.     }
  1282.     /**
  1283.      * Checks whether given property has type
  1284.      *
  1285.      * @param string $name Property name
  1286.      */
  1287.     private function isTypedProperty(string $name): bool
  1288.     {
  1289.         return PHP_VERSION_ID >= 70400
  1290.                && isset($this->reflClass)
  1291.                && $this->reflClass->hasProperty($name)
  1292.                && $this->reflClass->getProperty($name)->hasType();
  1293.     }
  1294.     /**
  1295.      * Validates & completes the given field mapping based on typed property.
  1296.      *
  1297.      * @param  mixed[] $mapping The field mapping to validate & complete.
  1298.      *
  1299.      * @return mixed[] The updated mapping.
  1300.      */
  1301.     private function validateAndCompleteTypedFieldMapping(array $mapping): array
  1302.     {
  1303.         $type $this->reflClass->getProperty($mapping['fieldName'])->getType();
  1304.         if ($type) {
  1305.             if (
  1306.                 ! isset($mapping['type'])
  1307.                 && ($type instanceof ReflectionNamedType)
  1308.             ) {
  1309.                 switch ($type->getName()) {
  1310.                     case DateInterval::class:
  1311.                         $mapping['type'] = Types::DATEINTERVAL;
  1312.                         break;
  1313.                     case DateTime::class:
  1314.                         $mapping['type'] = Types::DATETIME_MUTABLE;
  1315.                         break;
  1316.                     case DateTimeImmutable::class:
  1317.                         $mapping['type'] = Types::DATETIME_IMMUTABLE;
  1318.                         break;
  1319.                     case 'array':
  1320.                         $mapping['type'] = Types::JSON;
  1321.                         break;
  1322.                     case 'bool':
  1323.                         $mapping['type'] = Types::BOOLEAN;
  1324.                         break;
  1325.                     case 'float':
  1326.                         $mapping['type'] = Types::FLOAT;
  1327.                         break;
  1328.                     case 'int':
  1329.                         $mapping['type'] = Types::INTEGER;
  1330.                         break;
  1331.                     case 'string':
  1332.                         $mapping['type'] = Types::STRING;
  1333.                         break;
  1334.                 }
  1335.             }
  1336.         }
  1337.         return $mapping;
  1338.     }
  1339.     /**
  1340.      * Validates & completes the basic mapping information based on typed property.
  1341.      *
  1342.      * @param mixed[] $mapping The mapping.
  1343.      *
  1344.      * @return mixed[] The updated mapping.
  1345.      */
  1346.     private function validateAndCompleteTypedAssociationMapping(array $mapping): array
  1347.     {
  1348.         $type $this->reflClass->getProperty($mapping['fieldName'])->getType();
  1349.         if ($type === null || ($mapping['type'] & self::TO_ONE) === 0) {
  1350.             return $mapping;
  1351.         }
  1352.         if (! isset($mapping['targetEntity']) && $type instanceof ReflectionNamedType) {
  1353.             $mapping['targetEntity'] = $type->getName();
  1354.         }
  1355.         return $mapping;
  1356.     }
  1357.     /**
  1358.      * Validates & completes the given field mapping.
  1359.      *
  1360.      * @psalm-param array<string, mixed> $mapping The field mapping to validate & complete.
  1361.      *
  1362.      * @return mixed[] The updated mapping.
  1363.      *
  1364.      * @throws MappingException
  1365.      */
  1366.     protected function validateAndCompleteFieldMapping(array $mapping): array
  1367.     {
  1368.         // Check mandatory fields
  1369.         if (! isset($mapping['fieldName']) || ! $mapping['fieldName']) {
  1370.             throw MappingException::missingFieldName($this->name);
  1371.         }
  1372.         if ($this->isTypedProperty($mapping['fieldName'])) {
  1373.             $mapping $this->validateAndCompleteTypedFieldMapping($mapping);
  1374.         }
  1375.         if (! isset($mapping['type'])) {
  1376.             // Default to string
  1377.             $mapping['type'] = 'string';
  1378.         }
  1379.         // Complete fieldName and columnName mapping
  1380.         if (! isset($mapping['columnName'])) {
  1381.             $mapping['columnName'] = $this->namingStrategy->propertyToColumnName($mapping['fieldName'], $this->name);
  1382.         }
  1383.         if ($mapping['columnName'][0] === '`') {
  1384.             $mapping['columnName'] = trim($mapping['columnName'], '`');
  1385.             $mapping['quoted']     = true;
  1386.         }
  1387.         $this->columnNames[$mapping['fieldName']] = $mapping['columnName'];
  1388.         if (isset($this->fieldNames[$mapping['columnName']]) || ($this->discriminatorColumn && $this->discriminatorColumn['name'] === $mapping['columnName'])) {
  1389.             throw MappingException::duplicateColumnName($this->name$mapping['columnName']);
  1390.         }
  1391.         $this->fieldNames[$mapping['columnName']] = $mapping['fieldName'];
  1392.         // Complete id mapping
  1393.         if (isset($mapping['id']) && $mapping['id'] === true) {
  1394.             if ($this->versionField === $mapping['fieldName']) {
  1395.                 throw MappingException::cannotVersionIdField($this->name$mapping['fieldName']);
  1396.             }
  1397.             if (! in_array($mapping['fieldName'], $this->identifiertrue)) {
  1398.                 $this->identifier[] = $mapping['fieldName'];
  1399.             }
  1400.             // Check for composite key
  1401.             if (! $this->isIdentifierComposite && count($this->identifier) > 1) {
  1402.                 $this->isIdentifierComposite true;
  1403.             }
  1404.         }
  1405.         if (Type::hasType($mapping['type']) && Type::getType($mapping['type'])->canRequireSQLConversion()) {
  1406.             if (isset($mapping['id']) && $mapping['id'] === true) {
  1407.                  throw MappingException::sqlConversionNotAllowedForIdentifiers($this->name$mapping['fieldName'], $mapping['type']);
  1408.             }
  1409.             $mapping['requireSQLConversion'] = true;
  1410.         }
  1411.         return $mapping;
  1412.     }
  1413.     /**
  1414.      * Validates & completes the basic mapping information that is common to all
  1415.      * association mappings (one-to-one, many-ot-one, one-to-many, many-to-many).
  1416.      *
  1417.      * @psalm-param array<string, mixed> $mapping The mapping.
  1418.      *
  1419.      * @return mixed[] The updated mapping.
  1420.      * @psalm-return array{
  1421.      *                   mappedBy: mixed|null,
  1422.      *                   inversedBy: mixed|null,
  1423.      *                   isOwningSide: bool,
  1424.      *                   sourceEntity: class-string,
  1425.      *                   targetEntity: string,
  1426.      *                   fieldName: mixed,
  1427.      *                   fetch: mixed,
  1428.      *                   cascade: array<array-key,string>,
  1429.      *                   isCascadeRemove: bool,
  1430.      *                   isCascadePersist: bool,
  1431.      *                   isCascadeRefresh: bool,
  1432.      *                   isCascadeMerge: bool,
  1433.      *                   isCascadeDetach: bool,
  1434.      *                   type: int,
  1435.      *                   originalField: string,
  1436.      *                   originalClass: class-string,
  1437.      *                   ?orphanRemoval: bool
  1438.      *               }
  1439.      *
  1440.      * @throws MappingException If something is wrong with the mapping.
  1441.      */
  1442.     protected function _validateAndCompleteAssociationMapping(array $mapping)
  1443.     {
  1444.         if (! isset($mapping['mappedBy'])) {
  1445.             $mapping['mappedBy'] = null;
  1446.         }
  1447.         if (! isset($mapping['inversedBy'])) {
  1448.             $mapping['inversedBy'] = null;
  1449.         }
  1450.         $mapping['isOwningSide'] = true// assume owning side until we hit mappedBy
  1451.         if (empty($mapping['indexBy'])) {
  1452.             unset($mapping['indexBy']);
  1453.         }
  1454.         // If targetEntity is unqualified, assume it is in the same namespace as
  1455.         // the sourceEntity.
  1456.         $mapping['sourceEntity'] = $this->name;
  1457.         if ($this->isTypedProperty($mapping['fieldName'])) {
  1458.             $mapping $this->validateAndCompleteTypedAssociationMapping($mapping);
  1459.         }
  1460.         if (isset($mapping['targetEntity'])) {
  1461.             $mapping['targetEntity'] = $this->fullyQualifiedClassName($mapping['targetEntity']);
  1462.             $mapping['targetEntity'] = ltrim($mapping['targetEntity'], '\\');
  1463.         }
  1464.         if (($mapping['type'] & self::MANY_TO_ONE) > && isset($mapping['orphanRemoval']) && $mapping['orphanRemoval']) {
  1465.             throw MappingException::illegalOrphanRemoval($this->name$mapping['fieldName']);
  1466.         }
  1467.         // Complete id mapping
  1468.         if (isset($mapping['id']) && $mapping['id'] === true) {
  1469.             if (isset($mapping['orphanRemoval']) && $mapping['orphanRemoval']) {
  1470.                 throw MappingException::illegalOrphanRemovalOnIdentifierAssociation($this->name$mapping['fieldName']);
  1471.             }
  1472.             if (! in_array($mapping['fieldName'], $this->identifiertrue)) {
  1473.                 if (isset($mapping['joinColumns']) && count($mapping['joinColumns']) >= 2) {
  1474.                     throw MappingException::cannotMapCompositePrimaryKeyEntitiesAsForeignId(
  1475.                         $mapping['targetEntity'],
  1476.                         $this->name,
  1477.                         $mapping['fieldName']
  1478.                     );
  1479.                 }
  1480.                 $this->identifier[]              = $mapping['fieldName'];
  1481.                 $this->containsForeignIdentifier true;
  1482.             }
  1483.             // Check for composite key
  1484.             if (! $this->isIdentifierComposite && count($this->identifier) > 1) {
  1485.                 $this->isIdentifierComposite true;
  1486.             }
  1487.             if ($this->cache && ! isset($mapping['cache'])) {
  1488.                 throw NonCacheableEntityAssociation::fromEntityAndField(
  1489.                     $this->name,
  1490.                     $mapping['fieldName']
  1491.                 );
  1492.             }
  1493.         }
  1494.         // Mandatory attributes for both sides
  1495.         // Mandatory: fieldName, targetEntity
  1496.         if (! isset($mapping['fieldName']) || ! $mapping['fieldName']) {
  1497.             throw MappingException::missingFieldName($this->name);
  1498.         }
  1499.         if (! isset($mapping['targetEntity'])) {
  1500.             throw MappingException::missingTargetEntity($mapping['fieldName']);
  1501.         }
  1502.         // Mandatory and optional attributes for either side
  1503.         if (! $mapping['mappedBy']) {
  1504.             if (isset($mapping['joinTable']) && $mapping['joinTable']) {
  1505.                 if (isset($mapping['joinTable']['name']) && $mapping['joinTable']['name'][0] === '`') {
  1506.                     $mapping['joinTable']['name']   = trim($mapping['joinTable']['name'], '`');
  1507.                     $mapping['joinTable']['quoted'] = true;
  1508.                 }
  1509.             }
  1510.         } else {
  1511.             $mapping['isOwningSide'] = false;
  1512.         }
  1513.         if (isset($mapping['id']) && $mapping['id'] === true && $mapping['type'] & self::TO_MANY) {
  1514.             throw MappingException::illegalToManyIdentifierAssociation($this->name$mapping['fieldName']);
  1515.         }
  1516.         // Fetch mode. Default fetch mode to LAZY, if not set.
  1517.         if (! isset($mapping['fetch'])) {
  1518.             $mapping['fetch'] = self::FETCH_LAZY;
  1519.         }
  1520.         // Cascades
  1521.         $cascades = isset($mapping['cascade']) ? array_map('strtolower'$mapping['cascade']) : [];
  1522.         $allCascades = ['remove''persist''refresh''merge''detach'];
  1523.         if (in_array('all'$cascadestrue)) {
  1524.             $cascades $allCascades;
  1525.         } elseif (count($cascades) !== count(array_intersect($cascades$allCascades))) {
  1526.             throw MappingException::invalidCascadeOption(
  1527.                 array_diff($cascades$allCascades),
  1528.                 $this->name,
  1529.                 $mapping['fieldName']
  1530.             );
  1531.         }
  1532.         $mapping['cascade']          = $cascades;
  1533.         $mapping['isCascadeRemove']  = in_array('remove'$cascadestrue);
  1534.         $mapping['isCascadePersist'] = in_array('persist'$cascadestrue);
  1535.         $mapping['isCascadeRefresh'] = in_array('refresh'$cascadestrue);
  1536.         $mapping['isCascadeMerge']   = in_array('merge'$cascadestrue);
  1537.         $mapping['isCascadeDetach']  = in_array('detach'$cascadestrue);
  1538.         return $mapping;
  1539.     }
  1540.     /**
  1541.      * Validates & completes a one-to-one association mapping.
  1542.      *
  1543.      * @psalm-param array<string, mixed> $mapping The mapping to validate & complete.
  1544.      * @psalm-param array<string, mixed> $mapping The mapping to validate & complete.
  1545.      *
  1546.      * @return mixed[] The validated & completed mapping.
  1547.      * @psalm-return array{isOwningSide: mixed, orphanRemoval: bool, isCascadeRemove: bool}
  1548.      * @psalm-return array{
  1549.      *      mappedBy: mixed|null,
  1550.      *      inversedBy: mixed|null,
  1551.      *      isOwningSide: bool,
  1552.      *      sourceEntity: class-string,
  1553.      *      targetEntity: string,
  1554.      *      fieldName: mixed,
  1555.      *      fetch: mixed,
  1556.      *      cascade: array<string>,
  1557.      *      isCascadeRemove: bool,
  1558.      *      isCascadePersist: bool,
  1559.      *      isCascadeRefresh: bool,
  1560.      *      isCascadeMerge: bool,
  1561.      *      isCascadeDetach: bool,
  1562.      *      type: int,
  1563.      *      originalField: string,
  1564.      *      originalClass: class-string,
  1565.      *      joinColumns?: array{0: array{name: string, referencedColumnName: string}}|mixed,
  1566.      *      id?: mixed,
  1567.      *      sourceToTargetKeyColumns?: array,
  1568.      *      joinColumnFieldNames?: array,
  1569.      *      targetToSourceKeyColumns?: array<array-key>,
  1570.      *      orphanRemoval: bool
  1571.      * }
  1572.      *
  1573.      * @throws RuntimeException
  1574.      * @throws MappingException
  1575.      */
  1576.     protected function _validateAndCompleteOneToOneMapping(array $mapping)
  1577.     {
  1578.         $mapping $this->_validateAndCompleteAssociationMapping($mapping);
  1579.         if (isset($mapping['joinColumns']) && $mapping['joinColumns']) {
  1580.             $mapping['isOwningSide'] = true;
  1581.         }
  1582.         if ($mapping['isOwningSide']) {
  1583.             if (empty($mapping['joinColumns'])) {
  1584.                 // Apply default join column
  1585.                 $mapping['joinColumns'] = [
  1586.                     [
  1587.                         'name' => $this->namingStrategy->joinColumnName($mapping['fieldName'], $this->name),
  1588.                         'referencedColumnName' => $this->namingStrategy->referenceColumnName(),
  1589.                     ],
  1590.                 ];
  1591.             }
  1592.             $uniqueConstraintColumns = [];
  1593.             foreach ($mapping['joinColumns'] as &$joinColumn) {
  1594.                 if ($mapping['type'] === self::ONE_TO_ONE && ! $this->isInheritanceTypeSingleTable()) {
  1595.                     if (count($mapping['joinColumns']) === 1) {
  1596.                         if (empty($mapping['id'])) {
  1597.                             $joinColumn['unique'] = true;
  1598.                         }
  1599.                     } else {
  1600.                         $uniqueConstraintColumns[] = $joinColumn['name'];
  1601.                     }
  1602.                 }
  1603.                 if (empty($joinColumn['name'])) {
  1604.                     $joinColumn['name'] = $this->namingStrategy->joinColumnName($mapping['fieldName'], $this->name);
  1605.                 }
  1606.                 if (empty($joinColumn['referencedColumnName'])) {
  1607.                     $joinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName();
  1608.                 }
  1609.                 if ($joinColumn['name'][0] === '`') {
  1610.                     $joinColumn['name']   = trim($joinColumn['name'], '`');
  1611.                     $joinColumn['quoted'] = true;
  1612.                 }
  1613.                 if ($joinColumn['referencedColumnName'][0] === '`') {
  1614.                     $joinColumn['referencedColumnName'] = trim($joinColumn['referencedColumnName'], '`');
  1615.                     $joinColumn['quoted']               = true;
  1616.                 }
  1617.                 $mapping['sourceToTargetKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName'];
  1618.                 $mapping['joinColumnFieldNames'][$joinColumn['name']]     = $joinColumn['fieldName'] ?? $joinColumn['name'];
  1619.             }
  1620.             if ($uniqueConstraintColumns) {
  1621.                 if (! $this->table) {
  1622.                     throw new RuntimeException('ClassMetadataInfo::setTable() has to be called before defining a one to one relationship.');
  1623.                 }
  1624.                 $this->table['uniqueConstraints'][$mapping['fieldName'] . '_uniq'] = ['columns' => $uniqueConstraintColumns];
  1625.             }
  1626.             $mapping['targetToSourceKeyColumns'] = array_flip($mapping['sourceToTargetKeyColumns']);
  1627.         }
  1628.         $mapping['orphanRemoval']   = isset($mapping['orphanRemoval']) && $mapping['orphanRemoval'];
  1629.         $mapping['isCascadeRemove'] = $mapping['orphanRemoval'] || $mapping['isCascadeRemove'];
  1630.         if ($mapping['orphanRemoval']) {
  1631.             unset($mapping['unique']);
  1632.         }
  1633.         if (isset($mapping['id']) && $mapping['id'] === true && ! $mapping['isOwningSide']) {
  1634.             throw MappingException::illegalInverseIdentifierAssociation($this->name$mapping['fieldName']);
  1635.         }
  1636.         return $mapping;
  1637.     }
  1638.     /**
  1639.      * Validates & completes a one-to-many association mapping.
  1640.      *
  1641.      * @psalm-param array<string, mixed> $mapping The mapping to validate and complete.
  1642.      *
  1643.      * @return mixed[] The validated and completed mapping.
  1644.      * @psalm-return array{
  1645.      *                   mappedBy: mixed,
  1646.      *                   inversedBy: mixed,
  1647.      *                   isOwningSide: bool,
  1648.      *                   sourceEntity: string,
  1649.      *                   targetEntity: string,
  1650.      *                   fieldName: mixed,
  1651.      *                   fetch: int|mixed,
  1652.      *                   cascade: array<array-key,string>,
  1653.      *                   isCascadeRemove: bool,
  1654.      *                   isCascadePersist: bool,
  1655.      *                   isCascadeRefresh: bool,
  1656.      *                   isCascadeMerge: bool,
  1657.      *                   isCascadeDetach: bool,
  1658.      *                   orphanRemoval: bool
  1659.      *               }
  1660.      *
  1661.      * @throws MappingException
  1662.      * @throws InvalidArgumentException
  1663.      */
  1664.     protected function _validateAndCompleteOneToManyMapping(array $mapping)
  1665.     {
  1666.         $mapping $this->_validateAndCompleteAssociationMapping($mapping);
  1667.         // OneToMany-side MUST be inverse (must have mappedBy)
  1668.         if (! isset($mapping['mappedBy'])) {
  1669.             throw MappingException::oneToManyRequiresMappedBy($this->name$mapping['fieldName']);
  1670.         }
  1671.         $mapping['orphanRemoval']   = isset($mapping['orphanRemoval']) && $mapping['orphanRemoval'];
  1672.         $mapping['isCascadeRemove'] = $mapping['orphanRemoval'] || $mapping['isCascadeRemove'];
  1673.         $this->assertMappingOrderBy($mapping);
  1674.         return $mapping;
  1675.     }
  1676.     /**
  1677.      * Validates & completes a many-to-many association mapping.
  1678.      *
  1679.      * @psalm-param array<string, mixed> $mapping The mapping to validate & complete.
  1680.      * @psalm-param array<string, mixed> $mapping The mapping to validate & complete.
  1681.      *
  1682.      * @return mixed[] The validated & completed mapping.
  1683.      * @psalm-return array{
  1684.      *      mappedBy: mixed,
  1685.      *      inversedBy: mixed,
  1686.      *      isOwningSide: bool,
  1687.      *      sourceEntity: class-string,
  1688.      *      targetEntity: string,
  1689.      *      fieldName: mixed,
  1690.      *      fetch: mixed,
  1691.      *      cascade: array<string>,
  1692.      *      isCascadeRemove: bool,
  1693.      *      isCascadePersist: bool,
  1694.      *      isCascadeRefresh: bool,
  1695.      *      isCascadeMerge: bool,
  1696.      *      isCascadeDetach: bool,
  1697.      *      type: int,
  1698.      *      originalField: string,
  1699.      *      originalClass: class-string,
  1700.      *      joinTable?: array{inverseJoinColumns: mixed}|mixed,
  1701.      *      joinTableColumns?: list<mixed>,
  1702.      *      isOnDeleteCascade?: true,
  1703.      *      relationToSourceKeyColumns?: array,
  1704.      *      relationToTargetKeyColumns?: array,
  1705.      *      orphanRemoval: bool
  1706.      * }
  1707.      *
  1708.      * @throws InvalidArgumentException
  1709.      */
  1710.     protected function _validateAndCompleteManyToManyMapping(array $mapping)
  1711.     {
  1712.         $mapping $this->_validateAndCompleteAssociationMapping($mapping);
  1713.         if ($mapping['isOwningSide']) {
  1714.             // owning side MUST have a join table
  1715.             if (! isset($mapping['joinTable']['name'])) {
  1716.                 $mapping['joinTable']['name'] = $this->namingStrategy->joinTableName($mapping['sourceEntity'], $mapping['targetEntity'], $mapping['fieldName']);
  1717.             }
  1718.             $selfReferencingEntityWithoutJoinColumns $mapping['sourceEntity'] === $mapping['targetEntity']
  1719.                 && (! (isset($mapping['joinTable']['joinColumns']) || isset($mapping['joinTable']['inverseJoinColumns'])));
  1720.             if (! isset($mapping['joinTable']['joinColumns'])) {
  1721.                 $mapping['joinTable']['joinColumns'] = [
  1722.                     [
  1723.                         'name' => $this->namingStrategy->joinKeyColumnName($mapping['sourceEntity'], $selfReferencingEntityWithoutJoinColumns 'source' null),
  1724.                         'referencedColumnName' => $this->namingStrategy->referenceColumnName(),
  1725.                         'onDelete' => 'CASCADE',
  1726.                     ],
  1727.                 ];
  1728.             }
  1729.             if (! isset($mapping['joinTable']['inverseJoinColumns'])) {
  1730.                 $mapping['joinTable']['inverseJoinColumns'] = [
  1731.                     [
  1732.                         'name' => $this->namingStrategy->joinKeyColumnName($mapping['targetEntity'], $selfReferencingEntityWithoutJoinColumns 'target' null),
  1733.                         'referencedColumnName' => $this->namingStrategy->referenceColumnName(),
  1734.                         'onDelete' => 'CASCADE',
  1735.                     ],
  1736.                 ];
  1737.             }
  1738.             $mapping['joinTableColumns'] = [];
  1739.             foreach ($mapping['joinTable']['joinColumns'] as &$joinColumn) {
  1740.                 if (empty($joinColumn['name'])) {
  1741.                     $joinColumn['name'] = $this->namingStrategy->joinKeyColumnName($mapping['sourceEntity'], $joinColumn['referencedColumnName']);
  1742.                 }
  1743.                 if (empty($joinColumn['referencedColumnName'])) {
  1744.                     $joinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName();
  1745.                 }
  1746.                 if ($joinColumn['name'][0] === '`') {
  1747.                     $joinColumn['name']   = trim($joinColumn['name'], '`');
  1748.                     $joinColumn['quoted'] = true;
  1749.                 }
  1750.                 if ($joinColumn['referencedColumnName'][0] === '`') {
  1751.                     $joinColumn['referencedColumnName'] = trim($joinColumn['referencedColumnName'], '`');
  1752.                     $joinColumn['quoted']               = true;
  1753.                 }
  1754.                 if (isset($joinColumn['onDelete']) && strtolower($joinColumn['onDelete']) === 'cascade') {
  1755.                     $mapping['isOnDeleteCascade'] = true;
  1756.                 }
  1757.                 $mapping['relationToSourceKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName'];
  1758.                 $mapping['joinTableColumns'][]                              = $joinColumn['name'];
  1759.             }
  1760.             foreach ($mapping['joinTable']['inverseJoinColumns'] as &$inverseJoinColumn) {
  1761.                 if (empty($inverseJoinColumn['name'])) {
  1762.                     $inverseJoinColumn['name'] = $this->namingStrategy->joinKeyColumnName($mapping['targetEntity'], $inverseJoinColumn['referencedColumnName']);
  1763.                 }
  1764.                 if (empty($inverseJoinColumn['referencedColumnName'])) {
  1765.                     $inverseJoinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName();
  1766.                 }
  1767.                 if ($inverseJoinColumn['name'][0] === '`') {
  1768.                     $inverseJoinColumn['name']   = trim($inverseJoinColumn['name'], '`');
  1769.                     $inverseJoinColumn['quoted'] = true;
  1770.                 }
  1771.                 if ($inverseJoinColumn['referencedColumnName'][0] === '`') {
  1772.                     $inverseJoinColumn['referencedColumnName'] = trim($inverseJoinColumn['referencedColumnName'], '`');
  1773.                     $inverseJoinColumn['quoted']               = true;
  1774.                 }
  1775.                 if (isset($inverseJoinColumn['onDelete']) && strtolower($inverseJoinColumn['onDelete']) === 'cascade') {
  1776.                     $mapping['isOnDeleteCascade'] = true;
  1777.                 }
  1778.                 $mapping['relationToTargetKeyColumns'][$inverseJoinColumn['name']] = $inverseJoinColumn['referencedColumnName'];
  1779.                 $mapping['joinTableColumns'][]                                     = $inverseJoinColumn['name'];
  1780.             }
  1781.         }
  1782.         $mapping['orphanRemoval'] = isset($mapping['orphanRemoval']) && $mapping['orphanRemoval'];
  1783.         $this->assertMappingOrderBy($mapping);
  1784.         return $mapping;
  1785.     }
  1786.     /**
  1787.      * {@inheritDoc}
  1788.      */
  1789.     public function getIdentifierFieldNames()
  1790.     {
  1791.         return $this->identifier;
  1792.     }
  1793.     /**
  1794.      * Gets the name of the single id field. Note that this only works on
  1795.      * entity classes that have a single-field pk.
  1796.      *
  1797.      * @return string
  1798.      *
  1799.      * @throws MappingException If the class doesn't have an identifier or it has a composite primary key.
  1800.      */
  1801.     public function getSingleIdentifierFieldName()
  1802.     {
  1803.         if ($this->isIdentifierComposite) {
  1804.             throw MappingException::singleIdNotAllowedOnCompositePrimaryKey($this->name);
  1805.         }
  1806.         if (! isset($this->identifier[0])) {
  1807.             throw MappingException::noIdDefined($this->name);
  1808.         }
  1809.         return $this->identifier[0];
  1810.     }
  1811.     /**
  1812.      * Gets the column name of the single id column. 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 doesn't have an identifier or it has a composite primary key.
  1818.      */
  1819.     public function getSingleIdentifierColumnName()
  1820.     {
  1821.         return $this->getColumnName($this->getSingleIdentifierFieldName());
  1822.     }
  1823.     /**
  1824.      * INTERNAL:
  1825.      * Sets the mapped identifier/primary key fields of this class.
  1826.      * Mainly used by the ClassMetadataFactory to assign inherited identifiers.
  1827.      *
  1828.      * @psalm-param list<mixed> $identifier
  1829.      *
  1830.      * @return void
  1831.      */
  1832.     public function setIdentifier(array $identifier)
  1833.     {
  1834.         $this->identifier            $identifier;
  1835.         $this->isIdentifierComposite = (count($this->identifier) > 1);
  1836.     }
  1837.     /**
  1838.      * {@inheritDoc}
  1839.      */
  1840.     public function getIdentifier()
  1841.     {
  1842.         return $this->identifier;
  1843.     }
  1844.     /**
  1845.      * {@inheritDoc}
  1846.      */
  1847.     public function hasField($fieldName)
  1848.     {
  1849.         return isset($this->fieldMappings[$fieldName]) || isset($this->embeddedClasses[$fieldName]);
  1850.     }
  1851.     /**
  1852.      * Gets an array containing all the column names.
  1853.      *
  1854.      * @psalm-param list<string>|null $fieldNames
  1855.      *
  1856.      * @return mixed[]
  1857.      * @psalm-return list<string>
  1858.      */
  1859.     public function getColumnNames(?array $fieldNames null)
  1860.     {
  1861.         if ($fieldNames === null) {
  1862.             return array_keys($this->fieldNames);
  1863.         }
  1864.         return array_values(array_map([$this'getColumnName'], $fieldNames));
  1865.     }
  1866.     /**
  1867.      * Returns an array with all the identifier column names.
  1868.      *
  1869.      * @psalm-return list<string>
  1870.      */
  1871.     public function getIdentifierColumnNames()
  1872.     {
  1873.         $columnNames = [];
  1874.         foreach ($this->identifier as $idProperty) {
  1875.             if (isset($this->fieldMappings[$idProperty])) {
  1876.                 $columnNames[] = $this->fieldMappings[$idProperty]['columnName'];
  1877.                 continue;
  1878.             }
  1879.             // Association defined as Id field
  1880.             $joinColumns      $this->associationMappings[$idProperty]['joinColumns'];
  1881.             $assocColumnNames array_map(static function ($joinColumn) {
  1882.                 return $joinColumn['name'];
  1883.             }, $joinColumns);
  1884.             $columnNames array_merge($columnNames$assocColumnNames);
  1885.         }
  1886.         return $columnNames;
  1887.     }
  1888.     /**
  1889.      * Sets the type of Id generator to use for the mapped class.
  1890.      *
  1891.      * @param int $generatorType
  1892.      *
  1893.      * @return void
  1894.      */
  1895.     public function setIdGeneratorType($generatorType)
  1896.     {
  1897.         $this->generatorType $generatorType;
  1898.     }
  1899.     /**
  1900.      * Checks whether the mapped class uses an Id generator.
  1901.      *
  1902.      * @return bool TRUE if the mapped class uses an Id generator, FALSE otherwise.
  1903.      */
  1904.     public function usesIdGenerator()
  1905.     {
  1906.         return $this->generatorType !== self::GENERATOR_TYPE_NONE;
  1907.     }
  1908.     /**
  1909.      * @return bool
  1910.      */
  1911.     public function isInheritanceTypeNone()
  1912.     {
  1913.         return $this->inheritanceType === self::INHERITANCE_TYPE_NONE;
  1914.     }
  1915.     /**
  1916.      * Checks whether the mapped class uses the JOINED inheritance mapping strategy.
  1917.      *
  1918.      * @return bool TRUE if the class participates in a JOINED inheritance mapping,
  1919.      * FALSE otherwise.
  1920.      */
  1921.     public function isInheritanceTypeJoined()
  1922.     {
  1923.         return $this->inheritanceType === self::INHERITANCE_TYPE_JOINED;
  1924.     }
  1925.     /**
  1926.      * Checks whether the mapped class uses the SINGLE_TABLE inheritance mapping strategy.
  1927.      *
  1928.      * @return bool TRUE if the class participates in a SINGLE_TABLE inheritance mapping,
  1929.      * FALSE otherwise.
  1930.      */
  1931.     public function isInheritanceTypeSingleTable()
  1932.     {
  1933.         return $this->inheritanceType === self::INHERITANCE_TYPE_SINGLE_TABLE;
  1934.     }
  1935.     /**
  1936.      * Checks whether the mapped class uses the TABLE_PER_CLASS inheritance mapping strategy.
  1937.      *
  1938.      * @return bool TRUE if the class participates in a TABLE_PER_CLASS inheritance mapping,
  1939.      * FALSE otherwise.
  1940.      */
  1941.     public function isInheritanceTypeTablePerClass()
  1942.     {
  1943.         return $this->inheritanceType === self::INHERITANCE_TYPE_TABLE_PER_CLASS;
  1944.     }
  1945.     /**
  1946.      * Checks whether the class uses an identity column for the Id generation.
  1947.      *
  1948.      * @return bool TRUE if the class uses the IDENTITY generator, FALSE otherwise.
  1949.      */
  1950.     public function isIdGeneratorIdentity()
  1951.     {
  1952.         return $this->generatorType === self::GENERATOR_TYPE_IDENTITY;
  1953.     }
  1954.     /**
  1955.      * Checks whether the class uses a sequence for id generation.
  1956.      *
  1957.      * @return bool TRUE if the class uses the SEQUENCE generator, FALSE otherwise.
  1958.      */
  1959.     public function isIdGeneratorSequence()
  1960.     {
  1961.         return $this->generatorType === self::GENERATOR_TYPE_SEQUENCE;
  1962.     }
  1963.     /**
  1964.      * Checks whether the class uses a table for id generation.
  1965.      *
  1966.      * @deprecated
  1967.      *
  1968.      * @return false
  1969.      */
  1970.     public function isIdGeneratorTable()
  1971.     {
  1972.         Deprecation::trigger(
  1973.             'doctrine/orm',
  1974.             'https://github.com/doctrine/orm/pull/9046',
  1975.             '%s is deprecated',
  1976.             __METHOD__
  1977.         );
  1978.         return false;
  1979.     }
  1980.     /**
  1981.      * Checks whether the class has a natural identifier/pk (which means it does
  1982.      * not use any Id generator.
  1983.      *
  1984.      * @return bool
  1985.      */
  1986.     public function isIdentifierNatural()
  1987.     {
  1988.         return $this->generatorType === self::GENERATOR_TYPE_NONE;
  1989.     }
  1990.     /**
  1991.      * Checks whether the class use a UUID for id generation.
  1992.      *
  1993.      * @deprecated
  1994.      *
  1995.      * @return bool
  1996.      */
  1997.     public function isIdentifierUuid()
  1998.     {
  1999.         Deprecation::trigger(
  2000.             'doctrine/orm',
  2001.             'https://github.com/doctrine/orm/pull/9046',
  2002.             '%s is deprecated',
  2003.             __METHOD__
  2004.         );
  2005.         return $this->generatorType === self::GENERATOR_TYPE_UUID;
  2006.     }
  2007.     /**
  2008.      * Gets the type of a field.
  2009.      *
  2010.      * @param string $fieldName
  2011.      *
  2012.      * @return string|null
  2013.      *
  2014.      * @todo 3.0 Remove this. PersisterHelper should fix it somehow
  2015.      */
  2016.     public function getTypeOfField($fieldName)
  2017.     {
  2018.         return isset($this->fieldMappings[$fieldName])
  2019.             ? $this->fieldMappings[$fieldName]['type']
  2020.             : null;
  2021.     }
  2022.     /**
  2023.      * Gets the type of a column.
  2024.      *
  2025.      * @deprecated 3.0 remove this. this method is bogus and unreliable, since it cannot resolve the type of a column
  2026.      *             that is derived by a referenced field on a different entity.
  2027.      *
  2028.      * @param string $columnName
  2029.      *
  2030.      * @return string|null
  2031.      */
  2032.     public function getTypeOfColumn($columnName)
  2033.     {
  2034.         return $this->getTypeOfField($this->getFieldName($columnName));
  2035.     }
  2036.     /**
  2037.      * Gets the name of the primary table.
  2038.      *
  2039.      * @return string
  2040.      */
  2041.     public function getTableName()
  2042.     {
  2043.         return $this->table['name'];
  2044.     }
  2045.     /**
  2046.      * Gets primary table's schema name.
  2047.      *
  2048.      * @return string|null
  2049.      */
  2050.     public function getSchemaName()
  2051.     {
  2052.         return $this->table['schema'] ?? null;
  2053.     }
  2054.     /**
  2055.      * Gets the table name to use for temporary identifier tables of this class.
  2056.      *
  2057.      * @return string
  2058.      */
  2059.     public function getTemporaryIdTableName()
  2060.     {
  2061.         // replace dots with underscores because PostgreSQL creates temporary tables in a special schema
  2062.         return str_replace('.''_'$this->getTableName() . '_id_tmp');
  2063.     }
  2064.     /**
  2065.      * Sets the mapped subclasses of this class.
  2066.      *
  2067.      * @psalm-param list<string> $subclasses The names of all mapped subclasses.
  2068.      *
  2069.      * @return void
  2070.      */
  2071.     public function setSubclasses(array $subclasses)
  2072.     {
  2073.         foreach ($subclasses as $subclass) {
  2074.             $this->subClasses[] = $this->fullyQualifiedClassName($subclass);
  2075.         }
  2076.     }
  2077.     /**
  2078.      * Sets the parent class names.
  2079.      * Assumes that the class names in the passed array are in the order:
  2080.      * directParent -> directParentParent -> directParentParentParent ... -> root.
  2081.      *
  2082.      * @psalm-param list<class-string> $classNames
  2083.      *
  2084.      * @return void
  2085.      */
  2086.     public function setParentClasses(array $classNames)
  2087.     {
  2088.         $this->parentClasses $classNames;
  2089.         if (count($classNames) > 0) {
  2090.             $this->rootEntityName array_pop($classNames);
  2091.         }
  2092.     }
  2093.     /**
  2094.      * Sets the inheritance type used by the class and its subclasses.
  2095.      *
  2096.      * @param int $type
  2097.      *
  2098.      * @return void
  2099.      *
  2100.      * @throws MappingException
  2101.      */
  2102.     public function setInheritanceType($type)
  2103.     {
  2104.         if (! $this->isInheritanceType($type)) {
  2105.             throw MappingException::invalidInheritanceType($this->name$type);
  2106.         }
  2107.         $this->inheritanceType $type;
  2108.     }
  2109.     /**
  2110.      * Sets the association to override association mapping of property for an entity relationship.
  2111.      *
  2112.      * @param string $fieldName
  2113.      * @psalm-param array<string, mixed> $overrideMapping
  2114.      *
  2115.      * @return void
  2116.      *
  2117.      * @throws MappingException
  2118.      */
  2119.     public function setAssociationOverride($fieldName, array $overrideMapping)
  2120.     {
  2121.         if (! isset($this->associationMappings[$fieldName])) {
  2122.             throw MappingException::invalidOverrideFieldName($this->name$fieldName);
  2123.         }
  2124.         $mapping $this->associationMappings[$fieldName];
  2125.         //if (isset($mapping['inherited']) && (count($overrideMapping) !== 1 || ! isset($overrideMapping['fetch']))) {
  2126.             // TODO: Deprecate overriding the fetch mode via association override for 3.0,
  2127.             // users should do this with a listener and a custom attribute/annotation
  2128.             // TODO: Enable this exception in 2.8
  2129.             //throw MappingException::illegalOverrideOfInheritedProperty($this->name, $fieldName);
  2130.         //}
  2131.         if (isset($overrideMapping['joinColumns'])) {
  2132.             $mapping['joinColumns'] = $overrideMapping['joinColumns'];
  2133.         }
  2134.         if (isset($overrideMapping['inversedBy'])) {
  2135.             $mapping['inversedBy'] = $overrideMapping['inversedBy'];
  2136.         }
  2137.         if (isset($overrideMapping['joinTable'])) {
  2138.             $mapping['joinTable'] = $overrideMapping['joinTable'];
  2139.         }
  2140.         if (isset($overrideMapping['fetch'])) {
  2141.             $mapping['fetch'] = $overrideMapping['fetch'];
  2142.         }
  2143.         $mapping['joinColumnFieldNames']       = null;
  2144.         $mapping['joinTableColumns']           = null;
  2145.         $mapping['sourceToTargetKeyColumns']   = null;
  2146.         $mapping['relationToSourceKeyColumns'] = null;
  2147.         $mapping['relationToTargetKeyColumns'] = null;
  2148.         switch ($mapping['type']) {
  2149.             case self::ONE_TO_ONE:
  2150.                 $mapping $this->_validateAndCompleteOneToOneMapping($mapping);
  2151.                 break;
  2152.             case self::ONE_TO_MANY:
  2153.                 $mapping $this->_validateAndCompleteOneToManyMapping($mapping);
  2154.                 break;
  2155.             case self::MANY_TO_ONE:
  2156.                 $mapping $this->_validateAndCompleteOneToOneMapping($mapping);
  2157.                 break;
  2158.             case self::MANY_TO_MANY:
  2159.                 $mapping $this->_validateAndCompleteManyToManyMapping($mapping);
  2160.                 break;
  2161.         }
  2162.         $this->associationMappings[$fieldName] = $mapping;
  2163.     }
  2164.     /**
  2165.      * Sets the override for a mapped field.
  2166.      *
  2167.      * @param string $fieldName
  2168.      * @psalm-param array<string, mixed> $overrideMapping
  2169.      *
  2170.      * @return void
  2171.      *
  2172.      * @throws MappingException
  2173.      */
  2174.     public function setAttributeOverride($fieldName, array $overrideMapping)
  2175.     {
  2176.         if (! isset($this->fieldMappings[$fieldName])) {
  2177.             throw MappingException::invalidOverrideFieldName($this->name$fieldName);
  2178.         }
  2179.         $mapping $this->fieldMappings[$fieldName];
  2180.         //if (isset($mapping['inherited'])) {
  2181.             // TODO: Enable this exception in 2.8
  2182.             //throw MappingException::illegalOverrideOfInheritedProperty($this->name, $fieldName);
  2183.         //}
  2184.         if (isset($mapping['id'])) {
  2185.             $overrideMapping['id'] = $mapping['id'];
  2186.         }
  2187.         if (! isset($overrideMapping['type'])) {
  2188.             $overrideMapping['type'] = $mapping['type'];
  2189.         }
  2190.         if (! isset($overrideMapping['fieldName'])) {
  2191.             $overrideMapping['fieldName'] = $mapping['fieldName'];
  2192.         }
  2193.         if ($overrideMapping['type'] !== $mapping['type']) {
  2194.             throw MappingException::invalidOverrideFieldType($this->name$fieldName);
  2195.         }
  2196.         unset($this->fieldMappings[$fieldName]);
  2197.         unset($this->fieldNames[$mapping['columnName']]);
  2198.         unset($this->columnNames[$mapping['fieldName']]);
  2199.         $overrideMapping $this->validateAndCompleteFieldMapping($overrideMapping);
  2200.         $this->fieldMappings[$fieldName] = $overrideMapping;
  2201.     }
  2202.     /**
  2203.      * Checks whether a mapped field is inherited from an entity superclass.
  2204.      *
  2205.      * @param string $fieldName
  2206.      *
  2207.      * @return bool TRUE if the field is inherited, FALSE otherwise.
  2208.      */
  2209.     public function isInheritedField($fieldName)
  2210.     {
  2211.         return isset($this->fieldMappings[$fieldName]['inherited']);
  2212.     }
  2213.     /**
  2214.      * Checks if this entity is the root in any entity-inheritance-hierarchy.
  2215.      *
  2216.      * @return bool
  2217.      */
  2218.     public function isRootEntity()
  2219.     {
  2220.         return $this->name === $this->rootEntityName;
  2221.     }
  2222.     /**
  2223.      * Checks whether a mapped association field is inherited from a superclass.
  2224.      *
  2225.      * @param string $fieldName
  2226.      *
  2227.      * @return bool TRUE if the field is inherited, FALSE otherwise.
  2228.      */
  2229.     public function isInheritedAssociation($fieldName)
  2230.     {
  2231.         return isset($this->associationMappings[$fieldName]['inherited']);
  2232.     }
  2233.     /**
  2234.      * @param string $fieldName
  2235.      *
  2236.      * @return bool
  2237.      */
  2238.     public function isInheritedEmbeddedClass($fieldName)
  2239.     {
  2240.         return isset($this->embeddedClasses[$fieldName]['inherited']);
  2241.     }
  2242.     /**
  2243.      * Sets the name of the primary table the class is mapped to.
  2244.      *
  2245.      * @deprecated Use {@link setPrimaryTable}.
  2246.      *
  2247.      * @param string $tableName The table name.
  2248.      *
  2249.      * @return void
  2250.      */
  2251.     public function setTableName($tableName)
  2252.     {
  2253.         $this->table['name'] = $tableName;
  2254.     }
  2255.     /**
  2256.      * Sets the primary table definition. The provided array supports the
  2257.      * following structure:
  2258.      *
  2259.      * name => <tableName> (optional, defaults to class name)
  2260.      * indexes => array of indexes (optional)
  2261.      * uniqueConstraints => array of constraints (optional)
  2262.      *
  2263.      * If a key is omitted, the current value is kept.
  2264.      *
  2265.      * @psalm-param array<string, mixed> $table The table description.
  2266.      *
  2267.      * @return void
  2268.      */
  2269.     public function setPrimaryTable(array $table)
  2270.     {
  2271.         if (isset($table['name'])) {
  2272.             // Split schema and table name from a table name like "myschema.mytable"
  2273.             if (strpos($table['name'], '.') !== false) {
  2274.                 [$this->table['schema'], $table['name']] = explode('.'$table['name'], 2);
  2275.             }
  2276.             if ($table['name'][0] === '`') {
  2277.                 $table['name']         = trim($table['name'], '`');
  2278.                 $this->table['quoted'] = true;
  2279.             }
  2280.             $this->table['name'] = $table['name'];
  2281.         }
  2282.         if (isset($table['quoted'])) {
  2283.             $this->table['quoted'] = $table['quoted'];
  2284.         }
  2285.         if (isset($table['schema'])) {
  2286.             $this->table['schema'] = $table['schema'];
  2287.         }
  2288.         if (isset($table['indexes'])) {
  2289.             $this->table['indexes'] = $table['indexes'];
  2290.         }
  2291.         if (isset($table['uniqueConstraints'])) {
  2292.             $this->table['uniqueConstraints'] = $table['uniqueConstraints'];
  2293.         }
  2294.         if (isset($table['options'])) {
  2295.             $this->table['options'] = $table['options'];
  2296.         }
  2297.     }
  2298.     /**
  2299.      * Checks whether the given type identifies an inheritance type.
  2300.      *
  2301.      * @return bool TRUE if the given type identifies an inheritance type, FALSE otherwise.
  2302.      */
  2303.     private function isInheritanceType(int $type): bool
  2304.     {
  2305.         return $type === self::INHERITANCE_TYPE_NONE ||
  2306.                 $type === self::INHERITANCE_TYPE_SINGLE_TABLE ||
  2307.                 $type === self::INHERITANCE_TYPE_JOINED ||
  2308.                 $type === self::INHERITANCE_TYPE_TABLE_PER_CLASS;
  2309.     }
  2310.     /**
  2311.      * Adds a mapped field to the class.
  2312.      *
  2313.      * @psalm-param array<string, mixed> $mapping The field mapping.
  2314.      *
  2315.      * @return void
  2316.      *
  2317.      * @throws MappingException
  2318.      */
  2319.     public function mapField(array $mapping)
  2320.     {
  2321.         $mapping $this->validateAndCompleteFieldMapping($mapping);
  2322.         $this->assertFieldNotMapped($mapping['fieldName']);
  2323.         $this->fieldMappings[$mapping['fieldName']] = $mapping;
  2324.     }
  2325.     /**
  2326.      * INTERNAL:
  2327.      * Adds an association mapping without completing/validating it.
  2328.      * This is mainly used to add inherited association mappings to derived classes.
  2329.      *
  2330.      * @psalm-param array<string, mixed> $mapping
  2331.      *
  2332.      * @return void
  2333.      *
  2334.      * @throws MappingException
  2335.      */
  2336.     public function addInheritedAssociationMapping(array $mapping/*, $owningClassName = null*/)
  2337.     {
  2338.         if (isset($this->associationMappings[$mapping['fieldName']])) {
  2339.             throw MappingException::duplicateAssociationMapping($this->name$mapping['fieldName']);
  2340.         }
  2341.         $this->associationMappings[$mapping['fieldName']] = $mapping;
  2342.     }
  2343.     /**
  2344.      * INTERNAL:
  2345.      * Adds a field mapping without completing/validating it.
  2346.      * This is mainly used to add inherited field mappings to derived classes.
  2347.      *
  2348.      * @psalm-param array<string, mixed> $fieldMapping
  2349.      *
  2350.      * @return void
  2351.      */
  2352.     public function addInheritedFieldMapping(array $fieldMapping)
  2353.     {
  2354.         $this->fieldMappings[$fieldMapping['fieldName']] = $fieldMapping;
  2355.         $this->columnNames[$fieldMapping['fieldName']]   = $fieldMapping['columnName'];
  2356.         $this->fieldNames[$fieldMapping['columnName']]   = $fieldMapping['fieldName'];
  2357.     }
  2358.     /**
  2359.      * INTERNAL:
  2360.      * Adds a named query to this class.
  2361.      *
  2362.      * @deprecated
  2363.      *
  2364.      * @psalm-param array<string, mixed> $queryMapping
  2365.      *
  2366.      * @return void
  2367.      *
  2368.      * @throws MappingException
  2369.      */
  2370.     public function addNamedQuery(array $queryMapping)
  2371.     {
  2372.         if (! isset($queryMapping['name'])) {
  2373.             throw MappingException::nameIsMandatoryForQueryMapping($this->name);
  2374.         }
  2375.         Deprecation::trigger(
  2376.             'doctrine/orm',
  2377.             'https://github.com/doctrine/orm/issues/8592',
  2378.             'Named Queries are deprecated, here "%s" on entity %s. Move the query logic into EntityRepository',
  2379.             $queryMapping['name'],
  2380.             $this->name
  2381.         );
  2382.         if (isset($this->namedQueries[$queryMapping['name']])) {
  2383.             throw MappingException::duplicateQueryMapping($this->name$queryMapping['name']);
  2384.         }
  2385.         if (! isset($queryMapping['query'])) {
  2386.             throw MappingException::emptyQueryMapping($this->name$queryMapping['name']);
  2387.         }
  2388.         $name  $queryMapping['name'];
  2389.         $query $queryMapping['query'];
  2390.         $dql   str_replace('__CLASS__'$this->name$query);
  2391.         $this->namedQueries[$name] = [
  2392.             'name'  => $name,
  2393.             'query' => $query,
  2394.             'dql'   => $dql,
  2395.         ];
  2396.     }
  2397.     /**
  2398.      * INTERNAL:
  2399.      * Adds a named native query to this class.
  2400.      *
  2401.      * @deprecated
  2402.      *
  2403.      * @psalm-param array<string, mixed> $queryMapping
  2404.      *
  2405.      * @return void
  2406.      *
  2407.      * @throws MappingException
  2408.      */
  2409.     public function addNamedNativeQuery(array $queryMapping)
  2410.     {
  2411.         if (! isset($queryMapping['name'])) {
  2412.             throw MappingException::nameIsMandatoryForQueryMapping($this->name);
  2413.         }
  2414.         Deprecation::trigger(
  2415.             'doctrine/orm',
  2416.             'https://github.com/doctrine/orm/issues/8592',
  2417.             'Named Native Queries are deprecated, here "%s" on entity %s. Move the query logic into EntityRepository',
  2418.             $queryMapping['name'],
  2419.             $this->name
  2420.         );
  2421.         if (isset($this->namedNativeQueries[$queryMapping['name']])) {
  2422.             throw MappingException::duplicateQueryMapping($this->name$queryMapping['name']);
  2423.         }
  2424.         if (! isset($queryMapping['query'])) {
  2425.             throw MappingException::emptyQueryMapping($this->name$queryMapping['name']);
  2426.         }
  2427.         if (! isset($queryMapping['resultClass']) && ! isset($queryMapping['resultSetMapping'])) {
  2428.             throw MappingException::missingQueryMapping($this->name$queryMapping['name']);
  2429.         }
  2430.         $queryMapping['isSelfClass'] = false;
  2431.         if (isset($queryMapping['resultClass'])) {
  2432.             if ($queryMapping['resultClass'] === '__CLASS__') {
  2433.                 $queryMapping['isSelfClass'] = true;
  2434.                 $queryMapping['resultClass'] = $this->name;
  2435.             }
  2436.             $queryMapping['resultClass'] = $this->fullyQualifiedClassName($queryMapping['resultClass']);
  2437.             $queryMapping['resultClass'] = ltrim($queryMapping['resultClass'], '\\');
  2438.         }
  2439.         $this->namedNativeQueries[$queryMapping['name']] = $queryMapping;
  2440.     }
  2441.     /**
  2442.      * INTERNAL:
  2443.      * Adds a sql result set mapping to this class.
  2444.      *
  2445.      * @psalm-param array<string, mixed> $resultMapping
  2446.      *
  2447.      * @return void
  2448.      *
  2449.      * @throws MappingException
  2450.      */
  2451.     public function addSqlResultSetMapping(array $resultMapping)
  2452.     {
  2453.         if (! isset($resultMapping['name'])) {
  2454.             throw MappingException::nameIsMandatoryForSqlResultSetMapping($this->name);
  2455.         }
  2456.         if (isset($this->sqlResultSetMappings[$resultMapping['name']])) {
  2457.             throw MappingException::duplicateResultSetMapping($this->name$resultMapping['name']);
  2458.         }
  2459.         if (isset($resultMapping['entities'])) {
  2460.             foreach ($resultMapping['entities'] as $key => $entityResult) {
  2461.                 if (! isset($entityResult['entityClass'])) {
  2462.                     throw MappingException::missingResultSetMappingEntity($this->name$resultMapping['name']);
  2463.                 }
  2464.                 $entityResult['isSelfClass'] = false;
  2465.                 if ($entityResult['entityClass'] === '__CLASS__') {
  2466.                     $entityResult['isSelfClass'] = true;
  2467.                     $entityResult['entityClass'] = $this->name;
  2468.                 }
  2469.                 $entityResult['entityClass'] = $this->fullyQualifiedClassName($entityResult['entityClass']);
  2470.                 $resultMapping['entities'][$key]['entityClass'] = ltrim($entityResult['entityClass'], '\\');
  2471.                 $resultMapping['entities'][$key]['isSelfClass'] = $entityResult['isSelfClass'];
  2472.                 if (isset($entityResult['fields'])) {
  2473.                     foreach ($entityResult['fields'] as $k => $field) {
  2474.                         if (! isset($field['name'])) {
  2475.                             throw MappingException::missingResultSetMappingFieldName($this->name$resultMapping['name']);
  2476.                         }
  2477.                         if (! isset($field['column'])) {
  2478.                             $fieldName $field['name'];
  2479.                             if (strpos($fieldName'.')) {
  2480.                                 [, $fieldName] = explode('.'$fieldName);
  2481.                             }
  2482.                             $resultMapping['entities'][$key]['fields'][$k]['column'] = $fieldName;
  2483.                         }
  2484.                     }
  2485.                 }
  2486.             }
  2487.         }
  2488.         $this->sqlResultSetMappings[$resultMapping['name']] = $resultMapping;
  2489.     }
  2490.     /**
  2491.      * Adds a one-to-one mapping.
  2492.      *
  2493.      * @param array<string, mixed> $mapping The mapping.
  2494.      *
  2495.      * @return void
  2496.      */
  2497.     public function mapOneToOne(array $mapping)
  2498.     {
  2499.         $mapping['type'] = self::ONE_TO_ONE;
  2500.         $mapping $this->_validateAndCompleteOneToOneMapping($mapping);
  2501.         $this->_storeAssociationMapping($mapping);
  2502.     }
  2503.     /**
  2504.      * Adds a one-to-many mapping.
  2505.      *
  2506.      * @psalm-param array<string, mixed> $mapping The mapping.
  2507.      *
  2508.      * @return void
  2509.      */
  2510.     public function mapOneToMany(array $mapping)
  2511.     {
  2512.         $mapping['type'] = self::ONE_TO_MANY;
  2513.         $mapping $this->_validateAndCompleteOneToManyMapping($mapping);
  2514.         $this->_storeAssociationMapping($mapping);
  2515.     }
  2516.     /**
  2517.      * Adds a many-to-one mapping.
  2518.      *
  2519.      * @psalm-param array<string, mixed> $mapping The mapping.
  2520.      *
  2521.      * @return void
  2522.      */
  2523.     public function mapManyToOne(array $mapping)
  2524.     {
  2525.         $mapping['type'] = self::MANY_TO_ONE;
  2526.         // A many-to-one mapping is essentially a one-one backreference
  2527.         $mapping $this->_validateAndCompleteOneToOneMapping($mapping);
  2528.         $this->_storeAssociationMapping($mapping);
  2529.     }
  2530.     /**
  2531.      * Adds a many-to-many mapping.
  2532.      *
  2533.      * @psalm-param array<string, mixed> $mapping The mapping.
  2534.      *
  2535.      * @return void
  2536.      */
  2537.     public function mapManyToMany(array $mapping)
  2538.     {
  2539.         $mapping['type'] = self::MANY_TO_MANY;
  2540.         $mapping $this->_validateAndCompleteManyToManyMapping($mapping);
  2541.         $this->_storeAssociationMapping($mapping);
  2542.     }
  2543.     /**
  2544.      * Stores the association mapping.
  2545.      *
  2546.      * @psalm-param array<string, mixed> $assocMapping
  2547.      *
  2548.      * @return void
  2549.      *
  2550.      * @throws MappingException
  2551.      */
  2552.     protected function _storeAssociationMapping(array $assocMapping)
  2553.     {
  2554.         $sourceFieldName $assocMapping['fieldName'];
  2555.         $this->assertFieldNotMapped($sourceFieldName);
  2556.         $this->associationMappings[$sourceFieldName] = $assocMapping;
  2557.     }
  2558.     /**
  2559.      * Registers a custom repository class for the entity class.
  2560.      *
  2561.      * @param string $repositoryClassName The class name of the custom mapper.
  2562.      * @psalm-param class-string $repositoryClassName
  2563.      *
  2564.      * @return void
  2565.      */
  2566.     public function setCustomRepositoryClass($repositoryClassName)
  2567.     {
  2568.         $this->customRepositoryClassName $this->fullyQualifiedClassName($repositoryClassName);
  2569.     }
  2570.     /**
  2571.      * Dispatches the lifecycle event of the given entity to the registered
  2572.      * lifecycle callbacks and lifecycle listeners.
  2573.      *
  2574.      * @deprecated Deprecated since version 2.4 in favor of \Doctrine\ORM\Event\ListenersInvoker
  2575.      *
  2576.      * @param string $lifecycleEvent The lifecycle event.
  2577.      * @param object $entity         The Entity on which the event occurred.
  2578.      *
  2579.      * @return void
  2580.      */
  2581.     public function invokeLifecycleCallbacks($lifecycleEvent$entity)
  2582.     {
  2583.         foreach ($this->lifecycleCallbacks[$lifecycleEvent] as $callback) {
  2584.             $entity->$callback();
  2585.         }
  2586.     }
  2587.     /**
  2588.      * Whether the class has any attached lifecycle listeners or callbacks for a lifecycle event.
  2589.      *
  2590.      * @param string $lifecycleEvent
  2591.      *
  2592.      * @return bool
  2593.      */
  2594.     public function hasLifecycleCallbacks($lifecycleEvent)
  2595.     {
  2596.         return isset($this->lifecycleCallbacks[$lifecycleEvent]);
  2597.     }
  2598.     /**
  2599.      * Gets the registered lifecycle callbacks for an event.
  2600.      *
  2601.      * @param string $event
  2602.      *
  2603.      * @return string[]
  2604.      * @psalm-return list<string>
  2605.      */
  2606.     public function getLifecycleCallbacks($event)
  2607.     {
  2608.         return $this->lifecycleCallbacks[$event] ?? [];
  2609.     }
  2610.     /**
  2611.      * Adds a lifecycle callback for entities of this class.
  2612.      *
  2613.      * @param string $callback
  2614.      * @param string $event
  2615.      *
  2616.      * @return void
  2617.      */
  2618.     public function addLifecycleCallback($callback$event)
  2619.     {
  2620.         if ($this->isEmbeddedClass) {
  2621.             Deprecation::trigger(
  2622.                 'doctrine/orm',
  2623.                 'https://github.com/doctrine/orm/pull/8381',
  2624.                 'Registering lifecycle callback %s on Embedded class %s is not doing anything and will throw exception in 3.0',
  2625.                 $event,
  2626.                 $this->name
  2627.             );
  2628.         }
  2629.         if (isset($this->lifecycleCallbacks[$event]) && in_array($callback$this->lifecycleCallbacks[$event], true)) {
  2630.             return;
  2631.         }
  2632.         $this->lifecycleCallbacks[$event][] = $callback;
  2633.     }
  2634.     /**
  2635.      * Sets the lifecycle callbacks for entities of this class.
  2636.      * Any previously registered callbacks are overwritten.
  2637.      *
  2638.      * @psalm-param array<string, list<string>> $callbacks
  2639.      *
  2640.      * @return void
  2641.      */
  2642.     public function setLifecycleCallbacks(array $callbacks)
  2643.     {
  2644.         $this->lifecycleCallbacks $callbacks;
  2645.     }
  2646.     /**
  2647.      * Adds a entity listener for entities of this class.
  2648.      *
  2649.      * @param string $eventName The entity lifecycle event.
  2650.      * @param string $class     The listener class.
  2651.      * @param string $method    The listener callback method.
  2652.      *
  2653.      * @return void
  2654.      *
  2655.      * @throws MappingException
  2656.      */
  2657.     public function addEntityListener($eventName$class$method)
  2658.     {
  2659.         $class $this->fullyQualifiedClassName($class);
  2660.         $listener = [
  2661.             'class'  => $class,
  2662.             'method' => $method,
  2663.         ];
  2664.         if (! class_exists($class)) {
  2665.             throw MappingException::entityListenerClassNotFound($class$this->name);
  2666.         }
  2667.         if (! method_exists($class$method)) {
  2668.             throw MappingException::entityListenerMethodNotFound($class$method$this->name);
  2669.         }
  2670.         if (isset($this->entityListeners[$eventName]) && in_array($listener$this->entityListeners[$eventName], true)) {
  2671.             throw MappingException::duplicateEntityListener($class$method$this->name);
  2672.         }
  2673.         $this->entityListeners[$eventName][] = $listener;
  2674.     }
  2675.     /**
  2676.      * Sets the discriminator column definition.
  2677.      *
  2678.      * @see getDiscriminatorColumn()
  2679.      *
  2680.      * @param mixed[]|null $columnDef
  2681.      * @psalm-param array<string, mixed>|null $columnDef
  2682.      *
  2683.      * @return void
  2684.      *
  2685.      * @throws MappingException
  2686.      */
  2687.     public function setDiscriminatorColumn($columnDef)
  2688.     {
  2689.         if ($columnDef !== null) {
  2690.             if (! isset($columnDef['name'])) {
  2691.                 throw MappingException::nameIsMandatoryForDiscriminatorColumns($this->name);
  2692.             }
  2693.             if (isset($this->fieldNames[$columnDef['name']])) {
  2694.                 throw MappingException::duplicateColumnName($this->name$columnDef['name']);
  2695.             }
  2696.             if (! isset($columnDef['fieldName'])) {
  2697.                 $columnDef['fieldName'] = $columnDef['name'];
  2698.             }
  2699.             if (! isset($columnDef['type'])) {
  2700.                 $columnDef['type'] = 'string';
  2701.             }
  2702.             if (in_array($columnDef['type'], ['boolean''array''object''datetime''time''date'], true)) {
  2703.                 throw MappingException::invalidDiscriminatorColumnType($this->name$columnDef['type']);
  2704.             }
  2705.             $this->discriminatorColumn $columnDef;
  2706.         }
  2707.     }
  2708.     /**
  2709.      * @return array<string, mixed>
  2710.      */
  2711.     final public function getDiscriminatorColumn(): array
  2712.     {
  2713.         if ($this->discriminatorColumn === null) {
  2714.             throw new LogicException('The discriminator column was not set.');
  2715.         }
  2716.         return $this->discriminatorColumn;
  2717.     }
  2718.     /**
  2719.      * Sets the discriminator values used by this class.
  2720.      * Used for JOINED and SINGLE_TABLE inheritance mapping strategies.
  2721.      *
  2722.      * @psalm-param array<string, class-string> $map
  2723.      *
  2724.      * @return void
  2725.      */
  2726.     public function setDiscriminatorMap(array $map)
  2727.     {
  2728.         foreach ($map as $value => $className) {
  2729.             $this->addDiscriminatorMapClass($value$className);
  2730.         }
  2731.     }
  2732.     /**
  2733.      * Adds one entry of the discriminator map with a new class and corresponding name.
  2734.      *
  2735.      * @param string $name
  2736.      * @param string $className
  2737.      * @psalm-param class-string $className
  2738.      *
  2739.      * @return void
  2740.      *
  2741.      * @throws MappingException
  2742.      */
  2743.     public function addDiscriminatorMapClass($name$className)
  2744.     {
  2745.         $className $this->fullyQualifiedClassName($className);
  2746.         $className ltrim($className'\\');
  2747.         $this->discriminatorMap[$name] = $className;
  2748.         if ($this->name === $className) {
  2749.             $this->discriminatorValue $name;
  2750.             return;
  2751.         }
  2752.         if (! (class_exists($className) || interface_exists($className))) {
  2753.             throw MappingException::invalidClassInDiscriminatorMap($className$this->name);
  2754.         }
  2755.         if (is_subclass_of($className$this->name) && ! in_array($className$this->subClassestrue)) {
  2756.             $this->subClasses[] = $className;
  2757.         }
  2758.     }
  2759.     /**
  2760.      * Checks whether the class has a named query with the given query name.
  2761.      *
  2762.      * @param string $queryName
  2763.      *
  2764.      * @return bool
  2765.      */
  2766.     public function hasNamedQuery($queryName)
  2767.     {
  2768.         return isset($this->namedQueries[$queryName]);
  2769.     }
  2770.     /**
  2771.      * Checks whether the class has a named native query with the given query name.
  2772.      *
  2773.      * @param string $queryName
  2774.      *
  2775.      * @return bool
  2776.      */
  2777.     public function hasNamedNativeQuery($queryName)
  2778.     {
  2779.         return isset($this->namedNativeQueries[$queryName]);
  2780.     }
  2781.     /**
  2782.      * Checks whether the class has a named native query with the given query name.
  2783.      *
  2784.      * @param string $name
  2785.      *
  2786.      * @return bool
  2787.      */
  2788.     public function hasSqlResultSetMapping($name)
  2789.     {
  2790.         return isset($this->sqlResultSetMappings[$name]);
  2791.     }
  2792.     /**
  2793.      * {@inheritDoc}
  2794.      */
  2795.     public function hasAssociation($fieldName)
  2796.     {
  2797.         return isset($this->associationMappings[$fieldName]);
  2798.     }
  2799.     /**
  2800.      * {@inheritDoc}
  2801.      */
  2802.     public function isSingleValuedAssociation($fieldName)
  2803.     {
  2804.         return isset($this->associationMappings[$fieldName])
  2805.             && ($this->associationMappings[$fieldName]['type'] & self::TO_ONE);
  2806.     }
  2807.     /**
  2808.      * {@inheritDoc}
  2809.      */
  2810.     public function isCollectionValuedAssociation($fieldName)
  2811.     {
  2812.         return isset($this->associationMappings[$fieldName])
  2813.             && ! ($this->associationMappings[$fieldName]['type'] & self::TO_ONE);
  2814.     }
  2815.     /**
  2816.      * Is this an association that only has a single join column?
  2817.      *
  2818.      * @param string $fieldName
  2819.      *
  2820.      * @return bool
  2821.      */
  2822.     public function isAssociationWithSingleJoinColumn($fieldName)
  2823.     {
  2824.         return isset($this->associationMappings[$fieldName])
  2825.             && isset($this->associationMappings[$fieldName]['joinColumns'][0])
  2826.             && ! isset($this->associationMappings[$fieldName]['joinColumns'][1]);
  2827.     }
  2828.     /**
  2829.      * Returns the single association join column (if any).
  2830.      *
  2831.      * @param string $fieldName
  2832.      *
  2833.      * @return string
  2834.      *
  2835.      * @throws MappingException
  2836.      */
  2837.     public function getSingleAssociationJoinColumnName($fieldName)
  2838.     {
  2839.         if (! $this->isAssociationWithSingleJoinColumn($fieldName)) {
  2840.             throw MappingException::noSingleAssociationJoinColumnFound($this->name$fieldName);
  2841.         }
  2842.         return $this->associationMappings[$fieldName]['joinColumns'][0]['name'];
  2843.     }
  2844.     /**
  2845.      * Returns the single association referenced join column name (if any).
  2846.      *
  2847.      * @param string $fieldName
  2848.      *
  2849.      * @return string
  2850.      *
  2851.      * @throws MappingException
  2852.      */
  2853.     public function getSingleAssociationReferencedJoinColumnName($fieldName)
  2854.     {
  2855.         if (! $this->isAssociationWithSingleJoinColumn($fieldName)) {
  2856.             throw MappingException::noSingleAssociationJoinColumnFound($this->name$fieldName);
  2857.         }
  2858.         return $this->associationMappings[$fieldName]['joinColumns'][0]['referencedColumnName'];
  2859.     }
  2860.     /**
  2861.      * Used to retrieve a fieldname for either field or association from a given column.
  2862.      *
  2863.      * This method is used in foreign-key as primary-key contexts.
  2864.      *
  2865.      * @param string $columnName
  2866.      *
  2867.      * @return string
  2868.      *
  2869.      * @throws MappingException
  2870.      */
  2871.     public function getFieldForColumn($columnName)
  2872.     {
  2873.         if (isset($this->fieldNames[$columnName])) {
  2874.             return $this->fieldNames[$columnName];
  2875.         }
  2876.         foreach ($this->associationMappings as $assocName => $mapping) {
  2877.             if (
  2878.                 $this->isAssociationWithSingleJoinColumn($assocName) &&
  2879.                 $this->associationMappings[$assocName]['joinColumns'][0]['name'] === $columnName
  2880.             ) {
  2881.                 return $assocName;
  2882.             }
  2883.         }
  2884.         throw MappingException::noFieldNameFoundForColumn($this->name$columnName);
  2885.     }
  2886.     /**
  2887.      * Sets the ID generator used to generate IDs for instances of this class.
  2888.      *
  2889.      * @param AbstractIdGenerator $generator
  2890.      *
  2891.      * @return void
  2892.      */
  2893.     public function setIdGenerator($generator)
  2894.     {
  2895.         $this->idGenerator $generator;
  2896.     }
  2897.     /**
  2898.      * Sets definition.
  2899.      *
  2900.      * @psalm-param array<string, string|null> $definition
  2901.      *
  2902.      * @return void
  2903.      */
  2904.     public function setCustomGeneratorDefinition(array $definition)
  2905.     {
  2906.         $this->customGeneratorDefinition $definition;
  2907.     }
  2908.     /**
  2909.      * Sets the definition of the sequence ID generator for this class.
  2910.      *
  2911.      * The definition must have the following structure:
  2912.      * <code>
  2913.      * array(
  2914.      *     'sequenceName'   => 'name',
  2915.      *     'allocationSize' => 20,
  2916.      *     'initialValue'   => 1
  2917.      *     'quoted'         => 1
  2918.      * )
  2919.      * </code>
  2920.      *
  2921.      * @psalm-param array{sequenceName?: string, allocationSize?: int|string, initialValue?: int|string, quoted?: mixed} $definition
  2922.      *
  2923.      * @return void
  2924.      *
  2925.      * @throws MappingException
  2926.      */
  2927.     public function setSequenceGeneratorDefinition(array $definition)
  2928.     {
  2929.         if (! isset($definition['sequenceName']) || trim($definition['sequenceName']) === '') {
  2930.             throw MappingException::missingSequenceName($this->name);
  2931.         }
  2932.         if ($definition['sequenceName'][0] === '`') {
  2933.             $definition['sequenceName'] = trim($definition['sequenceName'], '`');
  2934.             $definition['quoted']       = true;
  2935.         }
  2936.         if (! isset($definition['allocationSize']) || trim((string) $definition['allocationSize']) === '') {
  2937.             $definition['allocationSize'] = '1';
  2938.         }
  2939.         if (! isset($definition['initialValue']) || trim((string) $definition['initialValue']) === '') {
  2940.             $definition['initialValue'] = '1';
  2941.         }
  2942.         $definition['allocationSize'] = (string) $definition['allocationSize'];
  2943.         $definition['initialValue']   = (string) $definition['initialValue'];
  2944.         $this->sequenceGeneratorDefinition $definition;
  2945.     }
  2946.     /**
  2947.      * Sets the version field mapping used for versioning. Sets the default
  2948.      * value to use depending on the column type.
  2949.      *
  2950.      * @psalm-param array<string, mixed> $mapping The version field mapping array.
  2951.      *
  2952.      * @return void
  2953.      *
  2954.      * @throws MappingException
  2955.      */
  2956.     public function setVersionMapping(array &$mapping)
  2957.     {
  2958.         $this->isVersioned  true;
  2959.         $this->versionField $mapping['fieldName'];
  2960.         if (! isset($mapping['default'])) {
  2961.             if (in_array($mapping['type'], ['integer''bigint''smallint'], true)) {
  2962.                 $mapping['default'] = 1;
  2963.             } elseif ($mapping['type'] === 'datetime') {
  2964.                 $mapping['default'] = 'CURRENT_TIMESTAMP';
  2965.             } else {
  2966.                 throw MappingException::unsupportedOptimisticLockingType($this->name$mapping['fieldName'], $mapping['type']);
  2967.             }
  2968.         }
  2969.     }
  2970.     /**
  2971.      * Sets whether this class is to be versioned for optimistic locking.
  2972.      *
  2973.      * @param bool $bool
  2974.      *
  2975.      * @return void
  2976.      */
  2977.     public function setVersioned($bool)
  2978.     {
  2979.         $this->isVersioned $bool;
  2980.     }
  2981.     /**
  2982.      * Sets the name of the field that is to be used for versioning if this class is
  2983.      * versioned for optimistic locking.
  2984.      *
  2985.      * @param string $versionField
  2986.      *
  2987.      * @return void
  2988.      */
  2989.     public function setVersionField($versionField)
  2990.     {
  2991.         $this->versionField $versionField;
  2992.     }
  2993.     /**
  2994.      * Marks this class as read only, no change tracking is applied to it.
  2995.      *
  2996.      * @return void
  2997.      */
  2998.     public function markReadOnly()
  2999.     {
  3000.         $this->isReadOnly true;
  3001.     }
  3002.     /**
  3003.      * {@inheritDoc}
  3004.      */
  3005.     public function getFieldNames()
  3006.     {
  3007.         return array_keys($this->fieldMappings);
  3008.     }
  3009.     /**
  3010.      * {@inheritDoc}
  3011.      */
  3012.     public function getAssociationNames()
  3013.     {
  3014.         return array_keys($this->associationMappings);
  3015.     }
  3016.     /**
  3017.      * {@inheritDoc}
  3018.      *
  3019.      * @param string $assocName
  3020.      *
  3021.      * @return string
  3022.      * @psalm-return class-string
  3023.      *
  3024.      * @throws InvalidArgumentException
  3025.      */
  3026.     public function getAssociationTargetClass($assocName)
  3027.     {
  3028.         if (! isset($this->associationMappings[$assocName])) {
  3029.             throw new InvalidArgumentException("Association name expected, '" $assocName "' is not an association.");
  3030.         }
  3031.         return $this->associationMappings[$assocName]['targetEntity'];
  3032.     }
  3033.     /**
  3034.      * {@inheritDoc}
  3035.      */
  3036.     public function getName()
  3037.     {
  3038.         return $this->name;
  3039.     }
  3040.     /**
  3041.      * Gets the (possibly quoted) identifier column names for safe use in an SQL statement.
  3042.      *
  3043.      * @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy
  3044.      *
  3045.      * @param AbstractPlatform $platform
  3046.      *
  3047.      * @return string[]
  3048.      * @psalm-return list<string>
  3049.      */
  3050.     public function getQuotedIdentifierColumnNames($platform)
  3051.     {
  3052.         $quotedColumnNames = [];
  3053.         foreach ($this->identifier as $idProperty) {
  3054.             if (isset($this->fieldMappings[$idProperty])) {
  3055.                 $quotedColumnNames[] = isset($this->fieldMappings[$idProperty]['quoted'])
  3056.                     ? $platform->quoteIdentifier($this->fieldMappings[$idProperty]['columnName'])
  3057.                     : $this->fieldMappings[$idProperty]['columnName'];
  3058.                 continue;
  3059.             }
  3060.             // Association defined as Id field
  3061.             $joinColumns            $this->associationMappings[$idProperty]['joinColumns'];
  3062.             $assocQuotedColumnNames array_map(
  3063.                 static function ($joinColumn) use ($platform) {
  3064.                     return isset($joinColumn['quoted'])
  3065.                         ? $platform->quoteIdentifier($joinColumn['name'])
  3066.                         : $joinColumn['name'];
  3067.                 },
  3068.                 $joinColumns
  3069.             );
  3070.             $quotedColumnNames array_merge($quotedColumnNames$assocQuotedColumnNames);
  3071.         }
  3072.         return $quotedColumnNames;
  3073.     }
  3074.     /**
  3075.      * Gets the (possibly quoted) column name of a mapped field for safe use  in an SQL statement.
  3076.      *
  3077.      * @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy
  3078.      *
  3079.      * @param string           $field
  3080.      * @param AbstractPlatform $platform
  3081.      *
  3082.      * @return string
  3083.      */
  3084.     public function getQuotedColumnName($field$platform)
  3085.     {
  3086.         return isset($this->fieldMappings[$field]['quoted'])
  3087.             ? $platform->quoteIdentifier($this->fieldMappings[$field]['columnName'])
  3088.             : $this->fieldMappings[$field]['columnName'];
  3089.     }
  3090.     /**
  3091.      * Gets the (possibly quoted) primary table name of this class for safe use in an SQL statement.
  3092.      *
  3093.      * @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy
  3094.      *
  3095.      * @param AbstractPlatform $platform
  3096.      *
  3097.      * @return string
  3098.      */
  3099.     public function getQuotedTableName($platform)
  3100.     {
  3101.         return isset($this->table['quoted'])
  3102.             ? $platform->quoteIdentifier($this->table['name'])
  3103.             : $this->table['name'];
  3104.     }
  3105.     /**
  3106.      * Gets the (possibly quoted) name of the join table.
  3107.      *
  3108.      * @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy
  3109.      *
  3110.      * @param mixed[]          $assoc
  3111.      * @param AbstractPlatform $platform
  3112.      *
  3113.      * @return string
  3114.      */
  3115.     public function getQuotedJoinTableName(array $assoc$platform)
  3116.     {
  3117.         return isset($assoc['joinTable']['quoted'])
  3118.             ? $platform->quoteIdentifier($assoc['joinTable']['name'])
  3119.             : $assoc['joinTable']['name'];
  3120.     }
  3121.     /**
  3122.      * {@inheritDoc}
  3123.      */
  3124.     public function isAssociationInverseSide($fieldName)
  3125.     {
  3126.         return isset($this->associationMappings[$fieldName])
  3127.             && ! $this->associationMappings[$fieldName]['isOwningSide'];
  3128.     }
  3129.     /**
  3130.      * {@inheritDoc}
  3131.      */
  3132.     public function getAssociationMappedByTargetField($fieldName)
  3133.     {
  3134.         return $this->associationMappings[$fieldName]['mappedBy'];
  3135.     }
  3136.     /**
  3137.      * @param string $targetClass
  3138.      *
  3139.      * @return mixed[][]
  3140.      * @psalm-return array<string, array<string, mixed>>
  3141.      */
  3142.     public function getAssociationsByTargetClass($targetClass)
  3143.     {
  3144.         $relations = [];
  3145.         foreach ($this->associationMappings as $mapping) {
  3146.             if ($mapping['targetEntity'] === $targetClass) {
  3147.                 $relations[$mapping['fieldName']] = $mapping;
  3148.             }
  3149.         }
  3150.         return $relations;
  3151.     }
  3152.     /**
  3153.      * @param string|null $className
  3154.      * @psalm-param ?class-string $className
  3155.      *
  3156.      * @return string|null null if the input value is null
  3157.      */
  3158.     public function fullyQualifiedClassName($className)
  3159.     {
  3160.         if (empty($className)) {
  3161.             return $className;
  3162.         }
  3163.         if ($className !== null && strpos($className'\\') === false && $this->namespace) {
  3164.             return $this->namespace '\\' $className;
  3165.         }
  3166.         return $className;
  3167.     }
  3168.     /**
  3169.      * @param string $name
  3170.      *
  3171.      * @return mixed
  3172.      */
  3173.     public function getMetadataValue($name)
  3174.     {
  3175.         if (isset($this->$name)) {
  3176.             return $this->$name;
  3177.         }
  3178.         return null;
  3179.     }
  3180.     /**
  3181.      * Map Embedded Class
  3182.      *
  3183.      * @psalm-param array<string, mixed> $mapping
  3184.      *
  3185.      * @return void
  3186.      *
  3187.      * @throws MappingException
  3188.      */
  3189.     public function mapEmbedded(array $mapping)
  3190.     {
  3191.         $this->assertFieldNotMapped($mapping['fieldName']);
  3192.         if (! isset($mapping['class']) && $this->isTypedProperty($mapping['fieldName'])) {
  3193.             $type $this->reflClass->getProperty($mapping['fieldName'])->getType();
  3194.             if ($type instanceof ReflectionNamedType) {
  3195.                 $mapping['class'] = $type->getName();
  3196.             }
  3197.         }
  3198.         $this->embeddedClasses[$mapping['fieldName']] = [
  3199.             'class' => $this->fullyQualifiedClassName($mapping['class']),
  3200.             'columnPrefix' => $mapping['columnPrefix'] ?? null,
  3201.             'declaredField' => $mapping['declaredField'] ?? null,
  3202.             'originalField' => $mapping['originalField'] ?? null,
  3203.         ];
  3204.     }
  3205.     /**
  3206.      * Inline the embeddable class
  3207.      *
  3208.      * @param string $property
  3209.      *
  3210.      * @return void
  3211.      */
  3212.     public function inlineEmbeddable($propertyClassMetadataInfo $embeddable)
  3213.     {
  3214.         foreach ($embeddable->fieldMappings as $fieldMapping) {
  3215.             $fieldMapping['originalClass'] = $fieldMapping['originalClass'] ?? $embeddable->name;
  3216.             $fieldMapping['declaredField'] = isset($fieldMapping['declaredField'])
  3217.                 ? $property '.' $fieldMapping['declaredField']
  3218.                 : $property;
  3219.             $fieldMapping['originalField'] = $fieldMapping['originalField'] ?? $fieldMapping['fieldName'];
  3220.             $fieldMapping['fieldName']     = $property '.' $fieldMapping['fieldName'];
  3221.             if (! empty($this->embeddedClasses[$property]['columnPrefix'])) {
  3222.                 $fieldMapping['columnName'] = $this->embeddedClasses[$property]['columnPrefix'] . $fieldMapping['columnName'];
  3223.             } elseif ($this->embeddedClasses[$property]['columnPrefix'] !== false) {
  3224.                 $fieldMapping['columnName'] = $this->namingStrategy
  3225.                     ->embeddedFieldToColumnName(
  3226.                         $property,
  3227.                         $fieldMapping['columnName'],
  3228.                         $this->reflClass->name,
  3229.                         $embeddable->reflClass->name
  3230.                     );
  3231.             }
  3232.             $this->mapField($fieldMapping);
  3233.         }
  3234.     }
  3235.     /**
  3236.      * @throws MappingException
  3237.      */
  3238.     private function assertFieldNotMapped(string $fieldName): void
  3239.     {
  3240.         if (
  3241.             isset($this->fieldMappings[$fieldName]) ||
  3242.             isset($this->associationMappings[$fieldName]) ||
  3243.             isset($this->embeddedClasses[$fieldName])
  3244.         ) {
  3245.             throw MappingException::duplicateFieldMapping($this->name$fieldName);
  3246.         }
  3247.     }
  3248.     /**
  3249.      * Gets the sequence name based on class metadata.
  3250.      *
  3251.      * @return string
  3252.      *
  3253.      * @todo Sequence names should be computed in DBAL depending on the platform
  3254.      */
  3255.     public function getSequenceName(AbstractPlatform $platform)
  3256.     {
  3257.         $sequencePrefix $this->getSequencePrefix($platform);
  3258.         $columnName     $this->getSingleIdentifierColumnName();
  3259.         return $sequencePrefix '_' $columnName '_seq';
  3260.     }
  3261.     /**
  3262.      * Gets the sequence name prefix based on class metadata.
  3263.      *
  3264.      * @return string
  3265.      *
  3266.      * @todo Sequence names should be computed in DBAL depending on the platform
  3267.      */
  3268.     public function getSequencePrefix(AbstractPlatform $platform)
  3269.     {
  3270.         $tableName      $this->getTableName();
  3271.         $sequencePrefix $tableName;
  3272.         // Prepend the schema name to the table name if there is one
  3273.         $schemaName $this->getSchemaName();
  3274.         if ($schemaName) {
  3275.             $sequencePrefix $schemaName '.' $tableName;
  3276.             if (! $platform->supportsSchemas() && $platform->canEmulateSchemas()) {
  3277.                 $sequencePrefix $schemaName '__' $tableName;
  3278.             }
  3279.         }
  3280.         return $sequencePrefix;
  3281.     }
  3282.     /**
  3283.      * @psalm-param array<string, mixed> $mapping
  3284.      */
  3285.     private function assertMappingOrderBy(array $mapping): void
  3286.     {
  3287.         if (isset($mapping['orderBy']) && ! is_array($mapping['orderBy'])) {
  3288.             throw new InvalidArgumentException("'orderBy' is expected to be an array, not " gettype($mapping['orderBy']));
  3289.         }
  3290.     }
  3291. }