Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[PropertyAccess][PropertyInfo] customize behavior for property hooks on read and write#59246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:7.4
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
c4ef85d
to399efcf
Comparepublic bool $virtualSetHookOnly { set=> $value; } | ||
public bool $virtualHook { get => true; set=> $value; } | ||
public bool $virtualSetHookOnly { set(bool $value) { } } | ||
public bool $virtualHook { get => true; set(bool $value) { } } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I updated this fixtures because PHP does not report these properties as Virtual, seereproducer
0900ef7
to379e96c
CompareTests are failing on 8.2 / highest deps because of other components (Bridge\twig, Bundle\FrameworkBundle, Component\HttpKernel). It leaves us with psalm for which PHP 8.4 support can be tracked here:vimeo/psalm#11107. Not sure how to deal with it here. |
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
a396856
to73f2e3f
Compare@mtarld Thanks for your feedback, I think everything is covered now :) |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
bd1f4a1
to0c5bb13
CompareUh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
0c5bb13
to0eaa1d4
CompareThanks@mtarld for your previous review, sorry I took so long to make the changes. |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
0eaa1d4
to0d100a9
Compare@OskarStark thanks for your feedback, I renamed the variables. |
Hi@mtarld do you think we might be good on this pull request ? Thanks ! 🙏 |
Uh oh!
There was an error while loading.Please reload this page.
OskarStark commentedApr 1, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Would it be sufficient to split those PR into two separate feature PRs? |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
if ($hasProperty &&(($r = $reflClass->getProperty($property))->getModifiers() & $this->propertyReflectionFlags)) { | ||
return new PropertyReadInfo(PropertyReadInfo::TYPE_PROPERTY, $property,$this->getReadVisibilityForProperty($r), $r->isStatic(), true, $this->propertyHasHook($r, 'get'), $this->propertyIsVirtual($r)); | ||
} | ||
if ($hasProperty &&(($r = $reflClass->getProperty($property))->getModifiers() & $this->propertyReflectionFlags)) { | ||
return new PropertyReadInfo(PropertyReadInfo::TYPE_PROPERTY, $property,$this->getReadVisibilityForProperty($r),$r->isStatic(),true); | ||
if ($allowMagicGet &&$reflClass->hasMethod('__get') && (($r = $reflClass->getMethod('__get'))->getModifiers() & $this->methodReflectionFlags)) { | ||
return new PropertyReadInfo(PropertyReadInfo::TYPE_PROPERTY, $property,PropertyReadInfo::VISIBILITY_PUBLIC, false,$r->returnsReference(),false, false); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Why theseif
s has been inverted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
See that comment#59246 (comment)
0d100a9
to3990cad
Compare@mtarld thanks for the feedback |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'm not sure I like this new feature of PropertyAccess. Until now, PropertyAccess never accesses the internal state of the object through Reflection (Reflection is used only for instrospection of the class structure). All reads and writes are done through the public API of the class until now.
@@ -77,19 +82,24 @@ class PropertyAccessor implements PropertyAccessorInterface | |||
* or self::DISALLOW_MAGIC_METHODS for none | |||
* @param int $throw A bitwise combination of the THROW_* constants | |||
* to specify when exceptions should be thrown | |||
* @param int $bypassPropertyHooks A bitwise combination of the BYPASS_PROPERTY_HOOK_* constants |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@param int-mask-of<self::BYPASS_PROPERTY_HOOK_*> $bypassPropertyHooks
so that static analysis tool know about the precise type and can report invalid usages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
thx, didn't know that syntax
@@ -47,6 +47,10 @@ class PropertyAccessor implements PropertyAccessorInterface | |||
/** @var int Allow magic __call methods */ | |||
public const MAGIC_CALL = ReflectionExtractor::ALLOW_MAGIC_CALL; | |||
public const BYPASS_PROPERTY_HOOK_NONE = 0; | |||
public const BYPASS_PROPERTY_HOOK_READ = 1 << 1; | |||
public const BYPASS_PROPERTY_HOOK_WRITE = 1 << 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
constants for a bit mask are generally defined in increasing order (so that new cases are added at the end of the list). This reverse order is unusual to me
3990cad
to7963304
Compare…ty hooks on read and write
7963304
toe4901fb
Compare@stof I thought it would be very relevant in this component as this follows new opportunities offered by the language, wdyt ? |
Uh oh!
There was an error while loading.Please reload this page.
This pull requests adds 2 new (tiny) features:
Have a nice day!