benkle/doctrine-adoption
Adds a small Collector + Doctrine metadata listener to enhance inheritance mapping by “adopting” child entities into a parent with a named association. Register the loadClassMetadata listener manually (including for schema creation/CLI tools).
EventManager setup), but Laravel’s Service Container and Event System can integrate it with minimal overhead. The doctrine-adoption-bundle (Symfony-specific) is not directly applicable, but the core library can be adapted.Collector instance to define inheritance mappings.MetadataListener attached to Doctrine’s loadClassMetadata event.EntityManager setup can coexist if Doctrine ORM is explicitly added (doctrine/orm).$inherits in models. This package enables class-table inheritance or custom strategies, which Eloquent lacks.loadClassMetadata requires:
Doctrine\ORM\EventManager alongside Laravel’s event system.doctrine executable setup for table creation. In Laravel, this translates to:
where clauses on parent/child tables).MetadataListener?EntityManager setup, schema updates)? Is the team comfortable with low-level Doctrine configuration?doctrine/orm) if not already present.benkle/doctrine-adoption: Core package.doctrine/orm: For EntityManager and event system.doctrine/doctrine-bundle (optional): If using Symfony’s bundle as a reference for configuration.EntityManager with the Collector and MetadataListener.composer require benkle/doctrine-adoption doctrine/orm
EntityManager:
// app/Providers/DoctrineServiceProvider.php
use Benkle\DoctrineAdoption\Collector;
use Benkle\DoctrineAdoption\MetadataListener;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EventManager;
use Doctrine\ORM\Events;
class DoctrineServiceProvider extends ServiceProvider {
public function register() {
$collector = new Collector();
$collector->addAdoptee(ParentEntity::class, ChildEntity::class, 'child');
$eventManager = new EventManager();
$eventManager->addEventListener(Events::loadClassMetadata, new MetadataListener($collector));
$this->app->singleton(EntityManager::class, function ($app) use ($eventManager) {
return EntityManager::create($app['config']['database'], $app['config']['doctrine'], $eventManager);
});
}
}
SchemaBuilder methods).EntityManager instances).EntityManager for testing inheritance logic.MetadataListener in unit tests to isolate behavior.EntityManager with the package.Collector must be manually configured for each inheritance hierarchy, adding boilerplate.$collector->addAdoptee(Animal::class, Dog::class, 'dog');
$collector->addAdoptee(Animal::class, Cat::class, 'cat');
composer.json and test upgrades rigorously.doctrine/orm:schema-tool.MetadataListener events.How can I help you explore Laravel packages today?