1 | <?php |
||
15 | class CachedProvider implements DefinitionProviderInterface |
||
16 | { |
||
17 | const PREFIX = 'json_api_mapper.'; |
||
18 | |||
19 | /** |
||
20 | * Delegated provider |
||
21 | * |
||
22 | * @var DefinitionProviderInterface |
||
23 | */ |
||
24 | protected $provider; |
||
25 | |||
26 | /** |
||
27 | * PSR-16 Compatible cache |
||
28 | * |
||
29 | * @var CacheInterface |
||
30 | */ |
||
31 | protected $cache; |
||
32 | |||
33 | /** |
||
34 | * Locally cached definitions |
||
35 | * |
||
36 | * @var Definition[] |
||
37 | */ |
||
38 | protected $definitions = []; |
||
39 | |||
40 | /** |
||
41 | * CachedProvider constructor. |
||
42 | * |
||
43 | * @param DefinitionProviderInterface $provider |
||
44 | * @param CacheInterface $cache |
||
45 | */ |
||
46 | 3 | public function __construct(DefinitionProviderInterface $provider, CacheInterface $cache) |
|
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | 3 | public function getDefinition(string $class): Definition |
|
63 | |||
64 | /** |
||
65 | * Provide definition: try cache or get from provider |
||
66 | * |
||
67 | * @param string $class |
||
68 | * @return Definition |
||
69 | */ |
||
70 | 3 | public function provideDefinition(string $class): Definition |
|
85 | } |