Skip to content

Commit

Permalink
Merge pull request #9693 from doctrine/2.12.x
Browse files Browse the repository at this point in the history
Merge 2.12.x up into 2.13.x
  • Loading branch information
greg0ire authored Apr 29, 2022
2 parents 825e964 + a0a0b0e commit d8f3198
Show file tree
Hide file tree
Showing 62 changed files with 252 additions and 257 deletions.
2 changes: 1 addition & 1 deletion docs/en/cookbook/sql-table-prefixes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ appropriate autoloaders.
}
foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) {
if ($mapping['type'] == \Doctrine\ORM\Mapping\ClassMetadataInfo::MANY_TO_MANY && $mapping['isOwningSide']) {
if ($mapping['type'] == \Doctrine\ORM\Mapping\ClassMetadata::MANY_TO_MANY && $mapping['isOwningSide']) {
$mappedTableName = $mapping['joinTable']['name'];
$classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $this->prefix . $mappedTableName;
}
Expand Down
86 changes: 46 additions & 40 deletions docs/en/reference/metadata-drivers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,51 +55,66 @@ Implementing Metadata Drivers

In addition to the included metadata drivers you can very easily
implement your own. All you need to do is define a class which
implements the ``Driver`` interface:
implements the ``MappingDriver`` interface:

.. code-block:: php
<?php
namespace Doctrine\ORM\Mapping\Driver;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
interface Driver
declare(strict_types=1);
namespace Doctrine\Persistence\Mapping\Driver;
use Doctrine\Persistence\Mapping\ClassMetadata;
/**
* Contract for metadata drivers.
*/
interface MappingDriver
{
/**
* Loads the metadata for the specified class into the provided container.
*
* @param string $className
* @param ClassMetadataInfo $metadata
*
* @psalm-param class-string<T> $className
* @psalm-param ClassMetadata<T> $metadata
*
* @return void
*
* @template T of object
*/
function loadMetadataForClass($className, ClassMetadataInfo $metadata);
public function loadMetadataForClass(string $className, ClassMetadata $metadata);
/**
* Gets the names of all mapped classes known to this driver.
*
* @return array The names of all mapped classes known to this driver.
*
* @return array<int, string> The names of all mapped classes known to this driver.
* @psalm-return list<class-string>
*/
function getAllClassNames();
public function getAllClassNames();
/**
* Whether the class with the specified name should have its metadata loaded.
* This is only the case if it is either mapped as an Entity or a
* MappedSuperclass.
* Returns whether the class with the specified name should have its metadata loaded.
* This is only the case if it is either mapped as an Entity or a MappedSuperclass.
*
* @psalm-param class-string $className
*
* @param string $className
* @return boolean
* @return bool
*/
function isTransient($className);
public function isTransient(string $className);
}
If you want to write a metadata driver to parse information from
some file format we've made your life a little easier by providing
the ``AbstractFileDriver`` implementation for you to extend from:
the ``FileDriver`` implementation for you to extend from:

.. code-block:: php
<?php
class MyMetadataDriver extends AbstractFileDriver
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\Mapping\Driver\FileDriver;
class MyMetadataDriver extends FileDriver
{
/**
* {@inheritdoc}
Expand All @@ -109,11 +124,11 @@ the ``AbstractFileDriver`` implementation for you to extend from:
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
$data = $this->_loadMappingFile($file);
// populate ClassMetadataInfo instance from $data
// populate ClassMetadata instance from $data
}
/**
Expand All @@ -127,13 +142,12 @@ the ``AbstractFileDriver`` implementation for you to extend from:
.. note::

When using the ``AbstractFileDriver`` it requires that you
only have one entity defined per file and the file named after the
class described inside where namespace separators are replaced by
periods. So if you have an entity named ``Entities\User`` and you
wanted to write a mapping file for your driver above you would need
to name the file ``Entities.User.dcm.ext`` for it to be
recognized.
When using the ``FileDriver`` it requires that you only have one
entity defined per file and the file named after the class described
inside where namespace separators are replaced by periods. So if you
have an entity named ``Entities\User`` and you wanted to write a
mapping file for your driver above you would need to name the file
``Entities.User.dcm.ext`` for it to be recognized.


Now you can use your ``MyMetadataDriver`` implementation by setting
Expand All @@ -156,14 +170,6 @@ entity when needed.

You have all the methods you need to manually specify the mapping
information instead of using some mapping file to populate it from.
The base ``ClassMetadataInfo`` class is responsible for only data
storage and is not meant for runtime use. It does not require that
the class actually exists yet so it is useful for describing some
entity before it exists and using that information to generate for
example the entities themselves. The class ``ClassMetadata``
extends ``ClassMetadataInfo`` and adds some functionality required
for runtime usage and requires that the PHP class is present and
can be autoloaded.

You can read more about the API of the ``ClassMetadata`` classes in
the PHP Mapping chapter.
Expand Down
21 changes: 9 additions & 12 deletions docs/en/reference/php-mapping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,12 @@ It also has several methods that create builders (which are necessary for advanc
- ``createManyToMany($name, $targetEntity)`` returns an ``ManyToManyAssociationBuilder`` instance
- ``createOneToMany($name, $targetEntity)`` returns an ``OneToManyAssociationBuilder`` instance

ClassMetadataInfo API
---------------------
ClassMetadata API
-----------------

The ``ClassMetadataInfo`` class is the base data object for storing
the mapping metadata for a single entity. It contains all the
getters and setters you need populate and retrieve information for
an entity.
The ``ClassMetadata`` class is the data object for storing the mapping
metadata for a single entity. It contains all the getters and setters
you need populate and retrieve information for an entity.

General Setters
~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -309,13 +308,11 @@ Lifecycle Callback Getters
- ``hasLifecycleCallbacks($lifecycleEvent)``
- ``getLifecycleCallbacks($event)``

ClassMetadata API
-----------------
Runtime reflection methods
~~~~~~~~~~~~~~~~~~~~~~~~~~

The ``ClassMetadata`` class extends ``ClassMetadataInfo`` and adds
the runtime functionality required by Doctrine. It adds a few extra
methods related to runtime reflection for working with the entities
themselves.
These are methods related to runtime reflection for working with the
entities themselves.


- ``getReflectionClass()``
Expand Down
12 changes: 6 additions & 6 deletions docs/en/reference/tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ When using the SchemaTool class directly, create your schema using
the ``createSchema()`` method. First create an instance of the
``SchemaTool`` and pass it an instance of the ``EntityManager``
that you want to use to create the schema. This method receives an
array of ``ClassMetadataInfo`` instances.
array of ``ClassMetadata`` instances.

.. code-block:: php
Expand Down Expand Up @@ -180,8 +180,8 @@ tables of the current model to clean up with orphaned tables.
You can also use database introspection to update your schema
easily with the ``updateSchema()`` method. It will compare your
existing database schema to the passed array of
``ClassMetadataInfo`` instances.
existing database schema to the passed array of ``ClassMetadata``
instances.

.. code-block:: php
Expand Down Expand Up @@ -324,9 +324,9 @@ convert to and the path to generate it:
Reverse Engineering
-------------------

You can use the ``DatabaseDriver`` to reverse engineer a database
to an array of ``ClassMetadataInfo`` instances and generate YAML,
XML, etc. from them.
You can use the ``DatabaseDriver`` to reverse engineer a database to an
array of ``ClassMetadata`` instances and generate YAML, XML, etc. from
them.

.. note::

Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/Models/CMS/CmsAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Doctrine\ORM\Events;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\ColumnResult;
use Doctrine\ORM\Mapping\Entity;
Expand Down Expand Up @@ -157,7 +157,7 @@ public function setUser(CmsUser $user): void
}
}

public static function loadMetadata(ClassMetadataInfo $metadata): void
public static function loadMetadata(ClassMetadata $metadata): void
{
$metadata->setPrimaryTable(
['name' => 'company_person']
Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/Models/CMS/CmsUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\ColumnResult;
use Doctrine\ORM\Mapping\Entity;
Expand Down Expand Up @@ -336,7 +336,7 @@ public function setEmail(?CmsEmail $email = null): void
}
}

public static function loadMetadata(ClassMetadataInfo $metadata): void
public static function loadMetadata(ClassMetadata $metadata): void
{
$metadata->setPrimaryTable(
['name' => 'cms_users']
Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/Models/Cache/City.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\Cache;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
Expand Down Expand Up @@ -136,7 +136,7 @@ public function getAttractions(): Collection
return $this->attractions;
}

public static function loadMetadata(ClassMetadataInfo $metadata): void
public static function loadMetadata(ClassMetadata $metadata): void
{
include __DIR__ . '/../../ORM/Mapping/php/Doctrine.Tests.Models.Cache.City.php';
}
Expand Down
3 changes: 1 addition & 2 deletions tests/Doctrine/Tests/Models/Company/CompanyContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Doctrine\ORM\Events;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\DiscriminatorColumn;
use Doctrine\ORM\Mapping\DiscriminatorMap;
Expand Down Expand Up @@ -170,7 +169,7 @@ public function removeEngineer(CompanyEmployee $engineer): void

abstract public function calculatePrice(): int;

public static function loadMetadata(ClassMetadataInfo $metadata): void
public static function loadMetadata(ClassMetadata $metadata): void
{
$metadata->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_JOINED);
$metadata->setTableName('company_contracts');
Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/Models/Company/CompanyFixContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Doctrine\Tests\Models\Company;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;

Expand Down Expand Up @@ -36,7 +36,7 @@ public function setFixPrice($fixPrice): void
$this->fixPrice = $fixPrice;
}

public static function loadMetadata(ClassMetadataInfo $metadata): void
public static function loadMetadata(ClassMetadata $metadata): void
{
$metadata->mapField(
[
Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/Models/Company/CompanyFlexContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\EntityResult;
Expand Down Expand Up @@ -140,7 +140,7 @@ public function removeManager(CompanyManager $manager): void
$this->managers->removeElement($manager);
}

public static function loadMetadata(ClassMetadataInfo $metadata): void
public static function loadMetadata(ClassMetadata $metadata): void
{
$metadata->mapField(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Doctrine\ORM\Events;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\EntityListeners;
Expand Down Expand Up @@ -42,7 +42,7 @@ public function setMaxPrice(int $maxPrice): void
$this->maxPrice = $maxPrice;
}

public static function loadMetadata(ClassMetadataInfo $metadata): void
public static function loadMetadata(ClassMetadata $metadata): void
{
$metadata->mapField(
[
Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/Models/Company/CompanyPerson.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\DiscriminatorColumn;
use Doctrine\ORM\Mapping\DiscriminatorMap;
Expand Down Expand Up @@ -153,7 +153,7 @@ public function setSpouse(CompanyPerson $spouse): void
}
}

public static function loadMetadata(ClassMetadataInfo $metadata): void
public static function loadMetadata(ClassMetadata $metadata): void
{
$metadata->setPrimaryTable(
['name' => 'company_person']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Doctrine\Tests\Models\DDC1476;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
Expand Down Expand Up @@ -48,7 +48,7 @@ public function setName(string $name): void
$this->name = $name;
}

public static function loadMetadata(ClassMetadataInfo $metadata): void
public static function loadMetadata(ClassMetadata $metadata): void
{
$metadata->mapField(
[
Expand All @@ -60,6 +60,6 @@ public static function loadMetadata(ClassMetadataInfo $metadata): void
['fieldName' => 'name']
);

$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE);
$metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);
}
}
Loading

0 comments on commit d8f3198

Please sign in to comment.