Skip to content

Unwrapping Denormalizer #2

Open

Activity

  1. SerafimArts commented on Dec 23, 2024

    @SerafimArts
    Member

    It seems like something similar could be done with custom types.

    $result = $mapper->denormalize($value, 'unwrap{path: "[baz][inner]", ...<ValueType>}');

    On the other hand, this is not very correct from a semantic point of view...

    I'm not sure that this is a critically needed functionality. Often, such things are solved manually.

    The only downside is that the mapper does not yet support array shapes, otherwise we could do:

    $json = '{"baz": {"foo": "bar", "inner": {"title": "value", "numbers": [5,3]}}}';
    
    $result = $mapper->denormalize(json_decode($json), <<<'TYPE'
        array{ 
            baz: array{
                inner: ExpectedType, 
                ...
            }
        }
        TYPE);
    
    /** @var ExpectedType $value */
    $value = $result['baz']['inner'];

    For some reason it just seems to me that this is some kind of separate, full-fledged functionality that should be introduced along with embeddable (Doctrine-like) types. The only difference is in the unpacking: One (embeddables) puts data it inside other type, and the other (unwraps) outside.

    P.S. If there are any suggestions on how to elegantly solve the problem - welcome))) I can only theorize for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions