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) {}
18 public function describeArguments(): Arguments
20 return $this->arguments ??= Arguments::fromParameters($this->class->methods()->constructor()->parameters());
23 public function build(array $arguments): object
25 $className = $this->class->name();
26 $arguments = new MethodArguments($this->class->methods()->constructor()->parameters(), $arguments);
29 return new $className(...$arguments);
30 } catch (Exception $exception) {
31 throw UserlandError::from($exception);
35 public function signature(): string
37 return $this->class->methods()->constructor()->signature();