1 | <?php |
||
13 | trait SmartMeta |
||
14 | { |
||
15 | protected $id; |
||
16 | |||
17 | protected $cacheMetas; |
||
18 | |||
19 | protected $globalKey; |
||
20 | |||
21 | protected $expireTime = 5; // 5 minutes |
||
22 | |||
23 | /** |
||
24 | * |
||
25 | * |
||
26 | * @return $this |
||
27 | */ |
||
28 | public function initCache() |
||
39 | |||
40 | /** |
||
41 | * |
||
42 | * |
||
43 | * @param $key |
||
44 | * @param $value |
||
45 | * @return $this |
||
46 | */ |
||
47 | public function putCacheMeta($key, $value) |
||
54 | |||
55 | // /** |
||
56 | // * @return array |
||
57 | // */ |
||
58 | // public function getAllCacheMeta(): array |
||
59 | // { |
||
60 | // return (Cache::get($this->globalKey)); |
||
61 | // } |
||
62 | |||
63 | |||
64 | /** |
||
65 | * @param $key |
||
66 | * @param null $default |
||
67 | * @param bool $getObj |
||
68 | * @return null |
||
69 | */ |
||
70 | public function getCacheMeta($key, $default = null, $getObj = false) |
||
78 | |||
79 | /** |
||
80 | * @param $key |
||
81 | * @return $this |
||
82 | */ |
||
83 | public function deleteCacheMeta($key) |
||
90 | |||
91 | /** |
||
92 | * |
||
93 | */ |
||
94 | public function deleteCacheMetas() |
||
101 | |||
102 | /** |
||
103 | * @param $key |
||
104 | * @param $value |
||
105 | */ |
||
106 | public function addCacheMeta($key, $value) |
||
112 | |||
113 | /** |
||
114 | * @param $value |
||
115 | * @return $this |
||
116 | */ |
||
117 | public function pushCacheMeta($value) |
||
124 | |||
125 | /** |
||
126 | * @param $key |
||
127 | * @param $default |
||
128 | * @return $this |
||
129 | */ |
||
130 | public function pullCacheMeta($key, $default = null) |
||
137 | |||
138 | /** |
||
139 | * @return $this |
||
140 | */ |
||
141 | public function setAllCacheMeta() |
||
146 | |||
147 | /** |
||
148 | * @return $this |
||
149 | */ |
||
150 | public function getAllCacheMeta() |
||
155 | |||
156 | /** |
||
157 | * @return mixed |
||
158 | */ |
||
159 | 1 | public function getId() |
|
163 | |||
164 | /** |
||
165 | * @param mixed $id |
||
166 | */ |
||
167 | 1 | public function setId($id) |
|
171 | |||
172 | /** |
||
173 | * @return mixed |
||
174 | */ |
||
175 | public function getGlobalKey() |
||
179 | |||
180 | /** |
||
181 | * @param mixed $globalKey |
||
182 | */ |
||
183 | 1 | public function setGlobalKey($globalKey) |
|
187 | |||
188 | /** |
||
189 | * @return int |
||
190 | */ |
||
191 | public function getExpireTime(): int |
||
195 | |||
196 | /** |
||
197 | * @param int $expireTime |
||
198 | */ |
||
199 | public function setExpireTime(int $expireTime) |
||
203 | |||
204 | /** |
||
205 | * @return mixed |
||
206 | */ |
||
207 | public function getCacheMetas() |
||
211 | |||
212 | /** |
||
213 | * @param mixed $cacheMetas |
||
214 | */ |
||
215 | public function setCacheMetas($cacheMetas) |
||
219 | } |
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.