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

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