Open Tom32i opened 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.
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.