StenopePHP / Stenope

The static website generator for Symfony developers
https://stenopephp.github.io/Stenope/
MIT License
119 stars 9 forks source link

Allow denormalization to simple array #91

Open Tom32i opened 3 years ago

Tom32i commented 3 years ago

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.

ogizanagi commented 3 years ago

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.