Doctrine ORM
Behaviors on Doctrine ORM 3.6+ entities: entity discovery with WovenEntityClassLocator and intercepted properties with native lazy objects.
Doctrine ORM (3.6+) maps a compiled entity as it is. The compiled class keeps its name and all mapping attributes, and the original class body lives in a trait that Doctrine never maps. You configure two things. In Symfony, the bundle does both for you (see Symfony).
Entity discovery
Section titled “Entity discovery”use Doctrine\ORM\Mapping\Driver\AttributeDriver;use Go\Bridge\Doctrine\WovenEntityClassLocator;
$configuration->setMetadataDriverImpl( new AttributeDriver(WovenEntityClassLocator::createFromDirectories([__DIR__ . '/src/Entity'])),);Given plain directories, Doctrine includes the entity source files directly. That bypasses the compiler, so the entity loses its behaviors, and Doctrine misses entities that the autoloader has already loaded. WovenEntityClassLocator reads the class names from the source files and loads each class through the autoloader, which serves the compiled version.
Intercepted properties and native lazy objects
Section titled “Intercepted properties and native lazy objects”use Doctrine\ORM\Events;use Go\Bridge\Doctrine\MetadataLoadInterceptor;
$configuration->enableNativeLazyObjects(true);$eventManager->addEventListener(Events::loadClassMetadata, new MetadataLoadInterceptor());An intercepted property is re-declared with native property hooks, and Doctrine supports those only with native lazy objects. Enable them. Registering MetadataLoadInterceptor is optional: when native lazy objects are off, it reports a compiled entity with intercepted mapped properties at metadata load time, instead of failing on the first lazy proxy.
Doctrine reads and writes the raw property values while hydrating and flushing. Behaviors on properties therefore run only for accesses made by your own code, never for Doctrine’s internal ones.
© 2026 Alexander Lisachenko
