ec7bedd304950aba9321899965ec617aa5dd5af9
[GitHub/WoltLab/WCF.git] /
1 <?php
2
3 declare(strict_types=1);
4
5 namespace CuyZ\Valinor\Mapper\Object;
6
7 use CuyZ\Valinor\Definition\ClassDefinition;
8 use CuyZ\Valinor\Mapper\Tree\Message\UserlandError;
9 use Exception;
10
11 /** @internal */
12 final class NativeConstructorObjectBuilder implements ObjectBuilder
13 {
14 private Arguments $arguments;
15
16 public function __construct(private ClassDefinition $class) {}
17
18 public function describeArguments(): Arguments
19 {
20 return $this->arguments ??= Arguments::fromParameters($this->class->methods()->constructor()->parameters());
21 }
22
23 public function build(array $arguments): object
24 {
25 $className = $this->class->name();
26 $arguments = new MethodArguments($this->class->methods()->constructor()->parameters(), $arguments);
27
28 try {
29 return new $className(...$arguments);
30 } catch (Exception $exception) {
31 throw UserlandError::from($exception);
32 }
33 }
34
35 public function signature(): string
36 {
37 return $this->class->methods()->constructor()->signature();
38 }
39 }