Skip to content
This repository has been archived by the owner on Sep 20, 2019. It is now read-only.

Remove constructor arguments restriction for deserialize #55

Closed
sebastiandedeyne opened this issue Jul 11, 2018 · 3 comments
Closed

Remove constructor arguments restriction for deserialize #55

sebastiandedeyne opened this issue Jul 11, 2018 · 3 comments

Comments

@sebastiandedeyne
Copy link
Member

Would it be possible to have the deserializer Just Work™️ without us needing to match the constructor signature with the stored attributes?

This doesn't work now:

<?php

namespace App\Products\Events;

use Spatie\EventProjector\ShouldBeStored;

class ProductCreated implements ShouldBeStored
{
    /** @var string */
    public $id;

    /** @var string */
    public $name;

    /** @var int */
    public $price;

    public function __construct(string $id, array $attributes)
    {
        $this->id = $id;

        $this->name = $attributes['name'];
        $this->price = $attributes['price'];
    }
}
Cannot create an instance of App\Products\Events\ProductCreated from serialized data because its constructor requires parameter "attributes" to be present.
@freekmurze
Copy link
Member

I really want it to work, but I couldn't find any support for this in Symfony's serializer components. I'm afraid that coding support for this ourselves is a rabbit hole...

@freekmurze
Copy link
Member

If you find a good solution, please PR it.

@rgehan
Copy link
Contributor

rgehan commented Jun 16, 2019

If I'm not mistaken, this isn't explained in the documentation and might confuse some users.

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

No branches or pull requests

3 participants