cfc8f0793dc7af1f34a8a765730419ee33c1c8e3
[GitHub/WoltLab/WCF.git] /
1 <?php
2
3 declare(strict_types=1);
4
5 namespace CuyZ\Valinor\Mapper\Object\Factory;
6
7 use CuyZ\Valinor\Definition\ClassDefinition;
8 use CuyZ\Valinor\Mapper\Object\Exception\PermissiveTypeNotAllowed;
9 use CuyZ\Valinor\Utility\PermissiveTypeFound;
10 use CuyZ\Valinor\Utility\TypeHelper;
11
12 /** @internal */
13 final class StrictTypesObjectBuilderFactory implements ObjectBuilderFactory
14 {
15 public function __construct(private ObjectBuilderFactory $delegate)
16 {
17 }
18
19 public function for(ClassDefinition $class): array
20 {
21 $builders = $this->delegate->for($class);
22
23 foreach ($builders as $builder) {
24 $arguments = $builder->describeArguments();
25
26 foreach ($arguments as $argument) {
27 try {
28 TypeHelper::checkPermissiveType($argument->type());
29 } catch (PermissiveTypeFound $exception) {
30 throw new PermissiveTypeNotAllowed($builder, $argument, $exception);
31 }
32 }
33 }
34
35 return $builders;
36 }
37 }