30eb40aab82da17a9cb9385fd0f2919073fa3c4d
[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 }
19
20 public function describeArguments(): Arguments
21 {
22 return $this->arguments ??= Arguments::fromParameters($this->class->methods()->constructor()->parameters());
23 }
24
25 public function build(array $arguments): object
26 {
27 $className = $this->class->name();
28 $arguments = new MethodArguments($this->class->methods()->constructor()->parameters(), $arguments);
29
30 try {
31 return new $className(...$arguments);
32 } catch (Exception $exception) {
33 throw UserlandError::from($exception);
34 }
35 }
36
37 public function signature(): string
38 {
39 return $this->class->methods()->constructor()->signature();
40 }
41 }