From a06011daf39ea2623c57a23dcf4465edbf061c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 27 Apr 2022 23:23:02 +0200 Subject: [PATCH 1/3] Refer to ClassMetadata instead of ClassMetadataInfo Although properties and methods are currently located in ClassMetadataInfo, it is better to refer to ClassMetadata as the former is deprecated in favor of the latter. --- docs/en/cookbook/sql-table-prefixes.rst | 2 +- docs/en/reference/tools.rst | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/en/cookbook/sql-table-prefixes.rst b/docs/en/cookbook/sql-table-prefixes.rst index 5ea587986b..dc4ae6952d 100644 --- a/docs/en/cookbook/sql-table-prefixes.rst +++ b/docs/en/cookbook/sql-table-prefixes.rst @@ -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; } diff --git a/docs/en/reference/tools.rst b/docs/en/reference/tools.rst index a215c38503..5c290ccebf 100644 --- a/docs/en/reference/tools.rst +++ b/docs/en/reference/tools.rst @@ -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 @@ -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 @@ -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:: From 6d2ca8fe40e35cf9f1e30c61d0c6bd6753c70e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 27 Apr 2022 23:24:12 +0200 Subject: [PATCH 2/3] Address mapping driver extraction This documentation must be very old because this is no longer valid as of e9e36dcf328218f07e88b5ffa9db9bd4ff593275 . The interface and abstract file driver have since then been moved to doctrine/common, and the to doctrine/persistence. --- docs/en/reference/metadata-drivers.rst | 78 +++++++++++++++----------- 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/docs/en/reference/metadata-drivers.rst b/docs/en/reference/metadata-drivers.rst index 9b0d521db3..0c3d567767 100644 --- a/docs/en/reference/metadata-drivers.rst +++ b/docs/en/reference/metadata-drivers.rst @@ -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 $className + * @psalm-param ClassMetadata $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 The names of all mapped classes known to this driver. + * @psalm-return list */ - 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 _loadMappingFile($file); - // populate ClassMetadataInfo instance from $data + // populate ClassMetadata instance from $data } /** @@ -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 From e9d3c218ef8cef9d193b8bd48d74c766bc329ec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 27 Apr 2022 23:26:07 +0200 Subject: [PATCH 3/3] Remove explanation about inexistent distinction ClassMetadataInfo used to be useful during entity generation, because it allowed the entity not to exist. We no longer do entity generation, and even if we did, the reflection methods have been moved to ClassMetadataInfo as of 76e4f5a80bf8faa6e00ec4746c34f2e4bfd4215e . --- docs/en/reference/metadata-drivers.rst | 8 -------- docs/en/reference/php-mapping.rst | 21 +++++++++------------ 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/docs/en/reference/metadata-drivers.rst b/docs/en/reference/metadata-drivers.rst index 0c3d567767..d7b04f11b1 100644 --- a/docs/en/reference/metadata-drivers.rst +++ b/docs/en/reference/metadata-drivers.rst @@ -170,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. diff --git a/docs/en/reference/php-mapping.rst b/docs/en/reference/php-mapping.rst index 0b4557136f..4ce2b52552 100644 --- a/docs/en/reference/php-mapping.rst +++ b/docs/en/reference/php-mapping.rst @@ -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 ~~~~~~~~~~~~~~~ @@ -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()``