orisai / object-mapper

Raw data mapping to validated objects
Mozilla Public License 2.0
10 stars 1 forks source link

Proxy objects #23

Closed mabar closed 2 years ago

mabar commented 2 years ago

Map fields from flat structure to objects hierarchy

Field names of root and all levels of proxied objects must be checked for name collisions

Proxy should not be allowed to be contained in other rules?

namespace Example\Orisai\ObjectMapper;

use Orisai\ObjectMapper\Attributes\Expect\MappedObjectValue;
use Orisai\ObjectMapper\Attributes\Expect\StringValue;
use Orisai\ObjectMapper\Attributes\Modifiers\FieldName;
use Orisai\ObjectMapper\MappedObject;
use Orisai\ObjectMapper\Processing\Processor;

final class Example extends MappedObject
{

    #[MappedObjectValue(Proxied::class, proxy: true)]
    public Proxied $proxy;

    #[MappedObjectValue(Proxied::class, proxy: true, proxySeparator: '@')]
    #[FieldName('changed-name')]
    public Proxied $anotherProxy;

}

final class Proxied extends MappedObject
{

    #[StringValue]
    public string $example;

}

$processor;
assert($processor instanceof Processor);

$processor->process([
    'proxy-example' => 'foo',
    'changed-name@example' => 'foo',
], Example::class);
mabar commented 2 years ago

Maybe later.

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.