1 | <?php |
||
23 | class CacheService implements SingletonInterface |
||
24 | { |
||
25 | const CACHE_IDENTIFIER = 'cache_configuration_object'; |
||
26 | const CACHE_TAG_DYNAMIC_CACHE = 'dynamic-cache'; |
||
27 | |||
28 | /** |
||
29 | * Options for the internal cache. |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | protected $cacheOptions = [ |
||
34 | 'backend' => FileBackend::class, |
||
35 | 'frontend' => VariableFrontend::class, |
||
36 | 'groups' => ['all', 'system'] |
||
37 | ]; |
||
38 | |||
39 | /** |
||
40 | * @var CacheManager |
||
41 | */ |
||
42 | protected $cacheManager; |
||
43 | |||
44 | /** |
||
45 | * Function called from `ext_localconf` file which will register the |
||
46 | * internal cache earlier. |
||
47 | * |
||
48 | * @internal |
||
49 | */ |
||
50 | public function registerInternalCache() |
||
58 | |||
59 | /** |
||
60 | * This function will take care of initializing all caches that were defined |
||
61 | * previously by the `CacheService` which allows dynamic caches to be used |
||
62 | * for every configuration object type. |
||
63 | * |
||
64 | * @see \Romm\ConfigurationObject\Service\Items\Cache\CacheService::initialize() |
||
65 | * @internal |
||
66 | */ |
||
67 | public function registerDynamicCaches() |
||
78 | |||
79 | /** |
||
80 | * Registers a new dynamic cache: the cache will be added to the cache |
||
81 | * manager after this function is executed. Its configuration will also be |
||
82 | * remembered so the cache will be registered properly during the cache |
||
83 | * framework initialization in further requests. |
||
84 | * |
||
85 | * @param string $identifier |
||
86 | * @param array $options |
||
87 | */ |
||
88 | public function registerDynamicCache($identifier, array $options) |
||
103 | |||
104 | /** |
||
105 | * @param string $identifier |
||
106 | * @param array $options |
||
107 | */ |
||
108 | protected function registerCacheInternal($identifier, array $options) |
||
116 | |||
117 | /** |
||
118 | * @return FrontendInterface |
||
119 | */ |
||
120 | protected function getCache() |
||
124 | |||
125 | /** |
||
126 | * @return CacheManager |
||
127 | */ |
||
128 | protected function getCacheManager() |
||
137 | } |
||
138 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: