Skip to content

Decide the Metadata entity mapping at compile time - #25

Merged
loevgaard merged 1 commit into
2.xfrom
compile-time-metadata-mapping
Nov 23, 2026
Merged

loevgaard merged 1 commit into
2.xfrom
compile-time-metadata-mapping

Conversation

@loevgaard

Copy link
Copy Markdown
Member

Summary

Whether the bundle's Metadata is an entity is now decided once, when the container compiles. Before, it was decided at runtime by a Doctrine listener.

 SetonoClientExtension::load()
-  if metadata_class extends Metadata
-    remove ConvertToEntityListener
+  if metadata_class is Metadata
+    set setono_client.doctrine_mapping.entity
+  else
+    set setono_client.doctrine_mapping.mapped_superclass

 Doctrine loads Metadata
-  XML mapping: mapped superclass
-  ConvertToEntityListener on loadClassMetadata: flip it to an entity, unless the extension removed it
+  XML mapping of the one enabled pass: entity/ or mapped-superclass/
 config/doctrine-mapping/
-└── Metadata.orm.xml                      # mapped superclass
+├── entity/Metadata.orm.xml               # table setono_client__metadata
+└── mapped-superclass/Metadata.orm.xml    # fields only, no table
 src/
-└── EventListener/Doctrine/ConvertToEntityListener.php
metadata_class Bundle's Metadata setono_client__metadata in the schema
Metadata (default) entity yes
extends Metadata mapped superclass no
only implements MetadataInterface mapped superclass (was: entity) no (was: yes)

DoctrineOrmMappingsPass checks only that its parameter exists, not the parameter's value. Its unit test compiles a container and loads the mapping through Doctrine's driver chain. A new interface_only_metadata test environment runs all of MetadataTest with an entity that only implements the interface.

Closes #22

Evidence

  • Before: in the new interface_only_metadata environment

    InterfaceOnlyMetadataClassTest::it_maps_the_bundles_metadata_as_a_mapped_superclass
      Failed asserting that false is true.
    InterfaceOnlyMetadataClassTest::it_leaves_the_bundles_table_out_of_the_schema
      Failed asserting that true is false.   # setono_client__metadata was in the schema
    

    Infection ignored one equivalent mutant (instanceof ClassMetadata in the listener).

    After: OK (135 tests, 923 assertions). Infection: 107 mutants, 107 killed, 0 ignored, MSI 100%. PHPStan, ECS and composer-dependency-analyser pass. The CI "lowest" job also passes locally (PHP 8.1, Symfony 6.4.0, DoctrineBundle 2.11.3, ORM 3.1.0, DBAL 3.8.2).

Merge Danger

Door: two-way

2.x is unreleased, so reverting this PR restores the listener with no migration.

Blast Radius: schema

An application whose metadata_class only implements MetadataInterface no longer gets setono_client__metadata from the bundle. Its next doctrine:migrations:diff drops that table. With a custom metadata class configured, the bundle never wrote to it. UPGRADE-2.0.md covers this and the removed ConvertToEntityListener and its service. composer-dependency-analyser.php now ignores doctrine/orm as "prod dependency only in dev": src/ no longer imports an ORM class, but the XML mapping and the entity manager still need it at runtime.

The bundle registers two XML mappings of its Metadata class, an entity and a
mapped superclass, each with its own DoctrineOrmMappingsPass enabled by a
parameter. SetonoClientExtension sets exactly one: the entity mapping when
Metadata is the configured metadata_class, the mapped superclass for any other
class. ConvertToEntityListener, its service, its test and its Infection
exclusion are gone.

A metadata_class that only implements MetadataInterface no longer leaves the
unused setono_client__metadata table in the schema. The new
interface_only_metadata test environment runs MetadataTest against such a class.

Closes #22
@loevgaard
loevgaard merged commit 857bc5b into 2.x Nov 23, 2026
19 checks passed
@loevgaard
loevgaard deleted the compile-time-metadata-mapping branch November 23, 2026 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decide the Metadata entity mapping at compile time

1 participant