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

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