1 | <?php |
||
10 | trait MemcacheTrait |
||
11 | { |
||
12 | /** |
||
13 | * Read the server information and add not existing keys |
||
14 | * |
||
15 | * @param array &$infos Server informations |
||
16 | * |
||
17 | * @return void |
||
18 | * |
||
19 | * @throw \Exception If informations datas is not an array |
||
20 | */ |
||
21 | protected function completeServerInfos(&$infos) |
||
44 | |||
45 | /** |
||
46 | * addServer not created the connection. It's created at the first call |
||
47 | * to the memcached servers. |
||
48 | * |
||
49 | * So, we run the connect to all server declared |
||
50 | * |
||
51 | * @throws \Exception If a server is not connected |
||
52 | * |
||
53 | * @return boolean |
||
54 | */ |
||
55 | protected function testConnect() |
||
82 | |||
83 | /** |
||
84 | * Check if a key exists into memcache(d) |
||
85 | * /!\ Not work if the correct value is the boolean false /!\ |
||
86 | * |
||
87 | * @param string $key The memcache(d) key to check |
||
88 | * |
||
89 | * @return boolean |
||
90 | * |
||
91 | * @throws Exception If the key is not a string |
||
92 | */ |
||
93 | public function ifExists($key) |
||
116 | |||
117 | /** |
||
118 | * Update the expire time for a memcache(d) key. |
||
119 | * |
||
120 | * @param string $key The memcache(d) key to update |
||
121 | * @param int $expire The new expire time |
||
122 | * |
||
123 | * @return boolean |
||
124 | * |
||
125 | * @throws Exception |
||
126 | */ |
||
127 | public function updateExpire($key, $expire) |
||
158 | } |
||
159 |
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.