Stenope icon indicating copy to clipboard operation
Stenope copied to clipboard

Allow denormalization to simple array

Open Tom32i opened this issue 3 years ago • 1 comments

For some usage, or just for convenience, it might be interesting to skip the "Create a Model" phase and juste get object as array to be manipulated in twig.

A unique key like user would be used instead of a FQCN:

$contentManager->getContents('user');

We would need to consider any unwanted side-effect.

Tom32i avatar May 19 '21 19:05 Tom32i

What about class User extends \stdClass {} ? 😁 It'll virtually accept any property and behave array-like.

I'm curious about use-cases for specifically having arrays instead of objects, but just for the convenience stuff, this trick might be enough and still keeps a proper unique, discoverable and auto-completable identifier with the FQCN.

It may require us to provide a small custom denormalizer for \stdClass though, since Symfony's ObjectNormalizer does only support \stdClass normalization as far as I remember. So denormalizing to an empty class might not work as expected due to non-discoverable properties.

Depending on what are the benefits you really expect with this idea, we can also generate on fly such generic classes for an identifier.

ogizanagi avatar May 19 '21 19:05 ogizanagi