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

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