From 2dde65c4bacce3c9c26d24fceb9bde938a5ba34c Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Thu, 11 Nov 2021 00:22:25 +0100 Subject: [PATCH 01/12] [Documentation] Events Overview Table: Adding "Passed Argument" column As announced in https://github.com/doctrine/orm/pull/9160#issuecomment-954304588 I'm adding the passed "EventArgs" class to the overview table. Once this is complete, my further plan is to remove the entire paragraph https://www.doctrine-project.org/projects/doctrine-orm/en/2.10/reference/events.html#lifecycle-callbacks-event-argument, and probably also the second code block at https://www.doctrine-project.org/projects/doctrine-orm/en/2.10/reference/events.html#entity-listeners-class Is there a better way to link to the source code of `LifecycleEventArgs` than https://github.com/doctrine/persistence/blob/2.2.x/lib/Doctrine/Persistence/Event/LifecycleEventArgs.php ? Also, I changed `postLoad` to `preUpdate` in the code block, to have an example that does not receive `LifecycleEventArgs` ;-) --- docs/en/reference/events.rst | 90 +++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 42 deletions(-) diff --git a/docs/en/reference/events.rst b/docs/en/reference/events.rst index f3e5fe75c38..f4a698566b6 100644 --- a/docs/en/reference/events.rst +++ b/docs/en/reference/events.rst @@ -135,38 +135,38 @@ see :ref:`Lifecycle Callbacks` Events Overview --------------- -+-----------------------------------------------------------------+-----------------------+-----------+ -| Event | Dispatched by | Lifecycle | -| | | Callback | -+=================================================================+=======================+===========+ -| :ref:`preRemove` | ``$em->remove()`` | Yes | -+-----------------------------------------------------------------+-----------------------+-----------+ -| :ref:`postRemove` | ``$em->flush()`` | Yes | -+-----------------------------------------------------------------+-----------------------+-----------+ -| :ref:`prePersist` | ``$em->persist()`` | Yes | -| | on *initial* persist | | -+-----------------------------------------------------------------+-----------------------+-----------+ -| :ref:`postPersist` | ``$em->flush()`` | Yes | -+-----------------------------------------------------------------+-----------------------+-----------+ -| :ref:`preUpdate` | ``$em->flush()`` | Yes | -+-----------------------------------------------------------------+-----------------------+-----------+ -| :ref:`postUpdate` | ``$em->flush()`` | Yes | -+-----------------------------------------------------------------+-----------------------+-----------+ -| :ref:`postLoad` | Loading from database | Yes | -+-----------------------------------------------------------------+-----------------------+-----------+ -| :ref:`loadClassMetadata` | Loading of mapping | No | -| | metadata | | -+-----------------------------------------------------------------+-----------------------+-----------+ -| ``onClassMetadataNotFound`` | ``MappingException`` | No | -+-----------------------------------------------------------------+-----------------------+-----------+ -| :ref:`preFlush` | ``$em->flush()`` | Yes | -+-----------------------------------------------------------------+-----------------------+-----------+ -| :ref:`onFlush` | ``$em->flush()`` | No | -+-----------------------------------------------------------------+-----------------------+-----------+ -| :ref:`postFlush` | ``$em->flush()`` | No | -+-----------------------------------------------------------------+-----------------------+-----------+ -| ``onClear`` | ``$em->clear()`` | No | -+-----------------------------------------------------------------+-----------------------+-----------+ ++-----------------------------------------------------------------+-----------------------+-----------+------------------------+ +| Event | Dispatched by | Lifecycle | Passed | +| | | Callback | Argument | ++=================================================================+=======================+===========+========================+ +| :ref:`preRemove` | ``$em->remove()`` | Yes | | ++-----------------------------------------------------------------+-----------------------+-----------+------------------------+ +| :ref:`postRemove` | ``$em->flush()`` | Yes | | ++-----------------------------------------------------------------+-----------------------+-----------+------------------------+ +| :ref:`prePersist` | ``$em->persist()`` | Yes | `_LifecycleEventArgs`_ | +| | on *initial* persist | | | ++-----------------------------------------------------------------+-----------------------+-----------+------------------------+ +| :ref:`postPersist` | ``$em->flush()`` | Yes | | ++-----------------------------------------------------------------+-----------------------+-----------+------------------------+ +| :ref:`preUpdate` | ``$em->flush()`` | Yes | | ++-----------------------------------------------------------------+-----------------------+-----------+------------------------+ +| :ref:`postUpdate` | ``$em->flush()`` | Yes | | ++-----------------------------------------------------------------+-----------------------+-----------+------------------------+ +| :ref:`postLoad` | Loading from database | Yes | | ++-----------------------------------------------------------------+-----------------------+-----------+------------------------+ +| :ref:`loadClassMetadata` | Loading of mapping | No | | +| | metadata | | | ++-----------------------------------------------------------------+-----------------------+-----------+------------------------+ +| ``onClassMetadataNotFound`` | ``MappingException`` | No | | ++-----------------------------------------------------------------+-----------------------+-----------+------------------------+ +| :ref:`preFlush` | ``$em->flush()`` | Yes | | ++-----------------------------------------------------------------+-----------------------+-----------+------------------------+ +| :ref:`onFlush` | ``$em->flush()`` | No | | ++-----------------------------------------------------------------+-----------------------+-----------+------------------------+ +| :ref:`postFlush` | ``$em->flush()`` | No | | ++-----------------------------------------------------------------+-----------------------+-----------+------------------------+ +| ``onClear`` | ``$em->clear()`` | No | | ++-----------------------------------------------------------------+-----------------------+-----------+------------------------+ Naming convention ~~~~~~~~~~~~~~~~~ @@ -296,6 +296,8 @@ specific to a particular entity class's lifecycle. .. code-block:: attribute createdAt = date('Y-m-d H:i:s'); } @@ -320,15 +322,17 @@ specific to a particular entity class's lifecycle. $this->value = 'changed from prePersist callback!'; } - #[PostLoad] - public function doStuffOnPostLoad() + #[PreUpdate] + public function doStuffOnPreUpdate(PreUpdateEventArgs $eventArgs) { - $this->value = 'changed from postLoad callback!'; + $this->value = 'changed from preUpdate callback!'; } } .. code-block:: annotation createdAt = date('Y-m-d H:i:s'); } @@ -353,10 +357,10 @@ specific to a particular entity class's lifecycle. $this->value = 'changed from prePersist callback!'; } - /** @PostLoad */ - public function doStuffOnPostLoad() + /** @PreUpdate */ + public function doStuffOnPreUpdate(PreUpdateEventArgs $eventArgs) { - $this->value = 'changed from postLoad callback!'; + $this->value = 'changed from preUpdate callback!'; } } .. code-block:: xml @@ -372,7 +376,7 @@ specific to a particular entity class's lifecycle. - + @@ -386,7 +390,7 @@ specific to a particular entity class's lifecycle. type: string(255) lifecycleCallbacks: prePersist: [ doStuffOnPrePersist, doOtherStuffOnPrePersist ] - postLoad: [ doStuffOnPostLoad ] + preUpdate: [ doStuffOnPreUpdate ] Lifecycle Callbacks Event Argument ---------------------------------- @@ -1073,3 +1077,5 @@ and the EntityManager. $em = $eventArgs->getEntityManager(); } } + +.. _LifecycleEventArgs: https://github.com/doctrine/persistence/blob/2.2.x/lib/Doctrine/Persistence/Event/LifecycleEventArgs.php From 77b7107d05f69c942b9a90a3ee9b60ba6a454bde Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Tue, 23 Nov 2021 01:41:01 +0100 Subject: [PATCH 02/12] Using `const` for `type` --- docs/en/reference/events.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/en/reference/events.rst b/docs/en/reference/events.rst index f4a698566b6..6da07e867d7 100644 --- a/docs/en/reference/events.rst +++ b/docs/en/reference/events.rst @@ -297,6 +297,7 @@ specific to a particular entity class's lifecycle. Date: Tue, 30 Nov 2021 15:51:20 +0100 Subject: [PATCH 03/12] Completing links to `EventArgs` classes in overview table Questions: 1. Is https://github.com/doctrine/persistence/blob/master/lib/Doctrine/Persistence/Event/LifecycleEventArgs.php correct at all? Shouldn't this be https://github.com/doctrine/orm/blob/2.10.x/lib/Doctrine/ORM/Event/LifecycleEventArgs.php, like all the others? 2. Which one is correct for `preUpdate`? https://www.doctrine-project.org/projects/doctrine-orm/en/2.10/reference/events.html#entity-listeners-class says `PreUpdateEventArgs`, but https://www.doctrine-project.org/projects/doctrine-orm/en/2.10/reference/events.html#listening-and-subscribing-to-lifecycle-events says `LifecycleEventArgs` For the two links to `doctrine/persistence`, I'm linking to `/master/` now, which is being forwarded to `/2.2.x/`. --- docs/en/reference/events.rst | 73 ++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/docs/en/reference/events.rst b/docs/en/reference/events.rst index 6da07e867d7..7e3bdfddf3d 100644 --- a/docs/en/reference/events.rst +++ b/docs/en/reference/events.rst @@ -135,38 +135,38 @@ see :ref:`Lifecycle Callbacks` Events Overview --------------- -+-----------------------------------------------------------------+-----------------------+-----------+------------------------+ -| Event | Dispatched by | Lifecycle | Passed | -| | | Callback | Argument | -+=================================================================+=======================+===========+========================+ -| :ref:`preRemove` | ``$em->remove()`` | Yes | | -+-----------------------------------------------------------------+-----------------------+-----------+------------------------+ -| :ref:`postRemove` | ``$em->flush()`` | Yes | | -+-----------------------------------------------------------------+-----------------------+-----------+------------------------+ -| :ref:`prePersist` | ``$em->persist()`` | Yes | `_LifecycleEventArgs`_ | -| | on *initial* persist | | | -+-----------------------------------------------------------------+-----------------------+-----------+------------------------+ -| :ref:`postPersist` | ``$em->flush()`` | Yes | | -+-----------------------------------------------------------------+-----------------------+-----------+------------------------+ -| :ref:`preUpdate` | ``$em->flush()`` | Yes | | -+-----------------------------------------------------------------+-----------------------+-----------+------------------------+ -| :ref:`postUpdate` | ``$em->flush()`` | Yes | | -+-----------------------------------------------------------------+-----------------------+-----------+------------------------+ -| :ref:`postLoad` | Loading from database | Yes | | -+-----------------------------------------------------------------+-----------------------+-----------+------------------------+ -| :ref:`loadClassMetadata` | Loading of mapping | No | | -| | metadata | | | -+-----------------------------------------------------------------+-----------------------+-----------+------------------------+ -| ``onClassMetadataNotFound`` | ``MappingException`` | No | | -+-----------------------------------------------------------------+-----------------------+-----------+------------------------+ -| :ref:`preFlush` | ``$em->flush()`` | Yes | | -+-----------------------------------------------------------------+-----------------------+-----------+------------------------+ -| :ref:`onFlush` | ``$em->flush()`` | No | | -+-----------------------------------------------------------------+-----------------------+-----------+------------------------+ -| :ref:`postFlush` | ``$em->flush()`` | No | | -+-----------------------------------------------------------------+-----------------------+-----------+------------------------+ -| ``onClear`` | ``$em->clear()`` | No | | -+-----------------------------------------------------------------+-----------------------+-----------+------------------------+ ++-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+ +| Event | Dispatched by | Lifecycle | Passed | +| | | Callback | Argument | ++=================================================================+=======================+===========+=====================================+ +| :ref:`preRemove` | ``$em->remove()`` | Yes | `_LifecycleEventArgs`_ | ++-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+ +| :ref:`postRemove` | ``$em->flush()`` | Yes | `_LifecycleEventArgs`_ | ++-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+ +| :ref:`prePersist` | ``$em->persist()`` | Yes | `_LifecycleEventArgs`_ | +| | on *initial* persist | | | ++-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+ +| :ref:`postPersist` | ``$em->flush()`` | Yes | `_LifecycleEventArgs`_ | ++-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+ +| :ref:`preUpdate` | ``$em->flush()`` | Yes | `_PreUpdateEventArgs`_ | ++-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+ +| :ref:`postUpdate` | ``$em->flush()`` | Yes | `_LifecycleEventArgs`_ | ++-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+ +| :ref:`postLoad` | Loading from database | Yes | `_LifecycleEventArgs`_ | ++-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+ +| :ref:`loadClassMetadata` | Loading of mapping | No | `_LoadClassMetadataEventArgs` | +| | metadata | | | ++-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+ +| ``onClassMetadataNotFound`` | ``MappingException`` | No | `_OnClassMetadataNotFoundEventArgs` | ++-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+ +| :ref:`preFlush` | ``$em->flush()`` | Yes | `_PreFlushEventArgs`_ | ++-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+ +| :ref:`onFlush` | ``$em->flush()`` | No | `_OnFlushEventArgs` | ++-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+ +| :ref:`postFlush` | ``$em->flush()`` | No | `_PostFlushEventArgs` | ++-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+ +| ``onClear`` | ``$em->clear()`` | No | `_OnClearEventArgs` | ++-----------------------------------------------------------------+-----------------------+-----------+-------------------------------------+ Naming convention ~~~~~~~~~~~~~~~~~ @@ -1079,4 +1079,11 @@ and the EntityManager. } } -.. _LifecycleEventArgs: https://github.com/doctrine/persistence/blob/2.2.x/lib/Doctrine/Persistence/Event/LifecycleEventArgs.php +.. _LifecycleEventArgs: https://github.com/doctrine/persistence/blob/master/lib/Doctrine/Persistence/Event/LifecycleEventArgs.php +.. _PreUpdateEventArgs: https://github.com/doctrine/persistence/blob/master/lib/Doctrine/Persistence/Event/PreUpdateEventArgs.php +.. _PreFlushEventArgs: https://github.com/doctrine/orm/blob/2.10.x/lib/Doctrine/ORM/Event/PreFlushEventArgs.php +.. _PostFlushEventArgs: https://github.com/doctrine/orm/blob/2.10.x/lib/Doctrine/ORM/Event/PostFlushEventArgs.php +.. _OnFlushEventArgs: https://github.com/doctrine/orm/blob/2.10.x/lib/Doctrine/ORM/Event/OnFlushEventArgs.php +.. _OnClearEventArgs: https://github.com/doctrine/orm/blob/2.10.x/lib/Doctrine/ORM/Event/OnClearEventArgs.php +.. _LoadClassMetadataEventArgs: https://github.com/doctrine/orm/blob/2.10.x/lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php +.. _OnClassMetadataNotFoundEventArgs: https://github.com/doctrine/orm/blob/2.10.x/lib/Doctrine/ORM/Event/OnClassMetadataNotFoundEventArgs.php From 8b6fe52f7417582c222c4bc6109bb60c5dce6608 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Wed, 1 Dec 2021 01:01:04 +0100 Subject: [PATCH 04/12] Update events.rst --- docs/en/reference/events.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/reference/events.rst b/docs/en/reference/events.rst index 7e3bdfddf3d..d393b7fed06 100644 --- a/docs/en/reference/events.rst +++ b/docs/en/reference/events.rst @@ -1079,8 +1079,8 @@ and the EntityManager. } } -.. _LifecycleEventArgs: https://github.com/doctrine/persistence/blob/master/lib/Doctrine/Persistence/Event/LifecycleEventArgs.php -.. _PreUpdateEventArgs: https://github.com/doctrine/persistence/blob/master/lib/Doctrine/Persistence/Event/PreUpdateEventArgs.php +.. _LifecycleEventArgs: https://github.com/doctrine/orm/blob/2.10.x/lib/Doctrine/ORM/Event/LifecycleEventArgs.php +.. _PreUpdateEventArgs: https://github.com/doctrine/orm/blob/2.10.x/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php .. _PreFlushEventArgs: https://github.com/doctrine/orm/blob/2.10.x/lib/Doctrine/ORM/Event/PreFlushEventArgs.php .. _PostFlushEventArgs: https://github.com/doctrine/orm/blob/2.10.x/lib/Doctrine/ORM/Event/PostFlushEventArgs.php .. _OnFlushEventArgs: https://github.com/doctrine/orm/blob/2.10.x/lib/Doctrine/ORM/Event/OnFlushEventArgs.php From ed1a5763058c27d43b534f4311f6544d22948530 Mon Sep 17 00:00:00 2001 From: Florian Varrin <34935953+Florian-Varrin@users.noreply.github.com> Date: Fri, 3 Dec 2021 11:39:59 +0100 Subject: [PATCH 05/12] Fix typo assumptio--> assumption --- docs/en/tutorials/extra-lazy-associations.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/tutorials/extra-lazy-associations.rst b/docs/en/tutorials/extra-lazy-associations.rst index 28fb479609c..622ae5eb497 100644 --- a/docs/en/tutorials/extra-lazy-associations.rst +++ b/docs/en/tutorials/extra-lazy-associations.rst @@ -40,7 +40,7 @@ easily using a combination of ``count`` and ``slice``. ``removeElement`` directly issued DELETE queries to the database from version 2.4.0 to 2.7.0. This circumvents the flush operation and might run outside a transactional boundary if you don't create one yourself. We - consider this a critical bug in the assumptio of how the ORM works and + consider this a critical bug in the assumption of how the ORM works and reverted ``removeElement`` EXTRA_LAZY behavior in 2.7.1. From 6414ad4cbb898e4ae027a1a0de48b31984002dea Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Mon, 6 Dec 2021 00:55:01 +0100 Subject: [PATCH 06/12] Merge pull request #9210 from alexander-schranz/patch-2 Fix making columns optional in indexes xml schema as they can be defined via fields now --- doctrine-mapping.xsd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doctrine-mapping.xsd b/doctrine-mapping.xsd index 30f30ce217d..4fb7249d277 100644 --- a/doctrine-mapping.xsd +++ b/doctrine-mapping.xsd @@ -353,7 +353,7 @@ - + From 92434f91c72912fdf88336538cc17f7b3d4dfac0 Mon Sep 17 00:00:00 2001 From: Kevin van Sonsbeek Date: Wed, 8 Dec 2021 23:31:52 +0100 Subject: [PATCH 07/12] Added psalm param to abstract addFilterConstraint (#9229) --- lib/Doctrine/ORM/Query/Filter/SQLFilter.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php index 2e02ac7692c..7ebc2169d41 100644 --- a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php +++ b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php @@ -195,6 +195,7 @@ final protected function getConnection(): Connection * Gets the SQL query part to add to a query. * * @param string $targetTableAlias + * @psalm-param ClassMetadata $targetEntity * * @return string The constraint SQL if there is available, empty string otherwise. */ From 0b0c3e7e5874f4d6f95a08dc995f97be5afa449b Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Thu, 9 Dec 2021 12:00:30 +0100 Subject: [PATCH 08/12] Update docs/en/reference/events.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Grégoire Paris --- docs/en/reference/events.rst | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/en/reference/events.rst b/docs/en/reference/events.rst index d393b7fed06..139f074878d 100644 --- a/docs/en/reference/events.rst +++ b/docs/en/reference/events.rst @@ -1079,11 +1079,11 @@ and the EntityManager. } } -.. _LifecycleEventArgs: https://github.com/doctrine/orm/blob/2.10.x/lib/Doctrine/ORM/Event/LifecycleEventArgs.php -.. _PreUpdateEventArgs: https://github.com/doctrine/orm/blob/2.10.x/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php -.. _PreFlushEventArgs: https://github.com/doctrine/orm/blob/2.10.x/lib/Doctrine/ORM/Event/PreFlushEventArgs.php -.. _PostFlushEventArgs: https://github.com/doctrine/orm/blob/2.10.x/lib/Doctrine/ORM/Event/PostFlushEventArgs.php -.. _OnFlushEventArgs: https://github.com/doctrine/orm/blob/2.10.x/lib/Doctrine/ORM/Event/OnFlushEventArgs.php -.. _OnClearEventArgs: https://github.com/doctrine/orm/blob/2.10.x/lib/Doctrine/ORM/Event/OnClearEventArgs.php -.. _LoadClassMetadataEventArgs: https://github.com/doctrine/orm/blob/2.10.x/lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php -.. _OnClassMetadataNotFoundEventArgs: https://github.com/doctrine/orm/blob/2.10.x/lib/Doctrine/ORM/Event/OnClassMetadataNotFoundEventArgs.php +.. _LifecycleEventArgs: https://github.com/doctrine/orm/blob/HEAD/lib/Doctrine/ORM/Event/LifecycleEventArgs.php +.. _PreUpdateEventArgs: https://github.com/doctrine/orm/blob/HEAD/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php +.. _PreFlushEventArgs: https://github.com/doctrine/orm/blob/HEAD/lib/Doctrine/ORM/Event/PreFlushEventArgs.php +.. _PostFlushEventArgs: https://github.com/doctrine/orm/blob/HEAD/lib/Doctrine/ORM/Event/PostFlushEventArgs.php +.. _OnFlushEventArgs: https://github.com/doctrine/orm/blob/HEAD/lib/Doctrine/ORM/Event/OnFlushEventArgs.php +.. _OnClearEventArgs: https://github.com/doctrine/orm/blob/HEAD/lib/Doctrine/ORM/Event/OnClearEventArgs.php +.. _LoadClassMetadataEventArgs: https://github.com/doctrine/orm/blob/HEAD/lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php +.. _OnClassMetadataNotFoundEventArgs: https://github.com/doctrine/orm/blob/HEAD/lib/Doctrine/ORM/Event/OnClassMetadataNotFoundEventArgs.php From 68fa55f31087552584546d6e77832bcd8f39fb92 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sat, 11 Dec 2021 17:11:34 +0100 Subject: [PATCH 09/12] Remove fallbacks for old doctrine/annotations version (#9235) --- tests/Doctrine/Tests/OrmTestCase.php | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/tests/Doctrine/Tests/OrmTestCase.php b/tests/Doctrine/Tests/OrmTestCase.php index d25c40d754d..1b1bdd818d1 100644 --- a/tests/Doctrine/Tests/OrmTestCase.php +++ b/tests/Doctrine/Tests/OrmTestCase.php @@ -58,23 +58,12 @@ abstract class OrmTestCase extends DoctrineTestCase /** @var Cache|null */ protected $secondLevelCacheDriverImpl = null; - /** - * @param mixed $alias - */ - protected function createAnnotationDriver(array $paths = [], $alias = null): AnnotationDriver + protected function createAnnotationDriver(array $paths = []): AnnotationDriver { - // Register the ORM Annotations in the AnnotationRegistry - $reader = new Annotations\AnnotationReader(); - - if (class_exists(Annotations\PsrCachedReader::class)) { - $reader = new Annotations\PsrCachedReader($reader, new ArrayAdapter()); - } else { - $reader = new Annotations\CachedReader($reader, DoctrineProvider::wrap(new ArrayAdapter())); - } - - Annotations\AnnotationRegistry::registerFile(__DIR__ . '/../../../lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'); - - return new AnnotationDriver($reader, (array) $paths); + return new AnnotationDriver( + new Annotations\PsrCachedReader(new Annotations\AnnotationReader(), new ArrayAdapter()), + $paths + ); } /** From 42195060e6d2ecca4bb1ccaa353bec7679a14759 Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Sun, 12 Dec 2021 13:42:07 +0100 Subject: [PATCH 10/12] Add SchemaIgnoreClasses property for #8195. (#9202) Co-authored-by: Simon Podlipsky Co-authored-by: Iab Foulds --- docs/en/reference/advanced-configuration.rst | 13 +++++++++ lib/Doctrine/ORM/Configuration.php | 20 +++++++++++++ lib/Doctrine/ORM/Tools/SchemaTool.php | 3 +- .../Tests/ORM/Tools/SchemaToolTest.php | 28 +++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/docs/en/reference/advanced-configuration.rst b/docs/en/reference/advanced-configuration.rst index 8e8442af98b..7502520f017 100644 --- a/docs/en/reference/advanced-configuration.rst +++ b/docs/en/reference/advanced-configuration.rst @@ -440,6 +440,19 @@ That will be available for all entities without a custom repository class. The default value is ``Doctrine\ORM\EntityRepository``. Any repository class must be a subclass of EntityRepository otherwise you got an ORMException +Ignoring entities (***OPTIONAL***) +----------------------------------- + +Specifies the Entity FQCNs to ignore. +SchemaTool will then skip these (e.g. when comparing schemas). + +.. code-block:: php + + setSchemaIgnoreClasses([$fqcn]); + $config->getSchemaIgnoreClasses(); + + Setting up the Console ---------------------- diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index 1c453de332d..a59400cf0b2 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -1012,4 +1012,24 @@ public function setDefaultQueryHint($name, $value) { $this->_attributes['defaultQueryHints'][$name] = $value; } + + /** + * Gets a list of entity class names to be ignored by the SchemaTool + * + * @return list + */ + public function getSchemaIgnoreClasses(): array + { + return $this->_attributes['schemaIgnoreClasses'] ?? []; + } + + /** + * Sets a list of entity class names to be ignored by the SchemaTool + * + * @param list $schemaIgnoreClasses List of entity class names + */ + public function setSchemaIgnoreClasses(array $schemaIgnoreClasses): void + { + $this->_attributes['schemaIgnoreClasses'] = $schemaIgnoreClasses; + } } diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 490ef817484..58e2366ae9d 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -129,7 +129,8 @@ private function processingNotRequired( return isset($processedClasses[$class->name]) || $class->isMappedSuperclass || $class->isEmbeddedClass || - ($class->isInheritanceTypeSingleTable() && $class->name !== $class->rootEntityName); + ($class->isInheritanceTypeSingleTable() && $class->name !== $class->rootEntityName) || + in_array($class->name, $this->em->getConfiguration()->getSchemaIgnoreClasses()); } /** diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php index 766af976a2c..5faa3146ece 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php @@ -338,6 +338,34 @@ public function testIncorrectUniqueConstraintsBasedOnFields(): void $this->expectException(MappingException::class); $schemaTool->getSchemaFromMetadata([$class]); } + + /** + * @group schema-configuration + */ + public function testConfigurationSchemaIgnoredEntity(): void + { + $em = $this->getTestEntityManager(); + $schemaTool = new SchemaTool($em); + + $classes = [ + $em->getClassMetadata(FirstEntity::class), + $em->getClassMetadata(SecondEntity::class), + ]; + + $schema = $schemaTool->getSchemaFromMetadata($classes); + + self::assertTrue($schema->hasTable('first_entity'), 'Table first_entity should exist.'); + self::assertTrue($schema->hasTable('second_entity'), 'Table second_entity should exist.'); + + $em->getConfiguration()->setSchemaIgnoreClasses([ + SecondEntity::class, + ]); + + $schema = $schemaTool->getSchemaFromMetadata($classes); + + self::assertTrue($schema->hasTable('first_entity'), 'Table first_entity should exist.'); + self::assertFalse($schema->hasTable('second_entity'), 'Table second_entity should not exist.'); + } } /** From 12a70bbefbb2c24c5ca2aa14338a36fe70d9cae3 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 13 Dec 2021 21:28:56 +0100 Subject: [PATCH 11/12] PHPCS 3.6.2, Psalm 4.15.0 (#9247) --- composer.json | 4 ++-- psalm-baseline.xml | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index abd30bf43bd..9d77d78b2ad 100644 --- a/composer.json +++ b/composer.json @@ -41,10 +41,10 @@ "phpbench/phpbench": "^0.16.10 || ^1.0", "phpstan/phpstan": "1.2.0", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.4", - "squizlabs/php_codesniffer": "3.6.1", + "squizlabs/php_codesniffer": "3.6.2", "symfony/cache": "^4.4 || ^5.2", "symfony/yaml": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "vimeo/psalm": "4.13.1" + "vimeo/psalm": "4.15.0" }, "conflict": { "doctrine/annotations": "<1.13 || >= 2.0" diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 1d53071d242..b691d93cae5 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + IterableResult @@ -1043,6 +1043,9 @@ $this->table $this->table + + array_values + $className !== null $mapping !== false From 003090b70c0905ddd327e1ce2757f53a57e13d30 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 13 Dec 2021 23:36:10 +0100 Subject: [PATCH 12/12] Deprecate Setup::registerAutoloadDirectory() (#9249) --- UPGRADE.md | 4 ++++ lib/Doctrine/ORM/Tools/Setup.php | 2 ++ 2 files changed, 6 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index ca5235e857a..dd4aa66f901 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,9 @@ # Upgrade to 2.11 +## Deprecated: `Setup::registerAutoloadDirectory()` + +Use Composer's autoloader instead. + ## Deprecated: `AbstractHydrator::hydrateRow()` Following the deprecation of the method `AbstractHydrator::iterate()`, the diff --git a/lib/Doctrine/ORM/Tools/Setup.php b/lib/Doctrine/ORM/Tools/Setup.php index e7ed759bb12..f6c09f60825 100644 --- a/lib/Doctrine/ORM/Tools/Setup.php +++ b/lib/Doctrine/ORM/Tools/Setup.php @@ -40,6 +40,8 @@ class Setup * Use this method to register all autoloads for a downloaded Doctrine library. * Pick the directory the library was uncompressed into. * + * @deprecated Use Composer's autoloader instead. + * * @param string $directory * * @return void