Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow denormalization to simple array #91

Open
Tom32i opened this issue May 19, 2021 · 1 comment
Open

Allow denormalization to simple array #91

Tom32i opened this issue May 19, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@Tom32i
Copy link
Collaborator

Tom32i commented May 19, 2021

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
Copy link
Member

ogizanagi commented May 19, 2021

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 ogizanagi added the enhancement New feature or request label May 19, 2021
ogizanagi added a commit to Elao/elao_ that referenced this issue Jul 1, 2021
POC for StenopePHP/Stenope#91 (comment)

Such content pages allows any properties by relying on \stdClass
specificities.
It just need creating once a class extending \stdClass. Then, any
content, with various and different properties can be loaded with the
content manager with its slug:

```php
$manager->getContent(Misc::class, 'elaomojis')
```
ogizanagi added a commit to Elao/elao_ that referenced this issue Jul 1, 2021
POC for StenopePHP/Stenope#91 (comment)

Such content pages allows any properties by relying on \stdClass
specificities.
It just need creating once a class extending \stdClass. Then, any
content, with various and different properties can be loaded with the
content manager with its slug:

```php
$manager->getContent(Misc::class, 'elaomojis')
```
ogizanagi added a commit to Elao/elao_ that referenced this issue Jul 1, 2021
POC for StenopePHP/Stenope#91 (comment)

Such content pages allows any properties by relying on \stdClass
specificities.
It just need creating once a class extending \stdClass. Then, any
content, with various and different properties can be loaded with the
content manager with its slug:

```php
$manager->getContent(Misc::class, 'elaomojis')
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants