orisai / object-mapper

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

Create without constructor #32

Closed mabar closed 1 year ago

mabar commented 2 years ago

Support manual creation of objects along with auto mapping

#[CreateWithoutConstructor]
final class ExampleInput extends MappedObject
{

    #[StringValue]
    public string $example;

    public function __construct(string $example)
    {
        $this->example = $example;
    }

}
$input = $processor->process(['example' => 'string'], ExampleInput::class);
$input = new ExampleInput('string');
mabar commented 1 year ago

isInstantiable() check should be probably replaced by checks for string being a class (not interface or enum) and non-abstract. Classes created with constructor should be also checked for public constructor.

mabar commented 1 year ago

Partially solved by https://github.com/orisai/object-mapper/commit/e37f84bb809f06115a7720846eb0719e9babb7af

isInstantiable() replacement should be still done

mabar commented 1 year ago

Object creator should also hint annotation could be used and which object failed to be created

mabar commented 1 year ago

Finalized by https://github.com/orisai/object-mapper/commit/3ba0c6e9f2ef96ac166e5dcae5a769bbd8e82741 and https://github.com/orisai/object-mapper/commit/3c96e57649c35e25c9cbccfd1456f2d401793693

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.