doctrine/persistence
Leverage Doctrine Persistence for consistent object mapping and database interactions in PHP. Abstracts ORM logic, simplifying persistence across frameworks. Supports Doctrine ORM, DBAL, and more with unified abstractions. Ideal for scalable applications needing clean persistence patterns.
The doctrine/persistence package is not typically used directly by application developers—it’s a foundational abstraction layer consumed by higher-level libraries like doctrine/orm, doctrine/mongodb-odm, or custom object mappers. As a developer, you’ll most often interact with it indirectly when configuring or extending Doctrine ORM/ODM, or when building your own persistence layer. Start by examining the interface contracts (ObjectManager, ObjectRepository, ClassMetadata) and lifecycle event abstractions (LifecycleEventArgs, LifecycleCallback). For quick local exploration, run composer require doctrine/persistence and inspect the src/Persistence directory structure—especially Events.php, Mapping/AbstractClassMetadataFactory.php, and ObjectManagerDecorator.php.
ObjectManagerDecorator to intercept and add cross-cutting concerns (e.g., auditing, caching) around entity operations without modifying the underlying manager (e.g., EntityManager).Driver interfaces from Persistence\Mapping\Driver (e.g., XmlDriver, YamlDriver, PHPDriver) or extend AbstractFileDriver to support configuration in non-Doctrine formats (e.g., YAML in legacy systems).AbstractClassMetadataFactory as a base to implement custom metadata loading strategies (e.g., database-backed, API-driven). The new ClassLocator (4.1.0+) simplifies discovering entity classes for attribute-based drivers.LifecycleEventArgs and EventManager—often via decorators or custom ObjectManager implementations.RuntimeReflectionProperty and Proxy utilities when writing custom proxy generators or lazy-loading mechanisms.ObjectManagerAware, doctrine/cache support, and clear($className); version 4.x requires PHP 8.1+. Ensure your drivers/listeners are version-compatible—check release notes before upgrading.ClassMetadata::getReflectionClass() instead of new \ReflectionClass() for robustness.ObjectRepository’s template parameter is covariant—be precise with return types in custom repository implementations to avoid PHPStan/Psalm errors.EnumReflectionProperty, setValue()), but ensure you’re on ≥3.3.0 to use array-of-enums and enum arguments reliably.doctrine/cache separately). If writing a driver, always check isTransient() before attempting to load metadata.ObjectManagerDecorator or ObjectRepositoryDecorator as test doubles to stub only the methods you need—don’t mock the entire ObjectManager.How can I help you explore Laravel packages today?