1 | <?php namespace AdammBalogh\KeyValueStore\Adapter\SharedMemoryAdapter; |
||
9 | trait KeyTrait |
||
10 | { |
||
11 | /** |
||
12 | * Removes a key. |
||
13 | * |
||
14 | * @param string $key |
||
15 | * |
||
16 | * @return bool True if the deletion was successful, false if the deletion was unsuccessful. |
||
17 | * |
||
18 | * @throws \Exception |
||
19 | */ |
||
20 | public function delete($key) |
||
34 | |||
35 | /** |
||
36 | * Sets a key's time to live in seconds. |
||
37 | * |
||
38 | * @param string $key |
||
39 | * @param int $seconds |
||
40 | * |
||
41 | * @return bool True if the timeout was set, false if the timeout could not be set. |
||
42 | * |
||
43 | * @throws \Exception |
||
44 | */ |
||
45 | public function expire($key, $seconds) |
||
55 | |||
56 | /** |
||
57 | * Returns the remaining time to live of a key that has a timeout. |
||
58 | * |
||
59 | * @param string $key |
||
60 | * |
||
61 | * @return int Ttl in seconds. |
||
62 | * |
||
63 | * @throws KeyNotFoundException |
||
64 | * @throws \Exception |
||
65 | */ |
||
66 | public function getTtl($key) |
||
81 | |||
82 | /** |
||
83 | * Determines if a key exists. |
||
84 | * |
||
85 | * @param string $key |
||
86 | * |
||
87 | * @return bool True if the key does exist, false if the key does not exist. |
||
88 | * |
||
89 | * @throws \Exception |
||
90 | */ |
||
91 | public function has($key) |
||
101 | |||
102 | /** |
||
103 | * Removes the existing timeout on key, turning the key from volatile (a key with an expire set) |
||
104 | * to persistent (a key that will never expire as no timeout is associated). |
||
105 | * |
||
106 | * @param string $key |
||
107 | * |
||
108 | * @return bool True if the persist was success, false if the persis was unsuccessful. |
||
109 | * |
||
110 | * @throws \Exception |
||
111 | */ |
||
112 | public function persist($key) |
||
133 | } |
||
134 |
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.