Feat: add PHP 8.4 lazy ghost mapper + fix asymmetric visibility in ClassPropertiesExtractor#552
Open
Shelamkoff wants to merge 8 commits intocycle:2.xfrom
Open
Feat: add PHP 8.4 lazy ghost mapper + fix asymmetric visibility in ClassPropertiesExtractor#552Shelamkoff wants to merge 8 commits intocycle:2.xfrom
Shelamkoff wants to merge 8 commits intocycle:2.xfrom
Conversation
Enhance visibility check for properties to account for restricted setters.
Implement LazyGhostEntityFactory for PHP 8.4 compatibility.
This class serves as a drop-in replacement for the Mapper, utilizing PHP 8.4 lazy ghost objects for entity creation and hydration.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #551 — Cycle ORM v2 incompatible with PHP 8.4 asymmetric visibility.
This PR adds two fixes:
Hot-fix:
ClassPropertiesExtractormisclassifiesprivate(set)/protected(set)properties asPUBLIC_CLASSbecauseisPublic()returnstruefor the read visibility.ClosureHydratorthen skipsClosure::bind()and the fallback@$entity->$prop = $valuesilently fails. The fix checksisPrivateSet()/isProtectedSet()(PHP 8.4) before classifying.Lazy ghost mapper:
LazyGhostMapper+LazyGhostEntityFactory— a drop-in alternative toMapper+ProxyEntityFactoryusing PHP 8.4 nativeReflectionClass::newLazyGhost(). Solves the asymmetric visibility bug,finalclass limitation, and(array)cast issues withprivate(set)property names.Changes
Bug fix:
ClassPropertiesExtractorNew files
src/Mapper/LazyGhost/LazyGhostEntityFactory.phpnewLazyGhost(),setRawValueWithoutLazyInitialization(),WeakMapfor pending refssrc/Mapper/LazyGhostMapper.phpLazyGhostEntityFactory(same structure asMapper)Usage
Why lazy ghosts over proxies
private(set)hydrationisPublic()misclassifies → silent failuresetRawValueWithoutLazyInitialization()bypasses all visibilityfinalclasseseval()subclass → RuntimeException(array)cast manglesprivate(set)namesReflectionProperty::getValue()get_class()Test plan
ClassPropertiesExtractorTest— 5 tests:public,private(set),protected(set),privateproperties + relation with asymmetric visibilityLazyGhostEntityFactoryTest— 16 tests: create, upgrade, extractData, extractRelations, extractAll, lazy initializer resolution