1 | <?php |
||
15 | final class StarCitizens |
||
16 | { |
||
17 | /** |
||
18 | * @var bool|StarCitizensClient |
||
19 | */ |
||
20 | private static $client = false; |
||
21 | |||
22 | private $systems = [ |
||
23 | "accounts" => [ |
||
24 | "base_action" => "full_profile", |
||
25 | "actions" => [ |
||
26 | "full_profile" => '\Profile', |
||
27 | "threads" => ['\Thread', '', 'thread_id'], |
||
28 | "posts" => ['\Post', 'post', 'post_id'], |
||
29 | ] |
||
30 | ] |
||
31 | ]; |
||
32 | |||
33 | /** |
||
34 | * StarCitizens constructor. |
||
35 | */ |
||
36 | 4 | public function __construct() |
|
40 | |||
41 | /** |
||
42 | * @param $name |
||
43 | * @param $arguments |
||
44 | * @return bool|mixed |
||
45 | * @throws \Exception |
||
46 | */ |
||
47 | 4 | public function __call($name, $arguments) |
|
48 | { |
||
49 | 4 | if (array_key_exists($name, $this->systems)) { |
|
50 | 3 | $this->doCall($name, $arguments); |
|
51 | 3 | } |
|
52 | |||
53 | 4 | throw new \Exception("Method not found"); |
|
54 | } |
||
55 | |||
56 | /** |
||
57 | * @param $name |
||
58 | * @param array $arguments |
||
59 | * @return bool|mixed |
||
60 | */ |
||
61 | 3 | private function doCall($name, array $arguments) |
|
62 | { |
||
63 | 3 | $argumentCount = count($arguments); |
|
64 | |||
65 | 3 | if ($argumentCount == 0) |
|
66 | 3 | throw new \InvalidArgumentException("Requires an argument"); |
|
67 | |||
68 | 3 | if ($argumentCount > 0 && $argumentCount< 2) |
|
69 | 3 | return $this->find($arguments[0], $name, $this->systems[$name]['base_action']); |
|
70 | |||
71 | 1 | if ($argumentCount == 2) { |
|
72 | 1 | list($id, $profileType) = $arguments; |
|
73 | 1 | if ($profileType == false) |
|
74 | 1 | $profileType = $this->systems[$name]['base_action']; |
|
75 | 1 | return $this->find($id, $name, $profileType); |
|
76 | } |
||
77 | |||
78 | if ($argumentCount == 4 ) { |
||
79 | list($id, $profileType, $cache, $raw) = $arguments; |
||
80 | return $this->find($id, $name, $profileType, $cache, $raw); |
||
81 | } |
||
82 | |||
83 | throw new \InvalidArgumentException("Invalid arguments"); |
||
84 | |||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @param $name |
||
89 | * @param $arguments |
||
90 | * @return bool|mixed |
||
91 | * @throws \Exception |
||
92 | */ |
||
93 | 1 | public static function __callStatic($name, $arguments) |
|
98 | |||
99 | |||
100 | /** |
||
101 | * Find an entity |
||
102 | * |
||
103 | * @param $id |
||
104 | * @param $system |
||
105 | * @param $profileType |
||
106 | * @param bool $cache |
||
107 | * @param bool $raw |
||
108 | * @return bool|mixed |
||
109 | */ |
||
110 | 3 | private function find($id, $system, $profileType, $cache = false, $raw = false) |
|
124 | |||
125 | /** |
||
126 | * @param $id |
||
127 | * @param $system |
||
128 | * @param $profileType |
||
129 | * @param $cache |
||
130 | * @return array |
||
131 | */ |
||
132 | 3 | private function getParams($id, $system, $profileType, $cache) |
|
147 | |||
148 | /** |
||
149 | * @param $response |
||
150 | * @param $profileType |
||
151 | * @param $raw |
||
152 | * |
||
153 | * @return bool|mixed |
||
154 | */ |
||
155 | 3 | private function checkResponse($response, $profileType, $raw) |
|
167 | |||
168 | /** |
||
169 | * Setup the client |
||
170 | */ |
||
171 | 4 | private static function setupClient() |
|
177 | |||
178 | /** |
||
179 | * Fills our model in with the provided data |
||
180 | * |
||
181 | * @param $model |
||
182 | * @param $fillData |
||
183 | * |
||
184 | * @return Model |
||
185 | */ |
||
186 | 3 | private function fillModel($model, $fillData) |
|
197 | } |
Late static binding only has effect in subclasses. A
final
class cannot be extended anymore so late static binding cannot occurr. Consider replacingstatic::
withself::
.To learn more about late static binding, please refer to the PHP core documentation.