3 declare(strict_types=1);
5 namespace CuyZ\Valinor\Mapper\Object;
7 use CuyZ\Valinor\Definition\ClassDefinition;
8 use CuyZ\Valinor\Mapper\Tree\Message\UserlandError;
12 final class NativeConstructorObjectBuilder implements ObjectBuilder
14 private Arguments $arguments;
16 public function __construct(private ClassDefinition $class)
20 public function describeArguments(): Arguments
22 return $this->arguments ??= Arguments::fromParameters($this->class->methods()->constructor()->parameters());
25 public function build(array $arguments): object
27 $className = $this->class->name();
28 $arguments = new MethodArguments($this->class->methods()->constructor()->parameters(), $arguments);
31 return new $className(...$arguments);
32 } catch (Exception $exception) {
33 throw UserlandError::from($exception);
37 public function signature(): string
39 return $this->class->methods()->constructor()->signature();