PHP Classes

File: CHANGELOG.md

Recommend this page to a friend!
  Packages of ?????? ???????   Adaptive Entity Manager   CHANGELOG.md   Download  
File: CHANGELOG.md
Role: Auxiliary data
Content type: text/markdown
Description: Auxiliary data
Class: Adaptive Entity Manager
Entity manager to work with multiple data sources
Author: By
Last change:
Date: 3 months ago
Size: 18,021 bytes
 

 

Contents

Class file image Download

Changelog

All notable changes to the Adaptive Entity Manager package will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[Unreleased]

[1.6.0] - 2026-05-03

Added

  • Map domain value objects without `ValueObjectInterface` using field metadata options: `class` (preferred) or `valueObjectClass`, `from` (static factory, one argument), and `to` (instance method with no required parameters). When `to` is omitted, `Stringable` is used only for `value_object` fields whose runtime value matches the declared property class.
  • `ValueObjectAwareEntityManagerInterface` (extends `EntityManagerInterface`) exposes `getValueObjectRegistry()` and `hasValueObjectSupport()` so third-party `EntityManagerInterface` implementations are not forced to add VO methods.
  • `EntityPersister` converts `value_object` criteria values that are objects via the same rules as persistence (e.g. `loadAll(['email' => $emailVo])`). The object must match the field?s declared value object class (same as for flush).
  • Runnable example: `examples/ddd_domain_vo_demo.php` with a domain type that does not implement `ValueObjectInterface` (dev autoload namespace `Examples\Ddd\`).

Changed

  • `ValueObjectAwareEntityFactory` hydrates and extracts using the above metadata; static factories must return an instance of the property?s declared class.
  • API: `getValueObjectRegistry()` and `hasValueObjectSupport()` were removed from `EntityManagerInterface`; use `ValueObjectAwareEntityManagerInterface` (implemented by `AdaptiveEntityManager`) where you need those calls.
  • If both metadata keys `class` and `valueObjectClass` are set to different FQCNs, configuration is rejected.
  • Non-`ValueObjectInterface` storage conversion validates the runtime value against the property type before invoking metadata `to` (closes criteria / `convertFieldValueToStorage` holes).

Fixed

  • If the first persister in a process was created without VO support, a later `EntityManager` with VO support now replaces the shared entity factory so hydration and extraction use `ValueObjectAwareEntityFactory`.

Known limitations

  • `EntityPersister` shares one static `EntityFactory` per PHP process. Multiple distinct `AdaptiveEntityManager` instances with different configs/registries are not fully isolated: use a single logical `EntityManager` per process, or accept that the shared factory is tied to whichever persister initialized or last upgraded it.

[1.5.0] - 2026-05-02

Added

  • Add CI matrix for PHP 8.1, 8.2, 8.3, and 8.4.
  • Add CI status badge to README.
  • Add PHPStan (level 5) with PHPUnit extension, baseline quality gate, and `composer analyse` / `composer check` scripts.
  • Add targeted tests: flush rollback on insert failure, commit event dispatch order, preFlush lifecycle, flush path with default optimized metadata, `loadAll` criteria (field-to-column and boolean source values), `PersistentCollection` lazy init, EntityManager proxy initialization helpers.
  • Add English documentation roadmap/RFC updates.

Changed

  • Make nullable parameters explicit for PHP 8.4 readiness.
  • Refresh documentation positioning around DBAL, legacy databases, and hexagonal architecture.

[1.4.0] - 2025-10-31

Added

Boolean Value Mapping

  • Bidirectional mapping for boolean fields with non-standard source representations (e.g., `Y|N`, `0|1`, `T|F`)
  • values option in metadata/YAML configuration to map source values to PHP boolean
  • Automatic conversion in both directions: - Inbound (row ? object): Source values (e.g., `'Y'`, `'N'`) automatically convert to PHP `bool` during hydration - Outbound (object ? row): PHP boolean values convert back to configured source representation during persistence - Criteria mapping: Boolean criteria values in repository queries are mapped to source values before adapter calls
  • Case-insensitive matching: String keys in `values` are matched case-insensitively with exact match taking precedence
  • Metadata extension: Added `getFieldOption()` method to `ClassMetadata` interface and `AbstractClassMetadata` for accessing arbitrary field options

Technical Details

  • Added `getFieldOption(string $fieldName, string $optionKey): mixed` to `ClassMetadata` interface
  • Implemented `getFieldOption()` in `AbstractClassMetadata` to access field metadata options
  • Added `applyBooleanMapIfNeeded()` method in `ValueObjectAwareEntityFactory` for inbound value mapping
  • Added `mapBooleanValueToSource()` method in `ValueObjectAwareEntityFactory` for outbound value mapping
  • Added `mapCriteriaBooleanValue()` method in `EntityPersister` for criteria value conversion
  • Integrated boolean mapping into `fillEntity()`, `setIdentifierValue()`, and `getEntityDataRow()` methods

Benefits

  • Flexible data sources: Works seamlessly with legacy databases using non-standard boolean representations
  • Type safety: Maintains PHP boolean type in entities while supporting various source formats
  • Transparent conversion: Automatic bidirectional mapping without manual conversion code
  • Query support: Criteria queries automatically use source values, ensuring correct filtering

Compatibility

  • 100% Backward Compatible: If `values` is not specified, behavior remains unchanged
  • No breaking changes: All existing code continues to work without modifications

[1.3.2] - 2025-06-30

Changed

  • Entity Instantiation: Modified `EntityFactory::makeEntity()` to use `ReflectionClass::newInstanceWithoutConstructor()` instead of calling entity constructors directly
  • Doctrine-like Behavior: EntityFactory now creates entities without invoking constructors during hydration, matching Doctrine ORM behavior
  • Constructor Safety: Prevents potential issues with entities that have constructors requiring parameters or containing business logic

Technical Details

  • Replaced `new ($classMetadata->getName())()` with `$reflectionClass->newInstanceWithoutConstructor()` in `EntityFactory::makeEntity()`
  • This change ensures entity constructors are not called during database hydration process
  • Maintains compatibility with existing code while providing safer entity instantiation
  • `ValueObjectAwareEntityFactory` inherits this improvement automatically

Benefits

  • Safer hydration: No unexpected constructor execution during entity creation from database
  • Better compatibility: Aligns with Doctrine ORM's entity instantiation approach
  • Reduced errors: Prevents constructor-related errors during entity hydration

[1.3.1] - 2025-06-18

Fixed

  • DateTime Immutable Support: Added support for `datetime_immutable` field type in `FieldTypeEnum::normalizeType()`
  • Enhanced DateTime Conversion: Implemented automatic string-to-DateTime conversion in `ValueObjectAwareEntityFactory`
  • Flexible Identifier Handling: Improved `loadById()` method to handle various identifier formats (`['id' => 1]`, `[1]`, `['ID' => 1]`)
  • Type Safety: Enhanced type validation and conversion for DateTime types (`DateTime`, `DateTimeImmutable`, `DateTimeInterface`)

Technical Details

  • Extended `FieldTypeEnum::normalizeType()` to map `'datetime_immutable'` and `'datetimeimmutable'` to `DateTime` type
  • Added `convertStandardType()` method in `ValueObjectAwareEntityFactory` for automatic DateTime conversion
  • Improved identifier resolution in data adapters to support multiple identifier key formats
  • Enhanced type compatibility checking between entity properties and field metadata

Compatibility

  • 100% Backward Compatible: All existing code continues to work without changes
  • Enhanced Type Support: Better handling of modern PHP DateTime types
  • Improved Robustness: More flexible identifier and type handling

[1.3.0] - 2024-06-18

Added

? ValueObject Support

  • Complete ValueObject system with `ValueObjectInterface` and `AbstractValueObject` base class
  • Built-in ValueObjects: - `Email` - Email validation with domain/local part extraction - `Money` - Currency-aware monetary values with arithmetic operations - `UserId` - Type-safe user identifiers with validation
  • Converter System: - `ValueObjectConverterInterface` for custom conversions - `DefaultValueObjectConverter` with automatic primitive conversion - `ValueObjectConverterRegistry` for managing multiple converters
  • Framework Integration: - Extended `FieldTypeEnum` with `ValueObject` type - `ValueObjectAwareEntityFactory` for automatic conversion during hydration - Enhanced `AdaptiveEntityManager` with optional `ValueObjectConverterRegistry` - Updated `EntityPersister` with ValueObject-aware persistence

? Core Enhancements

  • New Field Type: Added `FieldTypeEnum::ValueObject` for ValueObject fields
  • Enhanced Entity Factory: ValueObject-aware entity creation and hydration
  • Improved Entity Manager: Optional ValueObject support with registry parameter
  • Automatic Conversion: Seamless primitive ? ValueObject conversion during persistence

? Documentation & Examples

  • Complete Documentation: `docs/VALUE_OBJECTS.md` with usage examples
  • Demo Script: `examples/value_objects_demo.php` showcasing all features
  • Integration Tests: Comprehensive test suite with 80+ tests
  • Updated README: ValueObject examples and usage patterns

Enhanced

? Performance & Reliability

  • Runtime Caching: Optimized ValueObject conversion with caching
  • Type Safety: Full PHP type checking for ValueObjects
  • Validation: Built-in validation for all ValueObject types
  • Immutability: ValueObjects are immutable by design

? Backward Compatibility

  • 100% Backward Compatible: Existing code works without changes
  • Optional Feature: ValueObject support is opt-in
  • Graceful Degradation: Works with or without ValueObject registry

Technical Details

Architecture

  • Registry Pattern: Centralized ValueObject converter management
  • Factory Pattern: Enhanced entity factories with ValueObject support
  • Strategy Pattern: Pluggable converter system for custom ValueObjects

Database Integration

  • Transparent Persistence: ValueObjects serialize to primitives automatically
  • Schema Compatibility: No database schema changes required
  • Type Mapping: Automatic type conversion during hydration/persistence

Testing

  • Comprehensive Coverage: 80+ tests covering all ValueObject functionality
  • Integration Tests: Real-world usage scenarios
  • Validation Tests: Error handling and edge cases
  • Performance Tests: Conversion efficiency verification

Examples

// Using built-in Email ValueObject
$user = new User();
$user->setEmail(new Email('user@example.com'));

// Automatic conversion during persistence
$entityManager->persist($user);  // Email converts to string
$entityManager->flush();

// Automatic conversion during hydration
$loadedUser = $entityManager->find(User::class, 1);
$email = $loadedUser->getEmail();  // Returns Email ValueObject
echo $email->getDomain();  // "example.com"

Migration Guide

For existing projects wanting to use ValueObjects:

  1. Add ValueObject Registry to Entity Manager:
    $registry = new ValueObjectConverterRegistry();
    $entityManager = new AdaptiveEntityManager($config, $metadata, $dataAdapter, valueObjectRegistry: $registry);
    
  2. Update Entity Metadata to specify ValueObject fields:
    $metadata->addField('email', FieldTypeEnum::ValueObject, Email::class);
    
  3. Update Entity Properties to use ValueObject types:
    private ?Email $email = null;
    

Dependencies

  • No new required dependencies
  • Enhanced PSR-6 cache support for metadata caching
  • Compatible with existing Doctrine persistence interfaces

[1.2.1] - 2025-01-17

Fixed

  • DateTimeInterface Type Support: Added support for `DateTimeInterface` typed properties in entities
  • Enhanced Type Comparison: Fixed EntityFactory type comparison logic to properly normalize both property and field types
  • PHP 8.1+ Compatibility: Resolved compatibility issue with modern PHP typed properties using `DateTimeInterface`

Technical Details

  • Extended `FieldTypeEnum::normalizeType()` to recognize `'datetimeinterface'` as equivalent to `'datetime'`
  • Modified EntityFactory comparison logic to normalize both sides: `FieldTypeEnum::normalizeType(strtolower($propertyType->getName())) !== FieldTypeEnum::normalizeType($typeOfField)`
  • This allows entities to declare properties as `private ?DateTimeInterface $dateRegister` while using `'datetime'` type in metadata

[1.2.0] - 2025-06-16

Added

  • PSR-6 Compatible Metadata Caching System: Implemented multi-level caching for entity metadata with runtime and persistent cache layers
  • CachedEntityMetadataProvider: Decorator with cache invalidation, warm-up, and statistics
  • OptimizedEntityMetadataFactory: Replacement factory with cached entity scanning and optimized proxy generation
  • SimpleFileCache & SimpleCacheItem: Basic PSR-6 implementation as fallback when no external cache is provided
  • MetadataSystemFactory: Factory for easy setup supporting both optimized and legacy modes
  • New optional constructor parameters in `AdaptiveEntityManager`: - `?CacheItemPoolInterface $metadataCache = null` - PSR-6 cache for metadata - `bool $useOptimizedMetadata = true` - Enable/disable optimized metadata system - `EventDispatcherInterface $eventDispatcher = null` - Event dispatcher integration
  • Comprehensive test suite with 72 tests (52 unit + 14 integration + 6 metadata)
  • Documentation files: `CACHING.md` and `TESTING.md`
  • Enhanced Composer scripts: test:syntax, test:quick, cache:clear, install:dev

Changed

  • Performance improvements: Expected 50-70% faster cold start, 90-95% faster warm cache requests
  • Optimized metadata system enabled by default while maintaining full backward compatibility
  • Enhanced PHPUnit configuration with proper test suites and execution order
  • Improved test reliability with fixed SplObjectStorage handling and static property initialization

Fixed

  • Removed archive exclusions from `composer.json` - tests are now included in package distribution
  • Fixed test execution order issues that caused random failures
  • Resolved SplObjectStorage::current() issues with proper rewind() calls
  • Fixed static property initialization problems in test classes

Dependencies

  • Added `psr/cache: ^1.0 || ^2.0 || ^3.0` for metadata caching support

Breaking Changes

  • None - Full backward compatibility maintained for all existing code

[1.1.1] - 2024-06-05

Fixed

  • Corrected the dependency injection of `Psr\EventDispatcher\EventDispatcherInterface` into `UnitOfWork` via the `AdaptiveEntityManager` constructor, resolving issues with event dispatching and service instantiation.

[1.1.0] - 2025-06-05

Added

  • Implemented a universal event system using PSR-14 to allow extensibility and modularity for entity lifecycle events (Pre/Post Persist, Update, Remove).
  • Added `psr/event-dispatcher` as a required dependency.

[1.0.8] - 2025-06-05

Fixed

  • Normalized entity namespaces in `EntityMetadataFactory::getResult()` to allow configuration with or without trailing backslashes.

[1.0.7] - 2024-05-30

Changed

  • Added .gitattributes file to enforce LF line endings
  • Fixed namespace issues in test files
  • Improved test environment configuration

[1.0.6] - 2024-05-30

Fixed

  • Fixed: Corrected folder paths in Config.php to resolve issues with incorrect directory references.

[v1.0.5] - 2024-05-30

Fixed

  • Fixed paths and namespaces in tests when initializing Config objects

[v1.0.4] - 2024-05-30

Changed

  • Reorganized test structure for better maintainability
  • Moved unit tests to dedicated `tests/Unit` directory
  • Relocated mock objects to `tests/Mock` directory
  • Updated namespace declarations in test files
  • Fixed file paths in test configurations

[v1.0.3] - 2024-05-30

Added

  • Added comprehensive example of REST API data adapter implementation
  • Enhanced documentation with detailed data adapter usage examples
  • Improved data adapter configuration guide

[v1.0.2] - 2024-05-30

Added

  • Enhanced README.md with detailed metadata configuration example
  • Added comprehensive example of entity metadata implementation
  • Improved documentation for metadata management

[v1.0.1] - 2025-05-29

Fixed

  • Fixed DefaultEntityMetadataProvider implementation for proper metadata class resolution
  • Enhanced README.md with comprehensive documentation
  • Improved metadata class name resolution logic
  • Fixed namespace handling in metadata provider

Documentation

  • Added detailed installation instructions
  • Expanded usage examples
  • Added configuration documentation
  • Improved API documentation
  • Added examples for custom data adapters
  • Enhanced metadata configuration guide

[v1.0.0] - 2024-05-28

Added

  • Initial release of Adaptive Entity Manager
  • Core entity management functionality
  • Support for multiple data sources through adapters
  • Entity metadata system
  • Transaction management
  • Lazy loading through proxy objects
  • Flexible repository system
  • Unit of Work implementation
  • Entity lifecycle callbacks
  • Relationship management (One-to-One, One-to-Many)

Dependencies

  • PHP 8.1 or higher
  • doctrine/persistence: ^3.0 || ^4.0
  • laminas/laminas-code: ^4.0
  • psr/container: ^1.1 || ^2.0
  • symfony/cache: ^6.0 || ^7.0
  • symfony/string: ^6.0 || ^7.0

Support

If you discover any security-related issues, please email kabirovruslan@gmail.com instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.