Skip to content

[LiveComponent] LiveComponentHydrator doesn't handle interfaces #1590

Closed
@gremo

Description

@gremo

My model is a Product which has a typed discount property of type DiscountInterface:

namespace App\Model;

class Product
{
    public ?DiscountInterface $discount = null;
}

I'musing Product as a LiveProp (it doesn't matter how I use it or where, keep reading).

During the de/hydration process, a warning is raised:

Warning: foreach() argument must be of type array|object, null given.
in vendor/symfony/ux-live-component/src/LiveComponentHydrator.php (line 490)

Investigating more, around the dehydrateObjectValue of LiveComponentHydrator:

  • The passed $value is the instance of App\Model\StackableDiscount
  • The $classType is DiscountInterface
  • The getProperties on PropertyInfoExtractor returns null (hence the foreach warning)

image

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:

if (is_subclass_of($value, $classType, true)) {
    $classType = get_class($value);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions