1 | <?php |
||
9 | trait ListBehavior |
||
10 | { |
||
11 | private $driver; |
||
12 | |||
13 | abstract protected function init(); |
||
14 | |||
15 | abstract public function actualDriver(); |
||
16 | |||
17 | /** |
||
18 | * Prepend one or multiple values to a list |
||
19 | * @param string $key |
||
20 | * @param array $elements |
||
21 | * @return int the length of the list after the push operations |
||
22 | */ |
||
23 | public function lpush($key, ...$elements) |
||
29 | |||
30 | /** |
||
31 | * Append one or multiple values to a list |
||
32 | * @param string $key |
||
33 | * @param array $elements |
||
34 | * @return int the length of the list after the push operations |
||
35 | */ |
||
36 | public function rpush($key, ...$elements) |
||
42 | |||
43 | /** |
||
44 | * Remove and get the first element in a list |
||
45 | * @param string $key |
||
46 | * @return string|null |
||
47 | */ |
||
48 | public function lpop($key) |
||
54 | |||
55 | /** |
||
56 | * Remove and get the last element in a list |
||
57 | * @param string $key |
||
58 | * @return string|null |
||
59 | */ |
||
60 | public function rpop($key) |
||
66 | |||
67 | /** |
||
68 | * Get an element from a list by its index |
||
69 | * @param string $key |
||
70 | * @param int $index zero-based, so 0 means the first element, 1 the second element and so on. -1 means the last element, -2 means the penultimate and so forth |
||
71 | * @return string|null |
||
72 | */ |
||
73 | public function lindex($key, $index) |
||
79 | } |
||
80 |
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.