04144ce0e8292bbea1bcba8efe47e451dffbb97d
[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
21 public function for(ClassDefinition $class): array
22 {
23 $signature = $class->type()->toString();
24
25 $entry = $this->cache->get($signature);
26
27 if ($entry) {
28 return $entry;
29 }
30
31 $builders = $this->delegate->for($class);
32
33 $this->cache->set($signature, $builders);
34
35 return $builders;
36 }
37 }