1 | <?php |
||
20 | trait Cacheable |
||
21 | { |
||
22 | /** |
||
23 | * @var CacheItemPoolInterface |
||
24 | */ |
||
25 | private static $cachePool; |
||
26 | |||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | private static $cachePrefix = []; |
||
31 | |||
32 | /** |
||
33 | * @var CacheItemInterface |
||
34 | */ |
||
35 | private $cacheItem; |
||
36 | |||
37 | /** |
||
38 | * Sets the default cache instance used by new models. |
||
39 | */ |
||
40 | public static function setCachePool(CacheItemPoolInterface $pool): void |
||
44 | |||
45 | /** |
||
46 | * Clears the default cache instance for all models. |
||
47 | */ |
||
48 | public static function clearCachePool(): void |
||
52 | |||
53 | /** |
||
54 | * Returns the cache instance. |
||
55 | */ |
||
56 | public function getCachePool(): ?CacheItemPoolInterface |
||
60 | |||
61 | /** |
||
62 | * Returns the cache TTL. |
||
63 | */ |
||
64 | public function getCacheTTL(): ?int |
||
68 | |||
69 | /** |
||
70 | * Returns the cache key for this model. |
||
71 | */ |
||
72 | public function getCacheKey(): string |
||
81 | |||
82 | /** |
||
83 | * Returns the cache item for this model. |
||
84 | */ |
||
85 | public function getCacheItem(): ?CacheItemInterface |
||
98 | |||
99 | public function refresh() |
||
126 | |||
127 | public function refreshWith(array $values) |
||
131 | |||
132 | /** |
||
133 | * Caches the entire model. |
||
134 | * |
||
135 | * @return $this |
||
136 | */ |
||
137 | public function cache() |
||
152 | |||
153 | public function clearCache() |
||
162 | } |
||
163 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.