-
-
Notifications
You must be signed in to change notification settings - Fork 356
[LiveComponent] LiveComponentHydrator
doesn't handle interfaces
#1590
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
Comments
LiveComponentHydrator
bug with interfacesLiveComponentHydrator
<s>bug with interfaces</s>
LiveComponentHydrator
<s>bug with interfaces</s>LiveComponentHydrator
doesn't handle objects with no public properties "well"
LiveComponentHydrator
doesn't handle objects with no public properties "well"LiveComponentHydrator
doesn't handle interfaces
The documentation sadly states
But i don't bring only bad news... :) Just after that are listed the different option you can use when you're out of the standard cases:
Maybe one of those is the right fit for you ? |
Thanks for the input. As interfaces resolve to concrete classes, why this can't implement in the source code? Basically only the classType is wrong .. |
There would need to be some way to hint to the system that the namespace App\Model;
class Product
{
// something here ... or on the `product` LiveProp in your component to hint that the dehydrated data for this should be rehydrated into a specific class
public ?DiscountInterface $discount = null;
} So, this is solveable - but not sure the best path at the moment. Btw, the root of the issue is that we don't expose your server-side metadata to the client. So by the time the data is sent to the frontend, this |
@weaverryan I see now. So the problem isn't the dehydrate but the hydrate where the lack of "metadata", that is... which class that implements the Anyways, in the meanwhile, a problem remain: (new PropertyInfoExtractor([new ReflectionExtractor()]))->getProperties($classType) This return Why just not throw if object class it's an interface, after checking for extensions to handle it? |
@gremo I wanted to improve same thing in symfony/symfony#41420 |
Throwing a better error would be a simple, but huge step forward. Do you think you could create a PR? |
I'm afraid I don't have enough knowledge on how that component works (I mean the |
I'm opening the PR in 20mn Adding the following exception message:
|
20mn = 1hour.... classic 😆 |
My model is a
Product
which has a typeddiscount
property of typeDiscountInterface
:I'musing
Product
as aLiveProp
(it doesn't matter how I use it or where, keep reading).During the de/hydration process, a warning is raised:
Investigating more, around the
dehydrateObjectValue
ofLiveComponentHydrator
:$value
is the instance ofApp\Model\StackableDiscount
$classType
isDiscountInterface
getProperties
onPropertyInfoExtractor
returnsnull
(hence theforeach
warning)I think this is a bug but I don't know how to fix it. Logically, we can't get properties from an interface.
$classType
is cleary wrong here.Maybe:
The text was updated successfully, but these errors were encountered: