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

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 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 mixed[]
  573.      * @psalm-var array{sequenceName: string, allocationSize: int, initialValue: int}
  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.      */
  642.     public function __construct($entityName, ?NamingStrategy $namingStrategy null)
  643.     {
  644.         $this->name           $entityName;
  645.         $this->rootEntityName $entityName;
  646.         $this->namingStrategy $namingStrategy ?: new DefaultNamingStrategy();
  647.         $this->instantiator   = new Instantiator();
  648.     }
  649.     /**
  650.      * Gets the ReflectionProperties of the mapped class.
  651.      *
  652.      * @return ReflectionProperty[]|null[] An array of ReflectionProperty instances.
  653.      * @psalm-return array<ReflectionProperty|null>
  654.      */
  655.     public function getReflectionProperties()
  656.     {
  657.         return $this->reflFields;
  658.     }
  659.     /**
  660.      * Gets a ReflectionProperty for a specific field of the mapped class.
  661.      *
  662.      * @param string $name
  663.      *
  664.      * @return ReflectionProperty
  665.      */
  666.     public function getReflectionProperty($name)
  667.     {
  668.         return $this->reflFields[$name];
  669.     }
  670.     /**
  671.      * Gets the ReflectionProperty for the single identifier field.
  672.      *
  673.      * @return ReflectionProperty
  674.      *
  675.      * @throws BadMethodCallException If the class has a composite identifier.
  676.      */
  677.     public function getSingleIdReflectionProperty()
  678.     {
  679.         if ($this->isIdentifierComposite) {
  680.             throw new BadMethodCallException('Class ' $this->name ' has a composite identifier.');
  681.         }
  682.         return $this->reflFields[$this->identifier[0]];
  683.     }
  684.     /**
  685.      * Extracts the identifier values of an entity of this class.
  686.      *
  687.      * For composite identifiers, the identifier values are returned as an array
  688.      * with the same order as the field order in {@link identifier}.
  689.      *
  690.      * @param object $entity
  691.      *
  692.      * @return array<string, mixed>
  693.      */
  694.     public function getIdentifierValues($entity)
  695.     {
  696.         if ($this->isIdentifierComposite) {
  697.             $id = [];
  698.             foreach ($this->identifier as $idField) {
  699.                 $value $this->reflFields[$idField]->getValue($entity);
  700.                 if ($value !== null) {
  701.                     $id[$idField] = $value;
  702.                 }
  703.             }
  704.             return $id;
  705.         }
  706.         $id    $this->identifier[0];
  707.         $value $this->reflFields[$id]->getValue($entity);
  708.         if ($value === null) {
  709.             return [];
  710.         }
  711.         return [$id => $value];
  712.     }
  713.     /**
  714.      * Populates the entity identifier of an entity.
  715.      *
  716.      * @param object $entity
  717.      * @psalm-param array<string, mixed> $id
  718.      *
  719.      * @return void
  720.      *
  721.      * @todo Rename to assignIdentifier()
  722.      */
  723.     public function setIdentifierValues($entity, array $id)
  724.     {
  725.         foreach ($id as $idField => $idValue) {
  726.             $this->reflFields[$idField]->setValue($entity$idValue);
  727.         }
  728.     }
  729.     /**
  730.      * Sets the specified field to the specified value on the given entity.
  731.      *
  732.      * @param object $entity
  733.      * @param string $field
  734.      * @param mixed  $value
  735.      *
  736.      * @return void
  737.      */
  738.     public function setFieldValue($entity$field$value)
  739.     {
  740.         $this->reflFields[$field]->setValue($entity$value);
  741.     }
  742.     /**
  743.      * Gets the specified field's value off the given entity.
  744.      *
  745.      * @param object $entity
  746.      * @param string $field
  747.      *
  748.      * @return mixed
  749.      */
  750.     public function getFieldValue($entity$field)
  751.     {
  752.         return $this->reflFields[$field]->getValue($entity);
  753.     }
  754.     /**
  755.      * Creates a string representation of this instance.
  756.      *
  757.      * @return string The string representation of this instance.
  758.      *
  759.      * @todo Construct meaningful string representation.
  760.      */
  761.     public function __toString()
  762.     {
  763.         return self::class . '@' spl_object_hash($this);
  764.     }
  765.     /**
  766.      * Determines which fields get serialized.
  767.      *
  768.      * It is only serialized what is necessary for best unserialization performance.
  769.      * That means any metadata properties that are not set or empty or simply have
  770.      * their default value are NOT serialized.
  771.      *
  772.      * Parts that are also NOT serialized because they can not be properly unserialized:
  773.      *      - reflClass (ReflectionClass)
  774.      *      - reflFields (ReflectionProperty array)
  775.      *
  776.      * @return string[] The names of all the fields that should be serialized.
  777.      */
  778.     public function __sleep()
  779.     {
  780.         // This metadata is always serialized/cached.
  781.         $serialized = [
  782.             'associationMappings',
  783.             'columnNames'//TODO: 3.0 Remove this. Can use fieldMappings[$fieldName]['columnName']
  784.             'fieldMappings',
  785.             'fieldNames',
  786.             'embeddedClasses',
  787.             'identifier',
  788.             'isIdentifierComposite'// TODO: REMOVE
  789.             'name',
  790.             'namespace'// TODO: REMOVE
  791.             'table',
  792.             'rootEntityName',
  793.             'idGenerator'//TODO: Does not really need to be serialized. Could be moved to runtime.
  794.         ];
  795.         // The rest of the metadata is only serialized if necessary.
  796.         if ($this->changeTrackingPolicy !== self::CHANGETRACKING_DEFERRED_IMPLICIT) {
  797.             $serialized[] = 'changeTrackingPolicy';
  798.         }
  799.         if ($this->customRepositoryClassName) {
  800.             $serialized[] = 'customRepositoryClassName';
  801.         }
  802.         if ($this->inheritanceType !== self::INHERITANCE_TYPE_NONE) {
  803.             $serialized[] = 'inheritanceType';
  804.             $serialized[] = 'discriminatorColumn';
  805.             $serialized[] = 'discriminatorValue';
  806.             $serialized[] = 'discriminatorMap';
  807.             $serialized[] = 'parentClasses';
  808.             $serialized[] = 'subClasses';
  809.         }
  810.         if ($this->generatorType !== self::GENERATOR_TYPE_NONE) {
  811.             $serialized[] = 'generatorType';
  812.             if ($this->generatorType === self::GENERATOR_TYPE_SEQUENCE) {
  813.                 $serialized[] = 'sequenceGeneratorDefinition';
  814.             }
  815.         }
  816.         if ($this->isMappedSuperclass) {
  817.             $serialized[] = 'isMappedSuperclass';
  818.         }
  819.         if ($this->isEmbeddedClass) {
  820.             $serialized[] = 'isEmbeddedClass';
  821.         }
  822.         if ($this->containsForeignIdentifier) {
  823.             $serialized[] = 'containsForeignIdentifier';
  824.         }
  825.         if ($this->isVersioned) {
  826.             $serialized[] = 'isVersioned';
  827.             $serialized[] = 'versionField';
  828.         }
  829.         if ($this->lifecycleCallbacks) {
  830.             $serialized[] = 'lifecycleCallbacks';
  831.         }
  832.         if ($this->entityListeners) {
  833.             $serialized[] = 'entityListeners';
  834.         }
  835.         if ($this->namedQueries) {
  836.             $serialized[] = 'namedQueries';
  837.         }
  838.         if ($this->namedNativeQueries) {
  839.             $serialized[] = 'namedNativeQueries';
  840.         }
  841.         if ($this->sqlResultSetMappings) {
  842.             $serialized[] = 'sqlResultSetMappings';
  843.         }
  844.         if ($this->isReadOnly) {
  845.             $serialized[] = 'isReadOnly';
  846.         }
  847.         if ($this->customGeneratorDefinition) {
  848.             $serialized[] = 'customGeneratorDefinition';
  849.         }
  850.         if ($this->cache) {
  851.             $serialized[] = 'cache';
  852.         }
  853.         return $serialized;
  854.     }
  855.     /**
  856.      * Creates a new instance of the mapped class, without invoking the constructor.
  857.      *
  858.      * @return object
  859.      */
  860.     public function newInstance()
  861.     {
  862.         return $this->instantiator->instantiate($this->name);
  863.     }
  864.     /**
  865.      * Restores some state that can not be serialized/unserialized.
  866.      *
  867.      * @param ReflectionService $reflService
  868.      *
  869.      * @return void
  870.      */
  871.     public function wakeupReflection($reflService)
  872.     {
  873.         // Restore ReflectionClass and properties
  874.         $this->reflClass    $reflService->getClass($this->name);
  875.         $this->instantiator $this->instantiator ?: new Instantiator();
  876.         $parentReflFields = [];
  877.         foreach ($this->embeddedClasses as $property => $embeddedClass) {
  878.             if (isset($embeddedClass['declaredField'])) {
  879.                 $parentReflFields[$property] = new ReflectionEmbeddedProperty(
  880.                     $parentReflFields[$embeddedClass['declaredField']],
  881.                     $reflService->getAccessibleProperty(
  882.                         $this->embeddedClasses[$embeddedClass['declaredField']]['class'],
  883.                         $embeddedClass['originalField']
  884.                     ),
  885.                     $this->embeddedClasses[$embeddedClass['declaredField']]['class']
  886.                 );
  887.                 continue;
  888.             }
  889.             $fieldRefl $reflService->getAccessibleProperty(
  890.                 $embeddedClass['declared'] ?? $this->name,
  891.                 $property
  892.             );
  893.             $parentReflFields[$property] = $fieldRefl;
  894.             $this->reflFields[$property] = $fieldRefl;
  895.         }
  896.         foreach ($this->fieldMappings as $field => $mapping) {
  897.             if (isset($mapping['declaredField']) && isset($parentReflFields[$mapping['declaredField']])) {
  898.                 $this->reflFields[$field] = new ReflectionEmbeddedProperty(
  899.                     $parentReflFields[$mapping['declaredField']],
  900.                     $reflService->getAccessibleProperty($mapping['originalClass'], $mapping['originalField']),
  901.                     $mapping['originalClass']
  902.                 );
  903.                 continue;
  904.             }
  905.             $this->reflFields[$field] = isset($mapping['declared'])
  906.                 ? $reflService->getAccessibleProperty($mapping['declared'], $field)
  907.                 : $reflService->getAccessibleProperty($this->name$field);
  908.         }
  909.         foreach ($this->associationMappings as $field => $mapping) {
  910.             $this->reflFields[$field] = isset($mapping['declared'])
  911.                 ? $reflService->getAccessibleProperty($mapping['declared'], $field)
  912.                 : $reflService->getAccessibleProperty($this->name$field);
  913.         }
  914.     }
  915.     /**
  916.      * Initializes a new ClassMetadata instance that will hold the object-relational mapping
  917.      * metadata of the class with the given name.
  918.      *
  919.      * @param ReflectionService $reflService The reflection service.
  920.      *
  921.      * @return void
  922.      */
  923.     public function initializeReflection($reflService)
  924.     {
  925.         $this->reflClass $reflService->getClass($this->name);
  926.         $this->namespace $reflService->getClassNamespace($this->name);
  927.         if ($this->reflClass) {
  928.             $this->name $this->rootEntityName $this->reflClass->getName();
  929.         }
  930.         $this->table['name'] = $this->namingStrategy->classToTableName($this->name);
  931.     }
  932.     /**
  933.      * Validates Identifier.
  934.      *
  935.      * @return void
  936.      *
  937.      * @throws MappingException
  938.      */
  939.     public function validateIdentifier()
  940.     {
  941.         if ($this->isMappedSuperclass || $this->isEmbeddedClass) {
  942.             return;
  943.         }
  944.         // Verify & complete identifier mapping
  945.         if (! $this->identifier) {
  946.             throw MappingException::identifierRequired($this->name);
  947.         }
  948.         if ($this->usesIdGenerator() && $this->isIdentifierComposite) {
  949.             throw MappingException::compositeKeyAssignedIdGeneratorRequired($this->name);
  950.         }
  951.     }
  952.     /**
  953.      * Validates association targets actually exist.
  954.      *
  955.      * @return void
  956.      *
  957.      * @throws MappingException
  958.      */
  959.     public function validateAssociations()
  960.     {
  961.         foreach ($this->associationMappings as $mapping) {
  962.             if (
  963.                 ! class_exists($mapping['targetEntity'])
  964.                 && ! interface_exists($mapping['targetEntity'])
  965.                 && ! trait_exists($mapping['targetEntity'])
  966.             ) {
  967.                 throw MappingException::invalidTargetEntityClass($mapping['targetEntity'], $this->name$mapping['fieldName']);
  968.             }
  969.         }
  970.     }
  971.     /**
  972.      * Validates lifecycle callbacks.
  973.      *
  974.      * @param ReflectionService $reflService
  975.      *
  976.      * @return void
  977.      *
  978.      * @throws MappingException
  979.      */
  980.     public function validateLifecycleCallbacks($reflService)
  981.     {
  982.         foreach ($this->lifecycleCallbacks as $callbacks) {
  983.             foreach ($callbacks as $callbackFuncName) {
  984.                 if (! $reflService->hasPublicMethod($this->name$callbackFuncName)) {
  985.                     throw MappingException::lifecycleCallbackMethodNotFound($this->name$callbackFuncName);
  986.                 }
  987.             }
  988.         }
  989.     }
  990.     /**
  991.      * {@inheritDoc}
  992.      */
  993.     public function getReflectionClass()
  994.     {
  995.         return $this->reflClass;
  996.     }
  997.     /**
  998.      * @psalm-param array{usage?: mixed, region?: mixed} $cache
  999.      *
  1000.      * @return void
  1001.      */
  1002.     public function enableCache(array $cache)
  1003.     {
  1004.         if (! isset($cache['usage'])) {
  1005.             $cache['usage'] = self::CACHE_USAGE_READ_ONLY;
  1006.         }
  1007.         if (! isset($cache['region'])) {
  1008.             $cache['region'] = strtolower(str_replace('\\''_'$this->rootEntityName));
  1009.         }
  1010.         $this->cache $cache;
  1011.     }
  1012.     /**
  1013.      * @param string $fieldName
  1014.      * @psalm-param array{usage?: int, region?: string} $cache
  1015.      *
  1016.      * @return void
  1017.      */
  1018.     public function enableAssociationCache($fieldName, array $cache)
  1019.     {
  1020.         $this->associationMappings[$fieldName]['cache'] = $this->getAssociationCacheDefaults($fieldName$cache);
  1021.     }
  1022.     /**
  1023.      * @param string $fieldName
  1024.      * @param array  $cache
  1025.      * @psalm-param array{usage?: int, region?: string} $cache
  1026.      *
  1027.      * @return int[]|string[]
  1028.      * @psalm-return array{usage: int, region: string|null}
  1029.      */
  1030.     public function getAssociationCacheDefaults($fieldName, array $cache)
  1031.     {
  1032.         if (! isset($cache['usage'])) {
  1033.             $cache['usage'] = $this->cache['usage'] ?? self::CACHE_USAGE_READ_ONLY;
  1034.         }
  1035.         if (! isset($cache['region'])) {
  1036.             $cache['region'] = strtolower(str_replace('\\''_'$this->rootEntityName)) . '__' $fieldName;
  1037.         }
  1038.         return $cache;
  1039.     }
  1040.     /**
  1041.      * Sets the change tracking policy used by this class.
  1042.      *
  1043.      * @param int $policy
  1044.      *
  1045.      * @return void
  1046.      */
  1047.     public function setChangeTrackingPolicy($policy)
  1048.     {
  1049.         $this->changeTrackingPolicy $policy;
  1050.     }
  1051.     /**
  1052.      * Whether the change tracking policy of this class is "deferred explicit".
  1053.      *
  1054.      * @return bool
  1055.      */
  1056.     public function isChangeTrackingDeferredExplicit()
  1057.     {
  1058.         return $this->changeTrackingPolicy === self::CHANGETRACKING_DEFERRED_EXPLICIT;
  1059.     }
  1060.     /**
  1061.      * Whether the change tracking policy of this class is "deferred implicit".
  1062.      *
  1063.      * @return bool
  1064.      */
  1065.     public function isChangeTrackingDeferredImplicit()
  1066.     {
  1067.         return $this->changeTrackingPolicy === self::CHANGETRACKING_DEFERRED_IMPLICIT;
  1068.     }
  1069.     /**
  1070.      * Whether the change tracking policy of this class is "notify".
  1071.      *
  1072.      * @return bool
  1073.      */
  1074.     public function isChangeTrackingNotify()
  1075.     {
  1076.         return $this->changeTrackingPolicy === self::CHANGETRACKING_NOTIFY;
  1077.     }
  1078.     /**
  1079.      * Checks whether a field is part of the identifier/primary key field(s).
  1080.      *
  1081.      * @param string $fieldName The field name.
  1082.      *
  1083.      * @return bool TRUE if the field is part of the table identifier/primary key field(s),
  1084.      * FALSE otherwise.
  1085.      */
  1086.     public function isIdentifier($fieldName)
  1087.     {
  1088.         if (! $this->identifier) {
  1089.             return false;
  1090.         }
  1091.         if (! $this->isIdentifierComposite) {
  1092.             return $fieldName === $this->identifier[0];
  1093.         }
  1094.         return in_array($fieldName$this->identifiertrue);
  1095.     }
  1096.     /**
  1097.      * Checks if the field is unique.
  1098.      *
  1099.      * @param string $fieldName The field name.
  1100.      *
  1101.      * @return bool TRUE if the field is unique, FALSE otherwise.
  1102.      */
  1103.     public function isUniqueField($fieldName)
  1104.     {
  1105.         $mapping $this->getFieldMapping($fieldName);
  1106.         return $mapping !== false && isset($mapping['unique']) && $mapping['unique'];
  1107.     }
  1108.     /**
  1109.      * Checks if the field is not null.
  1110.      *
  1111.      * @param string $fieldName The field name.
  1112.      *
  1113.      * @return bool TRUE if the field is not null, FALSE otherwise.
  1114.      */
  1115.     public function isNullable($fieldName)
  1116.     {
  1117.         $mapping $this->getFieldMapping($fieldName);
  1118.         return $mapping !== false && isset($mapping['nullable']) && $mapping['nullable'];
  1119.     }
  1120.     /**
  1121.      * Gets a column name for a field name.
  1122.      * If the column name for the field cannot be found, the given field name
  1123.      * is returned.
  1124.      *
  1125.      * @param string $fieldName The field name.
  1126.      *
  1127.      * @return string The column name.
  1128.      */
  1129.     public function getColumnName($fieldName)
  1130.     {
  1131.         return $this->columnNames[$fieldName] ?? $fieldName;
  1132.     }
  1133.     /**
  1134.      * Gets the mapping of a (regular) field that holds some data but not a
  1135.      * reference to another object.
  1136.      *
  1137.      * @param string $fieldName The field name.
  1138.      *
  1139.      * @return mixed[] The field mapping.
  1140.      * @psalm-return array{
  1141.      *      type: string,
  1142.      *      fieldName: string,
  1143.      *      columnName?: string,
  1144.      *      inherited?: class-string,
  1145.      *      nullable?: bool,
  1146.      *      originalClass?: class-string,
  1147.      *      originalField?: string,
  1148.      *      scale?: int,
  1149.      *      precision?: int,
  1150.      *      length?: int
  1151.      * }
  1152.      *
  1153.      * @throws MappingException
  1154.      */
  1155.     public function getFieldMapping($fieldName)
  1156.     {
  1157.         if (! isset($this->fieldMappings[$fieldName])) {
  1158.             throw MappingException::mappingNotFound($this->name$fieldName);
  1159.         }
  1160.         return $this->fieldMappings[$fieldName];
  1161.     }
  1162.     /**
  1163.      * Gets the mapping of an association.
  1164.      *
  1165.      * @see ClassMetadataInfo::$associationMappings
  1166.      *
  1167.      * @param string $fieldName The field name that represents the association in
  1168.      *                          the object model.
  1169.      *
  1170.      * @psalm-return array<string, mixed> The mapping.
  1171.      *
  1172.      * @throws MappingException
  1173.      */
  1174.     public function getAssociationMapping($fieldName)
  1175.     {
  1176.         if (! isset($this->associationMappings[$fieldName])) {
  1177.             throw MappingException::mappingNotFound($this->name$fieldName);
  1178.         }
  1179.         return $this->associationMappings[$fieldName];
  1180.     }
  1181.     /**
  1182.      * Gets all association mappings of the class.
  1183.      *
  1184.      * @psalm-return array<string, array<string, mixed>>
  1185.      */
  1186.     public function getAssociationMappings()
  1187.     {
  1188.         return $this->associationMappings;
  1189.     }
  1190.     /**
  1191.      * Gets the field name for a column name.
  1192.      * If no field name can be found the column name is returned.
  1193.      *
  1194.      * @param string $columnName The column name.
  1195.      *
  1196.      * @return string The column alias.
  1197.      */
  1198.     public function getFieldName($columnName)
  1199.     {
  1200.         return $this->fieldNames[$columnName] ?? $columnName;
  1201.     }
  1202.     /**
  1203.      * Gets the named query.
  1204.      *
  1205.      * @see ClassMetadataInfo::$namedQueries
  1206.      *
  1207.      * @param string $queryName The query name.
  1208.      *
  1209.      * @return string
  1210.      *
  1211.      * @throws MappingException
  1212.      */
  1213.     public function getNamedQuery($queryName)
  1214.     {
  1215.         if (! isset($this->namedQueries[$queryName])) {
  1216.             throw MappingException::queryNotFound($this->name$queryName);
  1217.         }
  1218.         return $this->namedQueries[$queryName]['dql'];
  1219.     }
  1220.     /**
  1221.      * Gets all named queries of the class.
  1222.      *
  1223.      * @return mixed[][]
  1224.      * @psalm-return array<string, array<string, mixed>>
  1225.      */
  1226.     public function getNamedQueries()
  1227.     {
  1228.         return $this->namedQueries;
  1229.     }
  1230.     /**
  1231.      * Gets the named native query.
  1232.      *
  1233.      * @see ClassMetadataInfo::$namedNativeQueries
  1234.      *
  1235.      * @param string $queryName The query name.
  1236.      *
  1237.      * @psalm-return array<string, mixed>
  1238.      *
  1239.      * @throws MappingException
  1240.      */
  1241.     public function getNamedNativeQuery($queryName)
  1242.     {
  1243.         if (! isset($this->namedNativeQueries[$queryName])) {
  1244.             throw MappingException::queryNotFound($this->name$queryName);
  1245.         }
  1246.         return $this->namedNativeQueries[$queryName];
  1247.     }
  1248.     /**
  1249.      * Gets all named native queries of the class.
  1250.      *
  1251.      * @psalm-return array<string, array<string, mixed>>
  1252.      */
  1253.     public function getNamedNativeQueries()
  1254.     {
  1255.         return $this->namedNativeQueries;
  1256.     }
  1257.     /**
  1258.      * Gets the result set mapping.
  1259.      *
  1260.      * @see ClassMetadataInfo::$sqlResultSetMappings
  1261.      *
  1262.      * @param string $name The result set mapping name.
  1263.      *
  1264.      * @return mixed[]
  1265.      * @psalm-return array{name: string, entities: array, columns: array}
  1266.      *
  1267.      * @throws MappingException
  1268.      */
  1269.     public function getSqlResultSetMapping($name)
  1270.     {
  1271.         if (! isset($this->sqlResultSetMappings[$name])) {
  1272.             throw MappingException::resultMappingNotFound($this->name$name);
  1273.         }
  1274.         return $this->sqlResultSetMappings[$name];
  1275.     }
  1276.     /**
  1277.      * Gets all sql result set mappings of the class.
  1278.      *
  1279.      * @return mixed[]
  1280.      * @psalm-return array<string, array{name: string, entities: array, columns: array}>
  1281.      */
  1282.     public function getSqlResultSetMappings()
  1283.     {
  1284.         return $this->sqlResultSetMappings;
  1285.     }
  1286.     /**
  1287.      * Checks whether given property has type
  1288.      *
  1289.      * @param string $name Property name
  1290.      */
  1291.     private function isTypedProperty(string $name): bool
  1292.     {
  1293.         return PHP_VERSION_ID >= 70400
  1294.                && isset($this->reflClass)
  1295.                && $this->reflClass->hasProperty($name)
  1296.                && $this->reflClass->getProperty($name)->hasType();
  1297.     }
  1298.     /**
  1299.      * Validates & completes the given field mapping based on typed property.
  1300.      *
  1301.      * @param  mixed[] $mapping The field mapping to validate & complete.
  1302.      *
  1303.      * @return mixed[] The updated mapping.
  1304.      */
  1305.     private function validateAndCompleteTypedFieldMapping(array $mapping): array
  1306.     {
  1307.         $type $this->reflClass->getProperty($mapping['fieldName'])->getType();
  1308.         if ($type) {
  1309.             if (! isset($mapping['nullable'])) {
  1310.                 $mapping['nullable'] = $type->allowsNull();
  1311.             }
  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.         if (isset($mapping['joinColumns'])) {
  1363.             foreach ($mapping['joinColumns'] as &$joinColumn) {
  1364.                 if ($type->allowsNull() === false) {
  1365.                     $joinColumn['nullable'] = false;
  1366.                 }
  1367.             }
  1368.         }
  1369.         return $mapping;
  1370.     }
  1371.     /**
  1372.      * Validates & completes the given field mapping.
  1373.      *
  1374.      * @psalm-param array<string, mixed> $mapping The field mapping to validate & complete.
  1375.      *
  1376.      * @return mixed[] The updated mapping.
  1377.      *
  1378.      * @throws MappingException
  1379.      */
  1380.     protected function validateAndCompleteFieldMapping(array $mapping): array
  1381.     {
  1382.         // Check mandatory fields
  1383.         if (! isset($mapping['fieldName']) || ! $mapping['fieldName']) {
  1384.             throw MappingException::missingFieldName($this->name);
  1385.         }
  1386.         if ($this->isTypedProperty($mapping['fieldName'])) {
  1387.             $mapping $this->validateAndCompleteTypedFieldMapping($mapping);
  1388.         }
  1389.         if (! isset($mapping['type'])) {
  1390.             // Default to string
  1391.             $mapping['type'] = 'string';
  1392.         }
  1393.         // Complete fieldName and columnName mapping
  1394.         if (! isset($mapping['columnName'])) {
  1395.             $mapping['columnName'] = $this->namingStrategy->propertyToColumnName($mapping['fieldName'], $this->name);
  1396.         }
  1397.         if ($mapping['columnName'][0] === '`') {
  1398.             $mapping['columnName'] = trim($mapping['columnName'], '`');
  1399.             $mapping['quoted']     = true;
  1400.         }
  1401.         $this->columnNames[$mapping['fieldName']] = $mapping['columnName'];
  1402.         if (isset($this->fieldNames[$mapping['columnName']]) || ($this->discriminatorColumn && $this->discriminatorColumn['name'] === $mapping['columnName'])) {
  1403.             throw MappingException::duplicateColumnName($this->name$mapping['columnName']);
  1404.         }
  1405.         $this->fieldNames[$mapping['columnName']] = $mapping['fieldName'];
  1406.         // Complete id mapping
  1407.         if (isset($mapping['id']) && $mapping['id'] === true) {
  1408.             if ($this->versionField === $mapping['fieldName']) {
  1409.                 throw MappingException::cannotVersionIdField($this->name$mapping['fieldName']);
  1410.             }
  1411.             if (! in_array($mapping['fieldName'], $this->identifier)) {
  1412.                 $this->identifier[] = $mapping['fieldName'];
  1413.             }
  1414.             // Check for composite key
  1415.             if (! $this->isIdentifierComposite && count($this->identifier) > 1) {
  1416.                 $this->isIdentifierComposite true;
  1417.             }
  1418.         }
  1419.         if (Type::hasType($mapping['type']) && Type::getType($mapping['type'])->canRequireSQLConversion()) {
  1420.             if (isset($mapping['id']) && $mapping['id'] === true) {
  1421.                  throw MappingException::sqlConversionNotAllowedForIdentifiers($this->name$mapping['fieldName'], $mapping['type']);
  1422.             }
  1423.             $mapping['requireSQLConversion'] = true;
  1424.         }
  1425.         return $mapping;
  1426.     }
  1427.     /**
  1428.      * Validates & completes the basic mapping information that is common to all
  1429.      * association mappings (one-to-one, many-ot-one, one-to-many, many-to-many).
  1430.      *
  1431.      * @psalm-param array<string, mixed> $mapping The mapping.
  1432.      *
  1433.      * @return mixed[] The updated mapping.
  1434.      * @psalm-return array{
  1435.      *                   mappedBy: mixed|null,
  1436.      *                   inversedBy: mixed|null,
  1437.      *                   isOwningSide: bool,
  1438.      *                   sourceEntity: class-string,
  1439.      *                   targetEntity: string,
  1440.      *                   fieldName: mixed,
  1441.      *                   fetch: mixed,
  1442.      *                   cascade: array<array-key,string>,
  1443.      *                   isCascadeRemove: bool,
  1444.      *                   isCascadePersist: bool,
  1445.      *                   isCascadeRefresh: bool,
  1446.      *                   isCascadeMerge: bool,
  1447.      *                   isCascadeDetach: bool,
  1448.      *                   type: int,
  1449.      *                   originalField: string,
  1450.      *                   originalClass: class-string,
  1451.      *                   ?orphanRemoval: bool
  1452.      *               }
  1453.      *
  1454.      * @throws MappingException If something is wrong with the mapping.
  1455.      */
  1456.     protected function _validateAndCompleteAssociationMapping(array $mapping)
  1457.     {
  1458.         if (! isset($mapping['mappedBy'])) {
  1459.             $mapping['mappedBy'] = null;
  1460.         }
  1461.         if (! isset($mapping['inversedBy'])) {
  1462.             $mapping['inversedBy'] = null;
  1463.         }
  1464.         $mapping['isOwningSide'] = true// assume owning side until we hit mappedBy
  1465.         if (empty($mapping['indexBy'])) {
  1466.             unset($mapping['indexBy']);
  1467.         }
  1468.         // If targetEntity is unqualified, assume it is in the same namespace as
  1469.         // the sourceEntity.
  1470.         $mapping['sourceEntity'] = $this->name;
  1471.         if ($this->isTypedProperty($mapping['fieldName'])) {
  1472.             $mapping $this->validateAndCompleteTypedAssociationMapping($mapping);
  1473.         }
  1474.         if (isset($mapping['targetEntity'])) {
  1475.             $mapping['targetEntity'] = $this->fullyQualifiedClassName($mapping['targetEntity']);
  1476.             $mapping['targetEntity'] = ltrim($mapping['targetEntity'], '\\');
  1477.         }
  1478.         if (($mapping['type'] & self::MANY_TO_ONE) > && isset($mapping['orphanRemoval']) && $mapping['orphanRemoval']) {
  1479.             throw MappingException::illegalOrphanRemoval($this->name$mapping['fieldName']);
  1480.         }
  1481.         // Complete id mapping
  1482.         if (isset($mapping['id']) && $mapping['id'] === true) {
  1483.             if (isset($mapping['orphanRemoval']) && $mapping['orphanRemoval']) {
  1484.                 throw MappingException::illegalOrphanRemovalOnIdentifierAssociation($this->name$mapping['fieldName']);
  1485.             }
  1486.             if (! in_array($mapping['fieldName'], $this->identifier)) {
  1487.                 if (isset($mapping['joinColumns']) && count($mapping['joinColumns']) >= 2) {
  1488.                     throw MappingException::cannotMapCompositePrimaryKeyEntitiesAsForeignId(
  1489.                         $mapping['targetEntity'],
  1490.                         $this->name,
  1491.                         $mapping['fieldName']
  1492.                     );
  1493.                 }
  1494.                 $this->identifier[]              = $mapping['fieldName'];
  1495.                 $this->containsForeignIdentifier true;
  1496.             }
  1497.             // Check for composite key
  1498.             if (! $this->isIdentifierComposite && count($this->identifier) > 1) {
  1499.                 $this->isIdentifierComposite true;
  1500.             }
  1501.             if ($this->cache && ! isset($mapping['cache'])) {
  1502.                 throw CacheException::nonCacheableEntityAssociation($this->name$mapping['fieldName']);
  1503.             }
  1504.         }
  1505.         // Mandatory attributes for both sides
  1506.         // Mandatory: fieldName, targetEntity
  1507.         if (! isset($mapping['fieldName']) || ! $mapping['fieldName']) {
  1508.             throw MappingException::missingFieldName($this->name);
  1509.         }
  1510.         if (! isset($mapping['targetEntity'])) {
  1511.             throw MappingException::missingTargetEntity($mapping['fieldName']);
  1512.         }
  1513.         // Mandatory and optional attributes for either side
  1514.         if (! $mapping['mappedBy']) {
  1515.             if (isset($mapping['joinTable']) && $mapping['joinTable']) {
  1516.                 if (isset($mapping['joinTable']['name']) && $mapping['joinTable']['name'][0] === '`') {
  1517.                     $mapping['joinTable']['name']   = trim($mapping['joinTable']['name'], '`');
  1518.                     $mapping['joinTable']['quoted'] = true;
  1519.                 }
  1520.             }
  1521.         } else {
  1522.             $mapping['isOwningSide'] = false;
  1523.         }
  1524.         if (isset($mapping['id']) && $mapping['id'] === true && $mapping['type'] & self::TO_MANY) {
  1525.             throw MappingException::illegalToManyIdentifierAssociation($this->name$mapping['fieldName']);
  1526.         }
  1527.         // Fetch mode. Default fetch mode to LAZY, if not set.
  1528.         if (! isset($mapping['fetch'])) {
  1529.             $mapping['fetch'] = self::FETCH_LAZY;
  1530.         }
  1531.         // Cascades
  1532.         $cascades = isset($mapping['cascade']) ? array_map('strtolower'$mapping['cascade']) : [];
  1533.         $allCascades = ['remove''persist''refresh''merge''detach'];
  1534.         if (in_array('all'$cascades)) {
  1535.             $cascades $allCascades;
  1536.         } elseif (count($cascades) !== count(array_intersect($cascades$allCascades))) {
  1537.             throw MappingException::invalidCascadeOption(
  1538.                 array_diff($cascades$allCascades),
  1539.                 $this->name,
  1540.                 $mapping['fieldName']
  1541.             );
  1542.         }
  1543.         $mapping['cascade']          = $cascades;
  1544.         $mapping['isCascadeRemove']  = in_array('remove'$cascades);
  1545.         $mapping['isCascadePersist'] = in_array('persist'$cascades);
  1546.         $mapping['isCascadeRefresh'] = in_array('refresh'$cascades);
  1547.         $mapping['isCascadeMerge']   = in_array('merge'$cascades);
  1548.         $mapping['isCascadeDetach']  = in_array('detach'$cascades);
  1549.         return $mapping;
  1550.     }
  1551.     /**
  1552.      * Validates & completes a one-to-one association mapping.
  1553.      *
  1554.      * @psalm-param array<string, mixed> $mapping The mapping to validate & complete.
  1555.      * @psalm-param array<string, mixed> $mapping The mapping to validate & complete.
  1556.      *
  1557.      * @return mixed[] The validated & completed mapping.
  1558.      * @psalm-return array{isOwningSide: mixed, orphanRemoval: bool, isCascadeRemove: bool}
  1559.      * @psalm-return array{
  1560.      *      mappedBy: mixed|null,
  1561.      *      inversedBy: mixed|null,
  1562.      *      isOwningSide: bool,
  1563.      *      sourceEntity: class-string,
  1564.      *      targetEntity: string,
  1565.      *      fieldName: mixed,
  1566.      *      fetch: mixed,
  1567.      *      cascade: array<string>,
  1568.      *      isCascadeRemove: bool,
  1569.      *      isCascadePersist: bool,
  1570.      *      isCascadeRefresh: bool,
  1571.      *      isCascadeMerge: bool,
  1572.      *      isCascadeDetach: bool,
  1573.      *      type: int,
  1574.      *      originalField: string,
  1575.      *      originalClass: class-string,
  1576.      *      joinColumns?: array{0: array{name: string, referencedColumnName: string}}|mixed,
  1577.      *      id?: mixed,
  1578.      *      sourceToTargetKeyColumns?: array,
  1579.      *      joinColumnFieldNames?: array,
  1580.      *      targetToSourceKeyColumns?: array<array-key>,
  1581.      *      orphanRemoval: bool
  1582.      * }
  1583.      *
  1584.      * @throws RuntimeException
  1585.      * @throws MappingException
  1586.      */
  1587.     protected function _validateAndCompleteOneToOneMapping(array $mapping)
  1588.     {
  1589.         $mapping $this->_validateAndCompleteAssociationMapping($mapping);
  1590.         if (isset($mapping['joinColumns']) && $mapping['joinColumns']) {
  1591.             $mapping['isOwningSide'] = true;
  1592.         }
  1593.         if ($mapping['isOwningSide']) {
  1594.             if (empty($mapping['joinColumns'])) {
  1595.                 // Apply default join column
  1596.                 $mapping['joinColumns'] = [
  1597.                     [
  1598.                         'name' => $this->namingStrategy->joinColumnName($mapping['fieldName'], $this->name),
  1599.                         'referencedColumnName' => $this->namingStrategy->referenceColumnName(),
  1600.                     ],
  1601.                 ];
  1602.             }
  1603.             $uniqueConstraintColumns = [];
  1604.             foreach ($mapping['joinColumns'] as &$joinColumn) {
  1605.                 if ($mapping['type'] === self::ONE_TO_ONE && ! $this->isInheritanceTypeSingleTable()) {
  1606.                     if (count($mapping['joinColumns']) === 1) {
  1607.                         if (empty($mapping['id'])) {
  1608.                             $joinColumn['unique'] = true;
  1609.                         }
  1610.                     } else {
  1611.                         $uniqueConstraintColumns[] = $joinColumn['name'];
  1612.                     }
  1613.                 }
  1614.                 if (empty($joinColumn['name'])) {
  1615.                     $joinColumn['name'] = $this->namingStrategy->joinColumnName($mapping['fieldName'], $this->name);
  1616.                 }
  1617.                 if (empty($joinColumn['referencedColumnName'])) {
  1618.                     $joinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName();
  1619.                 }
  1620.                 if ($joinColumn['name'][0] === '`') {
  1621.                     $joinColumn['name']   = trim($joinColumn['name'], '`');
  1622.                     $joinColumn['quoted'] = true;
  1623.                 }
  1624.                 if ($joinColumn['referencedColumnName'][0] === '`') {
  1625.                     $joinColumn['referencedColumnName'] = trim($joinColumn['referencedColumnName'], '`');
  1626.                     $joinColumn['quoted']               = true;
  1627.                 }
  1628.                 $mapping['sourceToTargetKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName'];
  1629.                 $mapping['joinColumnFieldNames'][$joinColumn['name']]     = $joinColumn['fieldName'] ?? $joinColumn['name'];
  1630.             }
  1631.             if ($uniqueConstraintColumns) {
  1632.                 if (! $this->table) {
  1633.                     throw new RuntimeException('ClassMetadataInfo::setTable() has to be called before defining a one to one relationship.');
  1634.                 }
  1635.                 $this->table['uniqueConstraints'][$mapping['fieldName'] . '_uniq'] = ['columns' => $uniqueConstraintColumns];
  1636.             }
  1637.             $mapping['targetToSourceKeyColumns'] = array_flip($mapping['sourceToTargetKeyColumns']);
  1638.         }
  1639.         $mapping['orphanRemoval']   = isset($mapping['orphanRemoval']) && $mapping['orphanRemoval'];
  1640.         $mapping['isCascadeRemove'] = $mapping['orphanRemoval'] || $mapping['isCascadeRemove'];
  1641.         if ($mapping['orphanRemoval']) {
  1642.             unset($mapping['unique']);
  1643.         }
  1644.         if (isset($mapping['id']) && $mapping['id'] === true && ! $mapping['isOwningSide']) {
  1645.             throw MappingException::illegalInverseIdentifierAssociation($this->name$mapping['fieldName']);
  1646.         }
  1647.         return $mapping;
  1648.     }
  1649.     /**
  1650.      * Validates & completes a one-to-many association mapping.
  1651.      *
  1652.      * @psalm-param array<string, mixed> $mapping The mapping to validate and complete.
  1653.      *
  1654.      * @return mixed[] The validated and completed mapping.
  1655.      * @psalm-return array{
  1656.      *                   mappedBy: mixed,
  1657.      *                   inversedBy: mixed,
  1658.      *                   isOwningSide: bool,
  1659.      *                   sourceEntity: string,
  1660.      *                   targetEntity: string,
  1661.      *                   fieldName: mixed,
  1662.      *                   fetch: int|mixed,
  1663.      *                   cascade: array<array-key,string>,
  1664.      *                   isCascadeRemove: bool,
  1665.      *                   isCascadePersist: bool,
  1666.      *                   isCascadeRefresh: bool,
  1667.      *                   isCascadeMerge: bool,
  1668.      *                   isCascadeDetach: bool,
  1669.      *                   orphanRemoval: bool
  1670.      *               }
  1671.      *
  1672.      * @throws MappingException
  1673.      * @throws InvalidArgumentException
  1674.      */
  1675.     protected function _validateAndCompleteOneToManyMapping(array $mapping)
  1676.     {
  1677.         $mapping $this->_validateAndCompleteAssociationMapping($mapping);
  1678.         // OneToMany-side MUST be inverse (must have mappedBy)
  1679.         if (! isset($mapping['mappedBy'])) {
  1680.             throw MappingException::oneToManyRequiresMappedBy($this->name$mapping['fieldName']);
  1681.         }
  1682.         $mapping['orphanRemoval']   = isset($mapping['orphanRemoval']) && $mapping['orphanRemoval'];
  1683.         $mapping['isCascadeRemove'] = $mapping['orphanRemoval'] || $mapping['isCascadeRemove'];
  1684.         $this->assertMappingOrderBy($mapping);
  1685.         return $mapping;
  1686.     }
  1687.     /**
  1688.      * Validates & completes a many-to-many association mapping.
  1689.      *
  1690.      * @psalm-param array<string, mixed> $mapping The mapping to validate & complete.
  1691.      * @psalm-param array<string, mixed> $mapping The mapping to validate & complete.
  1692.      *
  1693.      * @return mixed[] The validated & completed mapping.
  1694.      * @psalm-return array{
  1695.      *      mappedBy: mixed,
  1696.      *      inversedBy: mixed,
  1697.      *      isOwningSide: bool,
  1698.      *      sourceEntity: class-string,
  1699.      *      targetEntity: string,
  1700.      *      fieldName: mixed,
  1701.      *      fetch: mixed,
  1702.      *      cascade: array<string>,
  1703.      *      isCascadeRemove: bool,
  1704.      *      isCascadePersist: bool,
  1705.      *      isCascadeRefresh: bool,
  1706.      *      isCascadeMerge: bool,
  1707.      *      isCascadeDetach: bool,
  1708.      *      type: int,
  1709.      *      originalField: string,
  1710.      *      originalClass: class-string,
  1711.      *      joinTable?: array{inverseJoinColumns: mixed}|mixed,
  1712.      *      joinTableColumns?: list<mixed>,
  1713.      *      isOnDeleteCascade?: true,
  1714.      *      relationToSourceKeyColumns?: array,
  1715.      *      relationToTargetKeyColumns?: array,
  1716.      *      orphanRemoval: bool
  1717.      * }
  1718.      *
  1719.      * @throws InvalidArgumentException
  1720.      */
  1721.     protected function _validateAndCompleteManyToManyMapping(array $mapping)
  1722.     {
  1723.         $mapping $this->_validateAndCompleteAssociationMapping($mapping);
  1724.         if ($mapping['isOwningSide']) {
  1725.             // owning side MUST have a join table
  1726.             if (! isset($mapping['joinTable']['name'])) {
  1727.                 $mapping['joinTable']['name'] = $this->namingStrategy->joinTableName($mapping['sourceEntity'], $mapping['targetEntity'], $mapping['fieldName']);
  1728.             }
  1729.             $selfReferencingEntityWithoutJoinColumns $mapping['sourceEntity'] === $mapping['targetEntity']
  1730.                 && (! (isset($mapping['joinTable']['joinColumns']) || isset($mapping['joinTable']['inverseJoinColumns'])));
  1731.             if (! isset($mapping['joinTable']['joinColumns'])) {
  1732.                 $mapping['joinTable']['joinColumns'] = [
  1733.                     [
  1734.                         'name' => $this->namingStrategy->joinKeyColumnName($mapping['sourceEntity'], $selfReferencingEntityWithoutJoinColumns 'source' null),
  1735.                         'referencedColumnName' => $this->namingStrategy->referenceColumnName(),
  1736.                         'onDelete' => 'CASCADE',
  1737.                     ],
  1738.                 ];
  1739.             }
  1740.             if (! isset($mapping['joinTable']['inverseJoinColumns'])) {
  1741.                 $mapping['joinTable']['inverseJoinColumns'] = [
  1742.                     [
  1743.                         'name' => $this->namingStrategy->joinKeyColumnName($mapping['targetEntity'], $selfReferencingEntityWithoutJoinColumns 'target' null),
  1744.                         'referencedColumnName' => $this->namingStrategy->referenceColumnName(),
  1745.                         'onDelete' => 'CASCADE',
  1746.                     ],
  1747.                 ];
  1748.             }
  1749.             $mapping['joinTableColumns'] = [];
  1750.             foreach ($mapping['joinTable']['joinColumns'] as &$joinColumn) {
  1751.                 if (empty($joinColumn['name'])) {
  1752.                     $joinColumn['name'] = $this->namingStrategy->joinKeyColumnName($mapping['sourceEntity'], $joinColumn['referencedColumnName']);
  1753.                 }
  1754.                 if (empty($joinColumn['referencedColumnName'])) {
  1755.                     $joinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName();
  1756.                 }
  1757.                 if ($joinColumn['name'][0] === '`') {
  1758.                     $joinColumn['name']   = trim($joinColumn['name'], '`');
  1759.                     $joinColumn['quoted'] = true;
  1760.                 }
  1761.                 if ($joinColumn['referencedColumnName'][0] === '`') {
  1762.                     $joinColumn['referencedColumnName'] = trim($joinColumn['referencedColumnName'], '`');
  1763.                     $joinColumn['quoted']               = true;
  1764.                 }
  1765.                 if (isset($joinColumn['onDelete']) && strtolower($joinColumn['onDelete']) === 'cascade') {
  1766.                     $mapping['isOnDeleteCascade'] = true;
  1767.                 }
  1768.                 $mapping['relationToSourceKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName'];
  1769.                 $mapping['joinTableColumns'][]                              = $joinColumn['name'];
  1770.             }
  1771.             foreach ($mapping['joinTable']['inverseJoinColumns'] as &$inverseJoinColumn) {
  1772.                 if (empty($inverseJoinColumn['name'])) {
  1773.                     $inverseJoinColumn['name'] = $this->namingStrategy->joinKeyColumnName($mapping['targetEntity'], $inverseJoinColumn['referencedColumnName']);
  1774.                 }
  1775.                 if (empty($inverseJoinColumn['referencedColumnName'])) {
  1776.                     $inverseJoinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName();
  1777.                 }
  1778.                 if ($inverseJoinColumn['name'][0] === '`') {
  1779.                     $inverseJoinColumn['name']   = trim($inverseJoinColumn['name'], '`');
  1780.                     $inverseJoinColumn['quoted'] = true;
  1781.                 }
  1782.                 if ($inverseJoinColumn['referencedColumnName'][0] === '`') {
  1783.                     $inverseJoinColumn['referencedColumnName'] = trim($inverseJoinColumn['referencedColumnName'], '`');
  1784.                     $inverseJoinColumn['quoted']               = true;
  1785.                 }
  1786.                 if (isset($inverseJoinColumn['onDelete']) && strtolower($inverseJoinColumn['onDelete']) === 'cascade') {
  1787.                     $mapping['isOnDeleteCascade'] = true;
  1788.                 }
  1789.                 $mapping['relationToTargetKeyColumns'][$inverseJoinColumn['name']] = $inverseJoinColumn['referencedColumnName'];
  1790.                 $mapping['joinTableColumns'][]                                     = $inverseJoinColumn['name'];
  1791.             }
  1792.         }
  1793.         $mapping['orphanRemoval'] = isset($mapping['orphanRemoval']) && $mapping['orphanRemoval'];
  1794.         $this->assertMappingOrderBy($mapping);
  1795.         return $mapping;
  1796.     }
  1797.     /**
  1798.      * {@inheritDoc}
  1799.      */
  1800.     public function getIdentifierFieldNames()
  1801.     {
  1802.         return $this->identifier;
  1803.     }
  1804.     /**
  1805.      * Gets the name of the single id field. Note that this only works on
  1806.      * entity classes that have a single-field pk.
  1807.      *
  1808.      * @return string
  1809.      *
  1810.      * @throws MappingException If the class doesn't have an identifier or it has a composite primary key.
  1811.      */
  1812.     public function getSingleIdentifierFieldName()
  1813.     {
  1814.         if ($this->isIdentifierComposite) {
  1815.             throw MappingException::singleIdNotAllowedOnCompositePrimaryKey($this->name);
  1816.         }
  1817.         if (! isset($this->identifier[0])) {
  1818.             throw MappingException::noIdDefined($this->name);
  1819.         }
  1820.         return $this->identifier[0];
  1821.     }
  1822.     /**
  1823.      * Gets the column name of the single id column. Note that this only works on
  1824.      * entity classes that have a single-field pk.
  1825.      *
  1826.      * @return string
  1827.      *
  1828.      * @throws MappingException If the class doesn't have an identifier or it has a composite primary key.
  1829.      */
  1830.     public function getSingleIdentifierColumnName()
  1831.     {
  1832.         return $this->getColumnName($this->getSingleIdentifierFieldName());
  1833.     }
  1834.     /**
  1835.      * INTERNAL:
  1836.      * Sets the mapped identifier/primary key fields of this class.
  1837.      * Mainly used by the ClassMetadataFactory to assign inherited identifiers.
  1838.      *
  1839.      * @psalm-param list<mixed> $identifier
  1840.      *
  1841.      * @return void
  1842.      */
  1843.     public function setIdentifier(array $identifier)
  1844.     {
  1845.         $this->identifier            $identifier;
  1846.         $this->isIdentifierComposite = (count($this->identifier) > 1);
  1847.     }
  1848.     /**
  1849.      * {@inheritDoc}
  1850.      */
  1851.     public function getIdentifier()
  1852.     {
  1853.         return $this->identifier;
  1854.     }
  1855.     /**
  1856.      * {@inheritDoc}
  1857.      */
  1858.     public function hasField($fieldName)
  1859.     {
  1860.         return isset($this->fieldMappings[$fieldName]) || isset($this->embeddedClasses[$fieldName]);
  1861.     }
  1862.     /**
  1863.      * Gets an array containing all the column names.
  1864.      *
  1865.      * @psalm-param list<string>|null $fieldNames
  1866.      *
  1867.      * @return mixed[]
  1868.      * @psalm-return list<string>
  1869.      */
  1870.     public function getColumnNames(?array $fieldNames null)
  1871.     {
  1872.         if ($fieldNames === null) {
  1873.             return array_keys($this->fieldNames);
  1874.         }
  1875.         return array_values(array_map([$this'getColumnName'], $fieldNames));
  1876.     }
  1877.     /**
  1878.      * Returns an array with all the identifier column names.
  1879.      *
  1880.      * @psalm-return list<string>
  1881.      */
  1882.     public function getIdentifierColumnNames()
  1883.     {
  1884.         $columnNames = [];
  1885.         foreach ($this->identifier as $idProperty) {
  1886.             if (isset($this->fieldMappings[$idProperty])) {
  1887.                 $columnNames[] = $this->fieldMappings[$idProperty]['columnName'];
  1888.                 continue;
  1889.             }
  1890.             // Association defined as Id field
  1891.             $joinColumns      $this->associationMappings[$idProperty]['joinColumns'];
  1892.             $assocColumnNames array_map(static function ($joinColumn) {
  1893.                 return $joinColumn['name'];
  1894.             }, $joinColumns);
  1895.             $columnNames array_merge($columnNames$assocColumnNames);
  1896.         }
  1897.         return $columnNames;
  1898.     }
  1899.     /**
  1900.      * Sets the type of Id generator to use for the mapped class.
  1901.      *
  1902.      * @param int $generatorType
  1903.      *
  1904.      * @return void
  1905.      */
  1906.     public function setIdGeneratorType($generatorType)
  1907.     {
  1908.         $this->generatorType $generatorType;
  1909.     }
  1910.     /**
  1911.      * Checks whether the mapped class uses an Id generator.
  1912.      *
  1913.      * @return bool TRUE if the mapped class uses an Id generator, FALSE otherwise.
  1914.      */
  1915.     public function usesIdGenerator()
  1916.     {
  1917.         return $this->generatorType !== self::GENERATOR_TYPE_NONE;
  1918.     }
  1919.     /**
  1920.      * @return bool
  1921.      */
  1922.     public function isInheritanceTypeNone()
  1923.     {
  1924.         return $this->inheritanceType === self::INHERITANCE_TYPE_NONE;
  1925.     }
  1926.     /**
  1927.      * Checks whether the mapped class uses the JOINED inheritance mapping strategy.
  1928.      *
  1929.      * @return bool TRUE if the class participates in a JOINED inheritance mapping,
  1930.      * FALSE otherwise.
  1931.      */
  1932.     public function isInheritanceTypeJoined()
  1933.     {
  1934.         return $this->inheritanceType === self::INHERITANCE_TYPE_JOINED;
  1935.     }
  1936.     /**
  1937.      * Checks whether the mapped class uses the SINGLE_TABLE inheritance mapping strategy.
  1938.      *
  1939.      * @return bool TRUE if the class participates in a SINGLE_TABLE inheritance mapping,
  1940.      * FALSE otherwise.
  1941.      */
  1942.     public function isInheritanceTypeSingleTable()
  1943.     {
  1944.         return $this->inheritanceType === self::INHERITANCE_TYPE_SINGLE_TABLE;
  1945.     }
  1946.     /**
  1947.      * Checks whether the mapped class uses the TABLE_PER_CLASS inheritance mapping strategy.
  1948.      *
  1949.      * @return bool TRUE if the class participates in a TABLE_PER_CLASS inheritance mapping,
  1950.      * FALSE otherwise.
  1951.      */
  1952.     public function isInheritanceTypeTablePerClass()
  1953.     {
  1954.         return $this->inheritanceType === self::INHERITANCE_TYPE_TABLE_PER_CLASS;
  1955.     }
  1956.     /**
  1957.      * Checks whether the class uses an identity column for the Id generation.
  1958.      *
  1959.      * @return bool TRUE if the class uses the IDENTITY generator, FALSE otherwise.
  1960.      */
  1961.     public function isIdGeneratorIdentity()
  1962.     {
  1963.         return $this->generatorType === self::GENERATOR_TYPE_IDENTITY;
  1964.     }
  1965.     /**
  1966.      * Checks whether the class uses a sequence for id generation.
  1967.      *
  1968.      * @return bool TRUE if the class uses the SEQUENCE generator, FALSE otherwise.
  1969.      */
  1970.     public function isIdGeneratorSequence()
  1971.     {
  1972.         return $this->generatorType === self::GENERATOR_TYPE_SEQUENCE;
  1973.     }
  1974.     /**
  1975.      * Checks whether the class uses a table for id generation.
  1976.      *
  1977.      * @return bool TRUE if the class uses the TABLE generator, FALSE otherwise.
  1978.      */
  1979.     public function isIdGeneratorTable()
  1980.     {
  1981.         return $this->generatorType === self::GENERATOR_TYPE_TABLE;
  1982.     }
  1983.     /**
  1984.      * Checks whether the class has a natural identifier/pk (which means it does
  1985.      * not use any Id generator.
  1986.      *
  1987.      * @return bool
  1988.      */
  1989.     public function isIdentifierNatural()
  1990.     {
  1991.         return $this->generatorType === self::GENERATOR_TYPE_NONE;
  1992.     }
  1993.     /**
  1994.      * Checks whether the class use a UUID for id generation.
  1995.      *
  1996.      * @return bool
  1997.      */
  1998.     public function isIdentifierUuid()
  1999.     {
  2000.         return $this->generatorType === self::GENERATOR_TYPE_UUID;
  2001.     }
  2002.     /**
  2003.      * Gets the type of a field.
  2004.      *
  2005.      * @param string $fieldName
  2006.      *
  2007.      * @return string|null
  2008.      *
  2009.      * @todo 3.0 Remove this. PersisterHelper should fix it somehow
  2010.      */
  2011.     public function getTypeOfField($fieldName)
  2012.     {
  2013.         return isset($this->fieldMappings[$fieldName])
  2014.             ? $this->fieldMappings[$fieldName]['type']
  2015.             : null;
  2016.     }
  2017.     /**
  2018.      * Gets the type of a column.
  2019.      *
  2020.      * @deprecated 3.0 remove this. this method is bogus and unreliable, since it cannot resolve the type of a column
  2021.      *             that is derived by a referenced field on a different entity.
  2022.      *
  2023.      * @param string $columnName
  2024.      *
  2025.      * @return string|null
  2026.      */
  2027.     public function getTypeOfColumn($columnName)
  2028.     {
  2029.         return $this->getTypeOfField($this->getFieldName($columnName));
  2030.     }
  2031.     /**
  2032.      * Gets the name of the primary table.
  2033.      *
  2034.      * @return string
  2035.      */
  2036.     public function getTableName()
  2037.     {
  2038.         return $this->table['name'];
  2039.     }
  2040.     /**
  2041.      * Gets primary table's schema name.
  2042.      *
  2043.      * @return string|null
  2044.      */
  2045.     public function getSchemaName()
  2046.     {
  2047.         return $this->table['schema'] ?? null;
  2048.     }
  2049.     /**
  2050.      * Gets the table name to use for temporary identifier tables of this class.
  2051.      *
  2052.      * @return string
  2053.      */
  2054.     public function getTemporaryIdTableName()
  2055.     {
  2056.         // replace dots with underscores because PostgreSQL creates temporary tables in a special schema
  2057.         return str_replace('.''_'$this->getTableName() . '_id_tmp');
  2058.     }
  2059.     /**
  2060.      * Sets the mapped subclasses of this class.
  2061.      *
  2062.      * @psalm-param list<string> $subclasses The names of all mapped subclasses.
  2063.      *
  2064.      * @return void
  2065.      */
  2066.     public function setSubclasses(array $subclasses)
  2067.     {
  2068.         foreach ($subclasses as $subclass) {
  2069.             $this->subClasses[] = $this->fullyQualifiedClassName($subclass);
  2070.         }
  2071.     }
  2072.     /**
  2073.      * Sets the parent class names.
  2074.      * Assumes that the class names in the passed array are in the order:
  2075.      * directParent -> directParentParent -> directParentParentParent ... -> root.
  2076.      *
  2077.      * @psalm-param list<class-string> $classNames
  2078.      *
  2079.      * @return void
  2080.      */
  2081.     public function setParentClasses(array $classNames)
  2082.     {
  2083.         $this->parentClasses $classNames;
  2084.         if (count($classNames) > 0) {
  2085.             $this->rootEntityName array_pop($classNames);
  2086.         }
  2087.     }
  2088.     /**
  2089.      * Sets the inheritance type used by the class and its subclasses.
  2090.      *
  2091.      * @param int $type
  2092.      *
  2093.      * @return void
  2094.      *
  2095.      * @throws MappingException
  2096.      */
  2097.     public function setInheritanceType($type)
  2098.     {
  2099.         if (! $this->isInheritanceType($type)) {
  2100.             throw MappingException::invalidInheritanceType($this->name$type);
  2101.         }
  2102.         $this->inheritanceType $type;
  2103.     }
  2104.     /**
  2105.      * Sets the association to override association mapping of property for an entity relationship.
  2106.      *
  2107.      * @param string $fieldName
  2108.      * @psalm-param array<string, mixed> $overrideMapping
  2109.      *
  2110.      * @return void
  2111.      *
  2112.      * @throws MappingException
  2113.      */
  2114.     public function setAssociationOverride($fieldName, array $overrideMapping)
  2115.     {
  2116.         if (! isset($this->associationMappings[$fieldName])) {
  2117.             throw MappingException::invalidOverrideFieldName($this->name$fieldName);
  2118.         }
  2119.         $mapping $this->associationMappings[$fieldName];
  2120.         //if (isset($mapping['inherited']) && (count($overrideMapping) !== 1 || ! isset($overrideMapping['fetch']))) {
  2121.             // TODO: Deprecate overriding the fetch mode via association override for 3.0,
  2122.             // users should do this with a listener and a custom attribute/annotation
  2123.             // TODO: Enable this exception in 2.8
  2124.             //throw MappingException::illegalOverrideOfInheritedProperty($this->name, $fieldName);
  2125.         //}
  2126.         if (isset($overrideMapping['joinColumns'])) {
  2127.             $mapping['joinColumns'] = $overrideMapping['joinColumns'];
  2128.         }
  2129.         if (isset($overrideMapping['inversedBy'])) {
  2130.             $mapping['inversedBy'] = $overrideMapping['inversedBy'];
  2131.         }
  2132.         if (isset($overrideMapping['joinTable'])) {
  2133.             $mapping['joinTable'] = $overrideMapping['joinTable'];
  2134.         }
  2135.         if (isset($overrideMapping['fetch'])) {
  2136.             $mapping['fetch'] = $overrideMapping['fetch'];
  2137.         }
  2138.         $mapping['joinColumnFieldNames']       = null;
  2139.         $mapping['joinTableColumns']           = null;
  2140.         $mapping['sourceToTargetKeyColumns']   = null;
  2141.         $mapping['relationToSourceKeyColumns'] = null;
  2142.         $mapping['relationToTargetKeyColumns'] = null;
  2143.         switch ($mapping['type']) {
  2144.             case self::ONE_TO_ONE:
  2145.                 $mapping $this->_validateAndCompleteOneToOneMapping($mapping);
  2146.                 break;
  2147.             case self::ONE_TO_MANY:
  2148.                 $mapping $this->_validateAndCompleteOneToManyMapping($mapping);
  2149.                 break;
  2150.             case self::MANY_TO_ONE:
  2151.                 $mapping $this->_validateAndCompleteOneToOneMapping($mapping);
  2152.                 break;
  2153.             case self::MANY_TO_MANY:
  2154.                 $mapping $this->_validateAndCompleteManyToManyMapping($mapping);
  2155.                 break;
  2156.         }
  2157.         $this->associationMappings[$fieldName] = $mapping;
  2158.     }
  2159.     /**
  2160.      * Sets the override for a mapped field.
  2161.      *
  2162.      * @param string $fieldName
  2163.      * @psalm-param array<string, mixed> $overrideMapping
  2164.      *
  2165.      * @return void
  2166.      *
  2167.      * @throws MappingException
  2168.      */
  2169.     public function setAttributeOverride($fieldName, array $overrideMapping)
  2170.     {
  2171.         if (! isset($this->fieldMappings[$fieldName])) {
  2172.             throw MappingException::invalidOverrideFieldName($this->name$fieldName);
  2173.         }
  2174.         $mapping $this->fieldMappings[$fieldName];
  2175.         //if (isset($mapping['inherited'])) {
  2176.             // TODO: Enable this exception in 2.8
  2177.             //throw MappingException::illegalOverrideOfInheritedProperty($this->name, $fieldName);
  2178.         //}
  2179.         if (isset($mapping['id'])) {
  2180.             $overrideMapping['id'] = $mapping['id'];
  2181.         }
  2182.         if (! isset($overrideMapping['type'])) {
  2183.             $overrideMapping['type'] = $mapping['type'];
  2184.         }
  2185.         if (! isset($overrideMapping['fieldName'])) {
  2186.             $overrideMapping['fieldName'] = $mapping['fieldName'];
  2187.         }
  2188.         if ($overrideMapping['type'] !== $mapping['type']) {
  2189.             throw MappingException::invalidOverrideFieldType($this->name$fieldName);
  2190.         }
  2191.         unset($this->fieldMappings[$fieldName]);
  2192.         unset($this->fieldNames[$mapping['columnName']]);
  2193.         unset($this->columnNames[$mapping['fieldName']]);
  2194.         $overrideMapping $this->validateAndCompleteFieldMapping($overrideMapping);
  2195.         $this->fieldMappings[$fieldName] = $overrideMapping;
  2196.     }
  2197.     /**
  2198.      * Checks whether a mapped field is inherited from an entity superclass.
  2199.      *
  2200.      * @param string $fieldName
  2201.      *
  2202.      * @return bool TRUE if the field is inherited, FALSE otherwise.
  2203.      */
  2204.     public function isInheritedField($fieldName)
  2205.     {
  2206.         return isset($this->fieldMappings[$fieldName]['inherited']);
  2207.     }
  2208.     /**
  2209.      * Checks if this entity is the root in any entity-inheritance-hierarchy.
  2210.      *
  2211.      * @return bool
  2212.      */
  2213.     public function isRootEntity()
  2214.     {
  2215.         return $this->name === $this->rootEntityName;
  2216.     }
  2217.     /**
  2218.      * Checks whether a mapped association field is inherited from a superclass.
  2219.      *
  2220.      * @param string $fieldName
  2221.      *
  2222.      * @return bool TRUE if the field is inherited, FALSE otherwise.
  2223.      */
  2224.     public function isInheritedAssociation($fieldName)
  2225.     {
  2226.         return isset($this->associationMappings[$fieldName]['inherited']);
  2227.     }
  2228.     /**
  2229.      * @param string $fieldName
  2230.      *
  2231.      * @return bool
  2232.      */
  2233.     public function isInheritedEmbeddedClass($fieldName)
  2234.     {
  2235.         return isset($this->embeddedClasses[$fieldName]['inherited']);
  2236.     }
  2237.     /**
  2238.      * Sets the name of the primary table the class is mapped to.
  2239.      *
  2240.      * @deprecated Use {@link setPrimaryTable}.
  2241.      *
  2242.      * @param string $tableName The table name.
  2243.      *
  2244.      * @return void
  2245.      */
  2246.     public function setTableName($tableName)
  2247.     {
  2248.         $this->table['name'] = $tableName;
  2249.     }
  2250.     /**
  2251.      * Sets the primary table definition. The provided array supports the
  2252.      * following structure:
  2253.      *
  2254.      * name => <tableName> (optional, defaults to class name)
  2255.      * indexes => array of indexes (optional)
  2256.      * uniqueConstraints => array of constraints (optional)
  2257.      *
  2258.      * If a key is omitted, the current value is kept.
  2259.      *
  2260.      * @psalm-param array<string, mixed> $table The table description.
  2261.      *
  2262.      * @return void
  2263.      */
  2264.     public function setPrimaryTable(array $table)
  2265.     {
  2266.         if (isset($table['name'])) {
  2267.             // Split schema and table name from a table name like "myschema.mytable"
  2268.             if (strpos($table['name'], '.') !== false) {
  2269.                 [$this->table['schema'], $table['name']] = explode('.'$table['name'], 2);
  2270.             }
  2271.             if ($table['name'][0] === '`') {
  2272.                 $table['name']         = trim($table['name'], '`');
  2273.                 $this->table['quoted'] = true;
  2274.             }
  2275.             $this->table['name'] = $table['name'];
  2276.         }
  2277.         if (isset($table['quoted'])) {
  2278.             $this->table['quoted'] = $table['quoted'];
  2279.         }
  2280.         if (isset($table['schema'])) {
  2281.             $this->table['schema'] = $table['schema'];
  2282.         }
  2283.         if (isset($table['indexes'])) {
  2284.             $this->table['indexes'] = $table['indexes'];
  2285.         }
  2286.         if (isset($table['uniqueConstraints'])) {
  2287.             $this->table['uniqueConstraints'] = $table['uniqueConstraints'];
  2288.         }
  2289.         if (isset($table['options'])) {
  2290.             $this->table['options'] = $table['options'];
  2291.         }
  2292.     }
  2293.     /**
  2294.      * Checks whether the given type identifies an inheritance type.
  2295.      *
  2296.      * @return bool TRUE if the given type identifies an inheritance type, FALSE otherwise.
  2297.      */
  2298.     private function isInheritanceType(int $type): bool
  2299.     {
  2300.         return $type === self::INHERITANCE_TYPE_NONE ||
  2301.                 $type === self::INHERITANCE_TYPE_SINGLE_TABLE ||
  2302.                 $type === self::INHERITANCE_TYPE_JOINED ||
  2303.                 $type === self::INHERITANCE_TYPE_TABLE_PER_CLASS;
  2304.     }
  2305.     /**
  2306.      * Adds a mapped field to the class.
  2307.      *
  2308.      * @psalm-param array<string, mixed> $mapping The field mapping.
  2309.      *
  2310.      * @return void
  2311.      *
  2312.      * @throws MappingException
  2313.      */
  2314.     public function mapField(array $mapping)
  2315.     {
  2316.         $mapping $this->validateAndCompleteFieldMapping($mapping);
  2317.         $this->assertFieldNotMapped($mapping['fieldName']);
  2318.         $this->fieldMappings[$mapping['fieldName']] = $mapping;
  2319.     }
  2320.     /**
  2321.      * INTERNAL:
  2322.      * Adds an association mapping without completing/validating it.
  2323.      * This is mainly used to add inherited association mappings to derived classes.
  2324.      *
  2325.      * @psalm-param array<string, mixed> $mapping
  2326.      *
  2327.      * @return void
  2328.      *
  2329.      * @throws MappingException
  2330.      */
  2331.     public function addInheritedAssociationMapping(array $mapping/*, $owningClassName = null*/)
  2332.     {
  2333.         if (isset($this->associationMappings[$mapping['fieldName']])) {
  2334.             throw MappingException::duplicateAssociationMapping($this->name$mapping['fieldName']);
  2335.         }
  2336.         $this->associationMappings[$mapping['fieldName']] = $mapping;
  2337.     }
  2338.     /**
  2339.      * INTERNAL:
  2340.      * Adds a field mapping without completing/validating it.
  2341.      * This is mainly used to add inherited field mappings to derived classes.
  2342.      *
  2343.      * @psalm-param array<string, mixed> $fieldMapping
  2344.      *
  2345.      * @return void
  2346.      */
  2347.     public function addInheritedFieldMapping(array $fieldMapping)
  2348.     {
  2349.         $this->fieldMappings[$fieldMapping['fieldName']] = $fieldMapping;
  2350.         $this->columnNames[$fieldMapping['fieldName']]   = $fieldMapping['columnName'];
  2351.         $this->fieldNames[$fieldMapping['columnName']]   = $fieldMapping['fieldName'];
  2352.     }
  2353.     /**
  2354.      * INTERNAL:
  2355.      * Adds a named query to this class.
  2356.      *
  2357.      * @deprecated
  2358.      *
  2359.      * @psalm-param array<string, mixed> $queryMapping
  2360.      *
  2361.      * @return void
  2362.      *
  2363.      * @throws MappingException
  2364.      */
  2365.     public function addNamedQuery(array $queryMapping)
  2366.     {
  2367.         if (! isset($queryMapping['name'])) {
  2368.             throw MappingException::nameIsMandatoryForQueryMapping($this->name);
  2369.         }
  2370.         Deprecation::trigger(
  2371.             'doctrine/orm',
  2372.             'https://github.com/doctrine/orm/issues/8592',
  2373.             'Named Queries are deprecated, here "%s" on entity %s. Move the query logic into EntityRepository',
  2374.             $queryMapping['name'],
  2375.             $this->name
  2376.         );
  2377.         if (isset($this->namedQueries[$queryMapping['name']])) {
  2378.             throw MappingException::duplicateQueryMapping($this->name$queryMapping['name']);
  2379.         }
  2380.         if (! isset($queryMapping['query'])) {
  2381.             throw MappingException::emptyQueryMapping($this->name$queryMapping['name']);
  2382.         }
  2383.         $name  $queryMapping['name'];
  2384.         $query $queryMapping['query'];
  2385.         $dql   str_replace('__CLASS__'$this->name$query);
  2386.         $this->namedQueries[$name] = [
  2387.             'name'  => $name,
  2388.             'query' => $query,
  2389.             'dql'   => $dql,
  2390.         ];
  2391.     }
  2392.     /**
  2393.      * INTERNAL:
  2394.      * Adds a named native query to this class.
  2395.      *
  2396.      * @deprecated
  2397.      *
  2398.      * @psalm-param array<string, mixed> $queryMapping
  2399.      *
  2400.      * @return void
  2401.      *
  2402.      * @throws MappingException
  2403.      */
  2404.     public function addNamedNativeQuery(array $queryMapping)
  2405.     {
  2406.         if (! isset($queryMapping['name'])) {
  2407.             throw MappingException::nameIsMandatoryForQueryMapping($this->name);
  2408.         }
  2409.         Deprecation::trigger(
  2410.             'doctrine/orm',
  2411.             'https://github.com/doctrine/orm/issues/8592',
  2412.             'Named Native Queries are deprecated, here "%s" on entity %s. Move the query logic into EntityRepository',
  2413.             $queryMapping['name'],
  2414.             $this->name
  2415.         );
  2416.         if (isset($this->namedNativeQueries[$queryMapping['name']])) {
  2417.             throw MappingException::duplicateQueryMapping($this->name$queryMapping['name']);
  2418.         }
  2419.         if (! isset($queryMapping['query'])) {
  2420.             throw MappingException::emptyQueryMapping($this->name$queryMapping['name']);
  2421.         }
  2422.         if (! isset($queryMapping['resultClass']) && ! isset($queryMapping['resultSetMapping'])) {
  2423.             throw MappingException::missingQueryMapping($this->name$queryMapping['name']);
  2424.         }
  2425.         $queryMapping['isSelfClass'] = false;
  2426.         if (isset($queryMapping['resultClass'])) {
  2427.             if ($queryMapping['resultClass'] === '__CLASS__') {
  2428.                 $queryMapping['isSelfClass'] = true;
  2429.                 $queryMapping['resultClass'] = $this->name;
  2430.             }
  2431.             $queryMapping['resultClass'] = $this->fullyQualifiedClassName($queryMapping['resultClass']);
  2432.             $queryMapping['resultClass'] = ltrim($queryMapping['resultClass'], '\\');
  2433.         }
  2434.         $this->namedNativeQueries[$queryMapping['name']] = $queryMapping;
  2435.     }
  2436.     /**
  2437.      * INTERNAL:
  2438.      * Adds a sql result set mapping to this class.
  2439.      *
  2440.      * @psalm-param array<string, mixed> $resultMapping
  2441.      *
  2442.      * @return void
  2443.      *
  2444.      * @throws MappingException
  2445.      */
  2446.     public function addSqlResultSetMapping(array $resultMapping)
  2447.     {
  2448.         if (! isset($resultMapping['name'])) {
  2449.             throw MappingException::nameIsMandatoryForSqlResultSetMapping($this->name);
  2450.         }
  2451.         if (isset($this->sqlResultSetMappings[$resultMapping['name']])) {
  2452.             throw MappingException::duplicateResultSetMapping($this->name$resultMapping['name']);
  2453.         }
  2454.         if (isset($resultMapping['entities'])) {
  2455.             foreach ($resultMapping['entities'] as $key => $entityResult) {
  2456.                 if (! isset($entityResult['entityClass'])) {
  2457.                     throw MappingException::missingResultSetMappingEntity($this->name$resultMapping['name']);
  2458.                 }
  2459.                 $entityResult['isSelfClass'] = false;
  2460.                 if ($entityResult['entityClass'] === '__CLASS__') {
  2461.                     $entityResult['isSelfClass'] = true;
  2462.                     $entityResult['entityClass'] = $this->name;
  2463.                 }
  2464.                 $entityResult['entityClass'] = $this->fullyQualifiedClassName($entityResult['entityClass']);
  2465.                 $resultMapping['entities'][$key]['entityClass'] = ltrim($entityResult['entityClass'], '\\');
  2466.                 $resultMapping['entities'][$key]['isSelfClass'] = $entityResult['isSelfClass'];
  2467.                 if (isset($entityResult['fields'])) {
  2468.                     foreach ($entityResult['fields'] as $k => $field) {
  2469.                         if (! isset($field['name'])) {
  2470.                             throw MappingException::missingResultSetMappingFieldName($this->name$resultMapping['name']);
  2471.                         }
  2472.                         if (! isset($field['column'])) {
  2473.                             $fieldName $field['name'];
  2474.                             if (strpos($fieldName'.')) {
  2475.                                 [, $fieldName] = explode('.'$fieldName);
  2476.                             }
  2477.                             $resultMapping['entities'][$key]['fields'][$k]['column'] = $fieldName;
  2478.                         }
  2479.                     }
  2480.                 }
  2481.             }
  2482.         }
  2483.         $this->sqlResultSetMappings[$resultMapping['name']] = $resultMapping;
  2484.     }
  2485.     /**
  2486.      * Adds a one-to-one mapping.
  2487.      *
  2488.      * @param array<string, mixed> $mapping The mapping.
  2489.      *
  2490.      * @return void
  2491.      */
  2492.     public function mapOneToOne(array $mapping)
  2493.     {
  2494.         $mapping['type'] = self::ONE_TO_ONE;
  2495.         $mapping $this->_validateAndCompleteOneToOneMapping($mapping);
  2496.         $this->_storeAssociationMapping($mapping);
  2497.     }
  2498.     /**
  2499.      * Adds a one-to-many mapping.
  2500.      *
  2501.      * @psalm-param array<string, mixed> $mapping The mapping.
  2502.      *
  2503.      * @return void
  2504.      */
  2505.     public function mapOneToMany(array $mapping)
  2506.     {
  2507.         $mapping['type'] = self::ONE_TO_MANY;
  2508.         $mapping $this->_validateAndCompleteOneToManyMapping($mapping);
  2509.         $this->_storeAssociationMapping($mapping);
  2510.     }
  2511.     /**
  2512.      * Adds a many-to-one mapping.
  2513.      *
  2514.      * @psalm-param array<string, mixed> $mapping The mapping.
  2515.      *
  2516.      * @return void
  2517.      */
  2518.     public function mapManyToOne(array $mapping)
  2519.     {
  2520.         $mapping['type'] = self::MANY_TO_ONE;
  2521.         // A many-to-one mapping is essentially a one-one backreference
  2522.         $mapping $this->_validateAndCompleteOneToOneMapping($mapping);
  2523.         $this->_storeAssociationMapping($mapping);
  2524.     }
  2525.     /**
  2526.      * Adds a many-to-many mapping.
  2527.      *
  2528.      * @psalm-param array<string, mixed> $mapping The mapping.
  2529.      *
  2530.      * @return void
  2531.      */
  2532.     public function mapManyToMany(array $mapping)
  2533.     {
  2534.         $mapping['type'] = self::MANY_TO_MANY;
  2535.         $mapping $this->_validateAndCompleteManyToManyMapping($mapping);
  2536.         $this->_storeAssociationMapping($mapping);
  2537.     }
  2538.     /**
  2539.      * Stores the association mapping.
  2540.      *
  2541.      * @psalm-param array<string, mixed> $assocMapping
  2542.      *
  2543.      * @return void
  2544.      *
  2545.      * @throws MappingException
  2546.      */
  2547.     protected function _storeAssociationMapping(array $assocMapping)
  2548.     {
  2549.         $sourceFieldName $assocMapping['fieldName'];
  2550.         $this->assertFieldNotMapped($sourceFieldName);
  2551.         $this->associationMappings[$sourceFieldName] = $assocMapping;
  2552.     }
  2553.     /**
  2554.      * Registers a custom repository class for the entity class.
  2555.      *
  2556.      * @param string $repositoryClassName The class name of the custom mapper.
  2557.      * @psalm-param class-string $repositoryClassName
  2558.      *
  2559.      * @return void
  2560.      */
  2561.     public function setCustomRepositoryClass($repositoryClassName)
  2562.     {
  2563.         $this->customRepositoryClassName $this->fullyQualifiedClassName($repositoryClassName);
  2564.     }
  2565.     /**
  2566.      * Dispatches the lifecycle event of the given entity to the registered
  2567.      * lifecycle callbacks and lifecycle listeners.
  2568.      *
  2569.      * @deprecated Deprecated since version 2.4 in favor of \Doctrine\ORM\Event\ListenersInvoker
  2570.      *
  2571.      * @param string $lifecycleEvent The lifecycle event.
  2572.      * @param object $entity         The Entity on which the event occurred.
  2573.      *
  2574.      * @return void
  2575.      */
  2576.     public function invokeLifecycleCallbacks($lifecycleEvent$entity)
  2577.     {
  2578.         foreach ($this->lifecycleCallbacks[$lifecycleEvent] as $callback) {
  2579.             $entity->$callback();
  2580.         }
  2581.     }
  2582.     /**
  2583.      * Whether the class has any attached lifecycle listeners or callbacks for a lifecycle event.
  2584.      *
  2585.      * @param string $lifecycleEvent
  2586.      *
  2587.      * @return bool
  2588.      */
  2589.     public function hasLifecycleCallbacks($lifecycleEvent)
  2590.     {
  2591.         return isset($this->lifecycleCallbacks[$lifecycleEvent]);
  2592.     }
  2593.     /**
  2594.      * Gets the registered lifecycle callbacks for an event.
  2595.      *
  2596.      * @param string $event
  2597.      *
  2598.      * @psalm-return list<string>
  2599.      */
  2600.     public function getLifecycleCallbacks($event)
  2601.     {
  2602.         return $this->lifecycleCallbacks[$event] ?? [];
  2603.     }
  2604.     /**
  2605.      * Adds a lifecycle callback for entities of this class.
  2606.      *
  2607.      * @param string $callback
  2608.      * @param string $event
  2609.      *
  2610.      * @return void
  2611.      */
  2612.     public function addLifecycleCallback($callback$event)
  2613.     {
  2614.         if ($this->isEmbeddedClass) {
  2615.             Deprecation::trigger(
  2616.                 'doctrine/orm',
  2617.                 'https://github.com/doctrine/orm/pull/8381',
  2618.                 'Registering lifecycle callback %s on Embedded class %s is not doing anything and will throw exception in 3.0',
  2619.                 $event,
  2620.                 $this->name
  2621.             );
  2622.         }
  2623.         if (isset($this->lifecycleCallbacks[$event]) && in_array($callback$this->lifecycleCallbacks[$event])) {
  2624.             return;
  2625.         }
  2626.         $this->lifecycleCallbacks[$event][] = $callback;
  2627.     }
  2628.     /**
  2629.      * Sets the lifecycle callbacks for entities of this class.
  2630.      * Any previously registered callbacks are overwritten.
  2631.      *
  2632.      * @psalm-param array<string, list<string>> $callbacks
  2633.      *
  2634.      * @return void
  2635.      */
  2636.     public function setLifecycleCallbacks(array $callbacks)
  2637.     {
  2638.         $this->lifecycleCallbacks $callbacks;
  2639.     }
  2640.     /**
  2641.      * Adds a entity listener for entities of this class.
  2642.      *
  2643.      * @param string $eventName The entity lifecycle event.
  2644.      * @param string $class     The listener class.
  2645.      * @param string $method    The listener callback method.
  2646.      *
  2647.      * @return void
  2648.      *
  2649.      * @throws MappingException
  2650.      */
  2651.     public function addEntityListener($eventName$class$method)
  2652.     {
  2653.         $class $this->fullyQualifiedClassName($class);
  2654.         $listener = [
  2655.             'class'  => $class,
  2656.             'method' => $method,
  2657.         ];
  2658.         if (! class_exists($class)) {
  2659.             throw MappingException::entityListenerClassNotFound($class$this->name);
  2660.         }
  2661.         if (! method_exists($class$method)) {
  2662.             throw MappingException::entityListenerMethodNotFound($class$method$this->name);
  2663.         }
  2664.         if (isset($this->entityListeners[$eventName]) && in_array($listener$this->entityListeners[$eventName])) {
  2665.             throw MappingException::duplicateEntityListener($class$method$this->name);
  2666.         }
  2667.         $this->entityListeners[$eventName][] = $listener;
  2668.     }
  2669.     /**
  2670.      * Sets the discriminator column definition.
  2671.      *
  2672.      * @see getDiscriminatorColumn()
  2673.      *
  2674.      * @psalm-param array<string, mixed> $columnDef
  2675.      *
  2676.      * @return void
  2677.      *
  2678.      * @throws MappingException
  2679.      */
  2680.     public function setDiscriminatorColumn($columnDef)
  2681.     {
  2682.         if ($columnDef !== null) {
  2683.             if (! isset($columnDef['name'])) {
  2684.                 throw MappingException::nameIsMandatoryForDiscriminatorColumns($this->name);
  2685.             }
  2686.             if (isset($this->fieldNames[$columnDef['name']])) {
  2687.                 throw MappingException::duplicateColumnName($this->name$columnDef['name']);
  2688.             }
  2689.             if (! isset($columnDef['fieldName'])) {
  2690.                 $columnDef['fieldName'] = $columnDef['name'];
  2691.             }
  2692.             if (! isset($columnDef['type'])) {
  2693.                 $columnDef['type'] = 'string';
  2694.             }
  2695.             if (in_array($columnDef['type'], ['boolean''array''object''datetime''time''date'])) {
  2696.                 throw MappingException::invalidDiscriminatorColumnType($this->name$columnDef['type']);
  2697.             }
  2698.             $this->discriminatorColumn $columnDef;
  2699.         }
  2700.     }
  2701.     /**
  2702.      * Sets the discriminator values used by this class.
  2703.      * Used for JOINED and SINGLE_TABLE inheritance mapping strategies.
  2704.      *
  2705.      * @psalm-param array<string, class-string> $map
  2706.      *
  2707.      * @return void
  2708.      */
  2709.     public function setDiscriminatorMap(array $map)
  2710.     {
  2711.         foreach ($map as $value => $className) {
  2712.             $this->addDiscriminatorMapClass($value$className);
  2713.         }
  2714.     }
  2715.     /**
  2716.      * Adds one entry of the discriminator map with a new class and corresponding name.
  2717.      *
  2718.      * @param string $name
  2719.      * @psalm-param class-string $className
  2720.      *
  2721.      * @return void
  2722.      *
  2723.      * @throws MappingException
  2724.      */
  2725.     public function addDiscriminatorMapClass($name$className)
  2726.     {
  2727.         $className $this->fullyQualifiedClassName($className);
  2728.         $className ltrim($className'\\');
  2729.         $this->discriminatorMap[$name] = $className;
  2730.         if ($this->name === $className) {
  2731.             $this->discriminatorValue $name;
  2732.             return;
  2733.         }
  2734.         if (! (class_exists($className) || interface_exists($className))) {
  2735.             throw MappingException::invalidClassInDiscriminatorMap($className$this->name);
  2736.         }
  2737.         if (is_subclass_of($className$this->name) && ! in_array($className$this->subClasses)) {
  2738.             $this->subClasses[] = $className;
  2739.         }
  2740.     }
  2741.     /**
  2742.      * Checks whether the class has a named query with the given query name.
  2743.      *
  2744.      * @param string $queryName
  2745.      *
  2746.      * @return bool
  2747.      */
  2748.     public function hasNamedQuery($queryName)
  2749.     {
  2750.         return isset($this->namedQueries[$queryName]);
  2751.     }
  2752.     /**
  2753.      * Checks whether the class has a named native query with the given query name.
  2754.      *
  2755.      * @param string $queryName
  2756.      *
  2757.      * @return bool
  2758.      */
  2759.     public function hasNamedNativeQuery($queryName)
  2760.     {
  2761.         return isset($this->namedNativeQueries[$queryName]);
  2762.     }
  2763.     /**
  2764.      * Checks whether the class has a named native query with the given query name.
  2765.      *
  2766.      * @param string $name
  2767.      *
  2768.      * @return bool
  2769.      */
  2770.     public function hasSqlResultSetMapping($name)
  2771.     {
  2772.         return isset($this->sqlResultSetMappings[$name]);
  2773.     }
  2774.     /**
  2775.      * {@inheritDoc}
  2776.      */
  2777.     public function hasAssociation($fieldName)
  2778.     {
  2779.         return isset($this->associationMappings[$fieldName]);
  2780.     }
  2781.     /**
  2782.      * {@inheritDoc}
  2783.      */
  2784.     public function isSingleValuedAssociation($fieldName)
  2785.     {
  2786.         return isset($this->associationMappings[$fieldName])
  2787.             && ($this->associationMappings[$fieldName]['type'] & self::TO_ONE);
  2788.     }
  2789.     /**
  2790.      * {@inheritDoc}
  2791.      */
  2792.     public function isCollectionValuedAssociation($fieldName)
  2793.     {
  2794.         return isset($this->associationMappings[$fieldName])
  2795.             && ! ($this->associationMappings[$fieldName]['type'] & self::TO_ONE);
  2796.     }
  2797.     /**
  2798.      * Is this an association that only has a single join column?
  2799.      *
  2800.      * @param string $fieldName
  2801.      *
  2802.      * @return bool
  2803.      */
  2804.     public function isAssociationWithSingleJoinColumn($fieldName)
  2805.     {
  2806.         return isset($this->associationMappings[$fieldName])
  2807.             && isset($this->associationMappings[$fieldName]['joinColumns'][0])
  2808.             && ! isset($this->associationMappings[$fieldName]['joinColumns'][1]);
  2809.     }
  2810.     /**
  2811.      * Returns the single association join column (if any).
  2812.      *
  2813.      * @param string $fieldName
  2814.      *
  2815.      * @return string
  2816.      *
  2817.      * @throws MappingException
  2818.      */
  2819.     public function getSingleAssociationJoinColumnName($fieldName)
  2820.     {
  2821.         if (! $this->isAssociationWithSingleJoinColumn($fieldName)) {
  2822.             throw MappingException::noSingleAssociationJoinColumnFound($this->name$fieldName);
  2823.         }
  2824.         return $this->associationMappings[$fieldName]['joinColumns'][0]['name'];
  2825.     }
  2826.     /**
  2827.      * Returns the single association referenced join column name (if any).
  2828.      *
  2829.      * @param string $fieldName
  2830.      *
  2831.      * @return string
  2832.      *
  2833.      * @throws MappingException
  2834.      */
  2835.     public function getSingleAssociationReferencedJoinColumnName($fieldName)
  2836.     {
  2837.         if (! $this->isAssociationWithSingleJoinColumn($fieldName)) {
  2838.             throw MappingException::noSingleAssociationJoinColumnFound($this->name$fieldName);
  2839.         }
  2840.         return $this->associationMappings[$fieldName]['joinColumns'][0]['referencedColumnName'];
  2841.     }
  2842.     /**
  2843.      * Used to retrieve a fieldname for either field or association from a given column.
  2844.      *
  2845.      * This method is used in foreign-key as primary-key contexts.
  2846.      *
  2847.      * @param string $columnName
  2848.      *
  2849.      * @return string
  2850.      *
  2851.      * @throws MappingException
  2852.      */
  2853.     public function getFieldForColumn($columnName)
  2854.     {
  2855.         if (isset($this->fieldNames[$columnName])) {
  2856.             return $this->fieldNames[$columnName];
  2857.         }
  2858.         foreach ($this->associationMappings as $assocName => $mapping) {
  2859.             if (
  2860.                 $this->isAssociationWithSingleJoinColumn($assocName) &&
  2861.                 $this->associationMappings[$assocName]['joinColumns'][0]['name'] === $columnName
  2862.             ) {
  2863.                 return $assocName;
  2864.             }
  2865.         }
  2866.         throw MappingException::noFieldNameFoundForColumn($this->name$columnName);
  2867.     }
  2868.     /**
  2869.      * Sets the ID generator used to generate IDs for instances of this class.
  2870.      *
  2871.      * @param AbstractIdGenerator $generator
  2872.      *
  2873.      * @return void
  2874.      */
  2875.     public function setIdGenerator($generator)
  2876.     {
  2877.         $this->idGenerator $generator;
  2878.     }
  2879.     /**
  2880.      * Sets definition.
  2881.      *
  2882.      * @psalm-param array<string, string> $definition
  2883.      *
  2884.      * @return void
  2885.      */
  2886.     public function setCustomGeneratorDefinition(array $definition)
  2887.     {
  2888.         $this->customGeneratorDefinition $definition;
  2889.     }
  2890.     /**
  2891.      * Sets the definition of the sequence ID generator for this class.
  2892.      *
  2893.      * The definition must have the following structure:
  2894.      * <code>
  2895.      * array(
  2896.      *     'sequenceName'   => 'name',
  2897.      *     'allocationSize' => 20,
  2898.      *     'initialValue'   => 1
  2899.      *     'quoted'         => 1
  2900.      * )
  2901.      * </code>
  2902.      *
  2903.      * @psalm-param array<string, string> $definition
  2904.      *
  2905.      * @return void
  2906.      *
  2907.      * @throws MappingException
  2908.      */
  2909.     public function setSequenceGeneratorDefinition(array $definition)
  2910.     {
  2911.         if (! isset($definition['sequenceName']) || trim($definition['sequenceName']) === '') {
  2912.             throw MappingException::missingSequenceName($this->name);
  2913.         }
  2914.         if ($definition['sequenceName'][0] === '`') {
  2915.             $definition['sequenceName'] = trim($definition['sequenceName'], '`');
  2916.             $definition['quoted']       = true;
  2917.         }
  2918.         if (! isset($definition['allocationSize']) || trim($definition['allocationSize']) === '') {
  2919.             $definition['allocationSize'] = '1';
  2920.         }
  2921.         if (! isset($definition['initialValue']) || trim($definition['initialValue']) === '') {
  2922.             $definition['initialValue'] = '1';
  2923.         }
  2924.         $this->sequenceGeneratorDefinition $definition;
  2925.     }
  2926.     /**
  2927.      * Sets the version field mapping used for versioning. Sets the default
  2928.      * value to use depending on the column type.
  2929.      *
  2930.      * @psalm-param array<string, mixed> $mapping The version field mapping array.
  2931.      *
  2932.      * @return void
  2933.      *
  2934.      * @throws MappingException
  2935.      */
  2936.     public function setVersionMapping(array &$mapping)
  2937.     {
  2938.         $this->isVersioned  true;
  2939.         $this->versionField $mapping['fieldName'];
  2940.         if (! isset($mapping['default'])) {
  2941.             if (in_array($mapping['type'], ['integer''bigint''smallint'])) {
  2942.                 $mapping['default'] = 1;
  2943.             } elseif ($mapping['type'] === 'datetime') {
  2944.                 $mapping['default'] = 'CURRENT_TIMESTAMP';
  2945.             } else {
  2946.                 throw MappingException::unsupportedOptimisticLockingType($this->name$mapping['fieldName'], $mapping['type']);
  2947.             }
  2948.         }
  2949.     }
  2950.     /**
  2951.      * Sets whether this class is to be versioned for optimistic locking.
  2952.      *
  2953.      * @param bool $bool
  2954.      *
  2955.      * @return void
  2956.      */
  2957.     public function setVersioned($bool)
  2958.     {
  2959.         $this->isVersioned $bool;
  2960.     }
  2961.     /**
  2962.      * Sets the name of the field that is to be used for versioning if this class is
  2963.      * versioned for optimistic locking.
  2964.      *
  2965.      * @param string $versionField
  2966.      *
  2967.      * @return void
  2968.      */
  2969.     public function setVersionField($versionField)
  2970.     {
  2971.         $this->versionField $versionField;
  2972.     }
  2973.     /**
  2974.      * Marks this class as read only, no change tracking is applied to it.
  2975.      *
  2976.      * @return void
  2977.      */
  2978.     public function markReadOnly()
  2979.     {
  2980.         $this->isReadOnly true;
  2981.     }
  2982.     /**
  2983.      * {@inheritDoc}
  2984.      */
  2985.     public function getFieldNames()
  2986.     {
  2987.         return array_keys($this->fieldMappings);
  2988.     }
  2989.     /**
  2990.      * {@inheritDoc}
  2991.      */
  2992.     public function getAssociationNames()
  2993.     {
  2994.         return array_keys($this->associationMappings);
  2995.     }
  2996.     /**
  2997.      * {@inheritDoc}
  2998.      *
  2999.      * @throws InvalidArgumentException
  3000.      */
  3001.     public function getAssociationTargetClass($assocName)
  3002.     {
  3003.         if (! isset($this->associationMappings[$assocName])) {
  3004.             throw new InvalidArgumentException("Association name expected, '" $assocName "' is not an association.");
  3005.         }
  3006.         return $this->associationMappings[$assocName]['targetEntity'];
  3007.     }
  3008.     /**
  3009.      * {@inheritDoc}
  3010.      */
  3011.     public function getName()
  3012.     {
  3013.         return $this->name;
  3014.     }
  3015.     /**
  3016.      * Gets the (possibly quoted) identifier column names for safe use in an SQL statement.
  3017.      *
  3018.      * @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy
  3019.      *
  3020.      * @param AbstractPlatform $platform
  3021.      *
  3022.      * @psalm-return list<string>
  3023.      */
  3024.     public function getQuotedIdentifierColumnNames($platform)
  3025.     {
  3026.         $quotedColumnNames = [];
  3027.         foreach ($this->identifier as $idProperty) {
  3028.             if (isset($this->fieldMappings[$idProperty])) {
  3029.                 $quotedColumnNames[] = isset($this->fieldMappings[$idProperty]['quoted'])
  3030.                     ? $platform->quoteIdentifier($this->fieldMappings[$idProperty]['columnName'])
  3031.                     : $this->fieldMappings[$idProperty]['columnName'];
  3032.                 continue;
  3033.             }
  3034.             // Association defined as Id field
  3035.             $joinColumns            $this->associationMappings[$idProperty]['joinColumns'];
  3036.             $assocQuotedColumnNames array_map(
  3037.                 static function ($joinColumn) use ($platform) {
  3038.                     return isset($joinColumn['quoted'])
  3039.                         ? $platform->quoteIdentifier($joinColumn['name'])
  3040.                         : $joinColumn['name'];
  3041.                 },
  3042.                 $joinColumns
  3043.             );
  3044.             $quotedColumnNames array_merge($quotedColumnNames$assocQuotedColumnNames);
  3045.         }
  3046.         return $quotedColumnNames;
  3047.     }
  3048.     /**
  3049.      * Gets the (possibly quoted) column name of a mapped field for safe use  in an SQL statement.
  3050.      *
  3051.      * @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy
  3052.      *
  3053.      * @param string           $field
  3054.      * @param AbstractPlatform $platform
  3055.      *
  3056.      * @return string
  3057.      */
  3058.     public function getQuotedColumnName($field$platform)
  3059.     {
  3060.         return isset($this->fieldMappings[$field]['quoted'])
  3061.             ? $platform->quoteIdentifier($this->fieldMappings[$field]['columnName'])
  3062.             : $this->fieldMappings[$field]['columnName'];
  3063.     }
  3064.     /**
  3065.      * Gets the (possibly quoted) primary table name of this class for safe use in an SQL statement.
  3066.      *
  3067.      * @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy
  3068.      *
  3069.      * @param AbstractPlatform $platform
  3070.      *
  3071.      * @return string
  3072.      */
  3073.     public function getQuotedTableName($platform)
  3074.     {
  3075.         return isset($this->table['quoted'])
  3076.             ? $platform->quoteIdentifier($this->table['name'])
  3077.             : $this->table['name'];
  3078.     }
  3079.     /**
  3080.      * Gets the (possibly quoted) name of the join table.
  3081.      *
  3082.      * @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy
  3083.      *
  3084.      * @param mixed[]          $assoc
  3085.      * @param AbstractPlatform $platform
  3086.      *
  3087.      * @return string
  3088.      */
  3089.     public function getQuotedJoinTableName(array $assoc$platform)
  3090.     {
  3091.         return isset($assoc['joinTable']['quoted'])
  3092.             ? $platform->quoteIdentifier($assoc['joinTable']['name'])
  3093.             : $assoc['joinTable']['name'];
  3094.     }
  3095.     /**
  3096.      * {@inheritDoc}
  3097.      */
  3098.     public function isAssociationInverseSide($fieldName)
  3099.     {
  3100.         return isset($this->associationMappings[$fieldName])
  3101.             && ! $this->associationMappings[$fieldName]['isOwningSide'];
  3102.     }
  3103.     /**
  3104.      * {@inheritDoc}
  3105.      */
  3106.     public function getAssociationMappedByTargetField($fieldName)
  3107.     {
  3108.         return $this->associationMappings[$fieldName]['mappedBy'];
  3109.     }
  3110.     /**
  3111.      * @param string $targetClass
  3112.      *
  3113.      * @psalm-return array<string, array<string, mixed>>
  3114.      */
  3115.     public function getAssociationsByTargetClass($targetClass)
  3116.     {
  3117.         $relations = [];
  3118.         foreach ($this->associationMappings as $mapping) {
  3119.             if ($mapping['targetEntity'] === $targetClass) {
  3120.                 $relations[$mapping['fieldName']] = $mapping;
  3121.             }
  3122.         }
  3123.         return $relations;
  3124.     }
  3125.     /**
  3126.      * @param string|null $className
  3127.      * @psalm-param ?class-string $className
  3128.      *
  3129.      * @return string|null null if the input value is null
  3130.      */
  3131.     public function fullyQualifiedClassName($className)
  3132.     {
  3133.         if (empty($className)) {
  3134.             return $className;
  3135.         }
  3136.         if ($className !== null && strpos($className'\\') === false && $this->namespace) {
  3137.             return $this->namespace '\\' $className;
  3138.         }
  3139.         return $className;
  3140.     }
  3141.     /**
  3142.      * @param string $name
  3143.      *
  3144.      * @return mixed
  3145.      */
  3146.     public function getMetadataValue($name)
  3147.     {
  3148.         if (isset($this->$name)) {
  3149.             return $this->$name;
  3150.         }
  3151.         return null;
  3152.     }
  3153.     /**
  3154.      * Map Embedded Class
  3155.      *
  3156.      * @psalm-param array<string, mixed> $mapping
  3157.      *
  3158.      * @return void
  3159.      *
  3160.      * @throws MappingException
  3161.      */
  3162.     public function mapEmbedded(array $mapping)
  3163.     {
  3164.         $this->assertFieldNotMapped($mapping['fieldName']);
  3165.         $this->embeddedClasses[$mapping['fieldName']] = [
  3166.             'class' => $this->fullyQualifiedClassName($mapping['class']),
  3167.             'columnPrefix' => $mapping['columnPrefix'],
  3168.             'declaredField' => $mapping['declaredField'] ?? null,
  3169.             'originalField' => $mapping['originalField'] ?? null,
  3170.         ];
  3171.     }
  3172.     /**
  3173.      * Inline the embeddable class
  3174.      *
  3175.      * @param string $property
  3176.      *
  3177.      * @return void
  3178.      */
  3179.     public function inlineEmbeddable($propertyClassMetadataInfo $embeddable)
  3180.     {
  3181.         foreach ($embeddable->fieldMappings as $fieldMapping) {
  3182.             $fieldMapping['originalClass'] = $fieldMapping['originalClass'] ?? $embeddable->name;
  3183.             $fieldMapping['declaredField'] = isset($fieldMapping['declaredField'])
  3184.                 ? $property '.' $fieldMapping['declaredField']
  3185.                 : $property;
  3186.             $fieldMapping['originalField'] = $fieldMapping['originalField'] ?? $fieldMapping['fieldName'];
  3187.             $fieldMapping['fieldName']     = $property '.' $fieldMapping['fieldName'];
  3188.             if (! empty($this->embeddedClasses[$property]['columnPrefix'])) {
  3189.                 $fieldMapping['columnName'] = $this->embeddedClasses[$property]['columnPrefix'] . $fieldMapping['columnName'];
  3190.             } elseif ($this->embeddedClasses[$property]['columnPrefix'] !== false) {
  3191.                 $fieldMapping['columnName'] = $this->namingStrategy
  3192.                     ->embeddedFieldToColumnName(
  3193.                         $property,
  3194.                         $fieldMapping['columnName'],
  3195.                         $this->reflClass->name,
  3196.                         $embeddable->reflClass->name
  3197.                     );
  3198.             }
  3199.             $this->mapField($fieldMapping);
  3200.         }
  3201.     }
  3202.     /**
  3203.      * @throws MappingException
  3204.      */
  3205.     private function assertFieldNotMapped(string $fieldName): void
  3206.     {
  3207.         if (
  3208.             isset($this->fieldMappings[$fieldName]) ||
  3209.             isset($this->associationMappings[$fieldName]) ||
  3210.             isset($this->embeddedClasses[$fieldName])
  3211.         ) {
  3212.             throw MappingException::duplicateFieldMapping($this->name$fieldName);
  3213.         }
  3214.     }
  3215.     /**
  3216.      * Gets the sequence name based on class metadata.
  3217.      *
  3218.      * @return string
  3219.      *
  3220.      * @todo Sequence names should be computed in DBAL depending on the platform
  3221.      */
  3222.     public function getSequenceName(AbstractPlatform $platform)
  3223.     {
  3224.         $sequencePrefix $this->getSequencePrefix($platform);
  3225.         $columnName     $this->getSingleIdentifierColumnName();
  3226.         return $sequencePrefix '_' $columnName '_seq';
  3227.     }
  3228.     /**
  3229.      * Gets the sequence name prefix based on class metadata.
  3230.      *
  3231.      * @return string
  3232.      *
  3233.      * @todo Sequence names should be computed in DBAL depending on the platform
  3234.      */
  3235.     public function getSequencePrefix(AbstractPlatform $platform)
  3236.     {
  3237.         $tableName      $this->getTableName();
  3238.         $sequencePrefix $tableName;
  3239.         // Prepend the schema name to the table name if there is one
  3240.         $schemaName $this->getSchemaName();
  3241.         if ($schemaName) {
  3242.             $sequencePrefix $schemaName '.' $tableName;
  3243.             if (! $platform->supportsSchemas() && $platform->canEmulateSchemas()) {
  3244.                 $sequencePrefix $schemaName '__' $tableName;
  3245.             }
  3246.         }
  3247.         return $sequencePrefix;
  3248.     }
  3249.     /**
  3250.      * @psalm-param array<string, mixed> $mapping
  3251.      */
  3252.     private function assertMappingOrderBy(array $mapping): void
  3253.     {
  3254.         if (isset($mapping['orderBy']) && ! is_array($mapping['orderBy'])) {
  3255.             throw new InvalidArgumentException("'orderBy' is expected to be an array, not " gettype($mapping['orderBy']));
  3256.         }
  3257.     }
  3258. }