1 | <?php |
||
10 | trait ChecksServer |
||
11 | { |
||
12 | use ItFetchesServers; |
||
13 | |||
14 | /** |
||
15 | * Check server and abort. |
||
16 | * |
||
17 | * @param null $server |
||
18 | */ |
||
19 | protected function checkServerAndAbort($server = null) |
||
27 | |||
28 | /** |
||
29 | * Check value in servers. |
||
30 | * |
||
31 | * @param $env_var |
||
32 | * @param $field |
||
33 | * @param null $value |
||
34 | * @param null $servers |
||
35 | * @return bool |
||
36 | */ |
||
37 | protected function checkValue($env_var, $field, $value = null, $servers = null) |
||
43 | |||
44 | /** |
||
45 | * Obtain servers. |
||
46 | * |
||
47 | * @return array|mixed |
||
48 | */ |
||
49 | protected function obtainServers() |
||
53 | |||
54 | /** |
||
55 | * Check server id. |
||
56 | * |
||
57 | * @param null $server |
||
58 | * @param null $servers |
||
59 | * @return bool |
||
60 | */ |
||
61 | protected function checkServer($server = null, $servers = null) |
||
62 | { |
||
63 | return $this->checkValue('ACACHA_FORGE_SERVER', 'forge_id', $server, $servers); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Check ip. |
||
68 | * |
||
69 | * @param null $ip |
||
70 | * @param null $servers |
||
71 | * @return bool |
||
72 | */ |
||
73 | protected function checkIp($ip = null, $servers = null) |
||
77 | |||
78 | /** |
||
79 | * Check server name. |
||
80 | * |
||
81 | * @param null $server_name |
||
82 | * @param null $servers |
||
83 | * @return bool |
||
84 | */ |
||
85 | protected function checkServerName($server_name = null, $servers = null) |
||
89 | } |
||
90 |
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.