Skip to content

Commit

Permalink
Merge pull request #9691 from greg0ire/reference-cmi-less
Browse files Browse the repository at this point in the history
Reference ClassMetadaInfo less
  • Loading branch information
greg0ire authored Apr 28, 2022
2 parents 0846b8b + e9d3c21 commit 38d1124
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 59 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

0 comments on commit 38d1124

Please sign in to comment.