82f140072b493d08b4edbfc666c843b961809e12
[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\ObjectBuilder;
9 use Psr\SimpleCache\CacheInterface;
10
11 /** @internal */
12 final class CacheObjectBuilderFactory implements ObjectBuilderFactory
13 {
14 public function __construct(
15 private ObjectBuilderFactory $delegate,
16 /** @var CacheInterface<list<ObjectBuilder>> */
17 private CacheInterface $cache
18 ) {}
19
20 public function for(ClassDefinition $class): array
21 {
22 $signature = $class->type()->toString();
23
24 $entry = $this->cache->get($signature);
25
26 if ($entry) {
27 return $entry;
28 }
29
30 $builders = $this->delegate->for($class);
31
32 $this->cache->set($signature, $builders);
33
34 return $builders;
35 }
36 }