Skip to content
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

[LiveComponent] Uuid are not natively (de)hydrated #1846

Open
Wait4Code opened this issue May 13, 2024 · 2 comments
Open

[LiveComponent] Uuid are not natively (de)hydrated #1846

Wait4Code opened this issue May 13, 2024 · 2 comments

Comments

@Wait4Code
Copy link

I'm not sure if it is covered by the "Future H)" item of #102 issue but I've noticed that LiveComponent crash when trying to (de)hydrate Uuid.

More precisely, in LiveComponentHydrator#dehydrateObjectValue() method, line 507, (new PropertyInfoExtractor([new ReflectionExtractor()]))->getProperties($classType) returns null which makes the foreach loop crash.

This is quite annoying when using Uuid in a DTO class that mixed entities and simple DTOs. I could use useSerializerForHydration option on LineProp but then I would need to manage serialization in my entity which can be a burden.
I will try to get through this by creating an Hydration Extension for Uuid but I think this would be a nice addition if it could be managed by Live Component natively.

@smnandre
Copy link
Collaborator

Is this UUID writable ? If not, maybe you could not make it a live prop ?

@Wait4Code
Copy link
Author

Wait4Code commented May 17, 2024

Well, as it is a dehydration of the Uuid object (from symfony/uid package), I don't think I would change anything. In fact, my UuidHydrationExtension workaround works pretty well :

use Symfony\Component\Uid\AbstractUid;
use Symfony\UX\LiveComponent\Hydration\HydrationExtensionInterface;

class UuidHydrationExtension implements HydrationExtensionInterface
{

    public function supports(string $className): bool
    {
        return is_a($className, AbstractUid::class, true);
    }

    public function hydrate(mixed $value, string $className): ?object
    {
        return new $className($value);
    }

    public function dehydrate(object $object): mixed
    {
        return $object->toRfc4122();
    }
}

I am not sure which package should have the responsibility to handle this compatibility problem between symfony/ux-live-component and symfony/uid packages ? Probably symfony/ux-live-component but for some reason it is not obvious to me :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants