-
-
Notifications
You must be signed in to change notification settings - Fork 587
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not use property metadata to get/set object values #934
Conversation
|
||
public function getValue(object $object, PropertyMetadata $metadata) | ||
{ | ||
return $metadata->getValue($object); | ||
if ($metadata instanceof StaticPropertyMetadata) { |
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.
Nice. This bunch of IFs calls for a strategy pattern imho, this is a bit too coupled.
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.
this has to be fast! very fast! 🤔
not sure if having extra classes to load and call will influence on it
|
||
/** | ||
* @author Asmir Mustafic <[email protected]> | ||
*/ | ||
final class DefaultAccessorStrategy implements AccessorStrategyInterface | ||
{ | ||
private $readAccessors = array(); | ||
private $writeAccessors = array(); |
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.
Inho one shared accessor is enough, no? They are bound to type only.
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.
The body of the closure is different,
function ($o, $name, $value) {
$o->$name = $value;
}
vs
function ($o, $name) {
return $o->$name;
}
so cant be done
As an experiment (perf), you could also try closures bound to specific object instances and/or properties. |
Can you explain? |
Right now you are using unbound accessors (2nd argument to Closure::bind() is null) so you have to pass around |
Btw this needs some test cases for inheritance with private properties: with different names, with same names (but different serialized names) and so. |
But if i do it per object is much slower... creating the closure takes a lot apparently. |
The whole testsuite is using this access strategy, so should work, no? |
Not sure. Your accessor is bound to specific class name which is crucial for private properties. class Foo
{
/** @Serializer\SerializedName("foo") */
private $a;
}
class Bar extends Foo
{
/** @Serializer\SerializedName("bar") */
private $a;
} Will that work when |
#935 proves that does not work :) |
first draft of what could be a solution for #932. To get some extra memory improvements, even
jms/metadata
should be updated (removing the reflection stuff from property metadata)