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

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