1 | <?php |
||
15 | final class StarCitizens |
||
16 | { |
||
17 | /** |
||
18 | * @var bool|StarCitizensClient The client object |
||
19 | */ |
||
20 | private static $client = false; |
||
21 | |||
22 | /** |
||
23 | * @var array The config for the StarCitizens todo move this to a separate file |
||
24 | */ |
||
25 | private $systems = []; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | public $configFile; |
||
31 | |||
32 | /** |
||
33 | * StarCitizens constructor. |
||
34 | * |
||
35 | * @param string $configFile |
||
36 | */ |
||
37 | 20 | public function __construct($configFile = "Resources/config/typesConfig.php") |
|
44 | |||
45 | /** |
||
46 | * Reads the basic config. |
||
47 | */ |
||
48 | 20 | private function readConfig() |
|
52 | |||
53 | /** |
||
54 | * Find an entity based on id and return the correct model or raw json output |
||
55 | * |
||
56 | * @param $id |
||
57 | * @param $system |
||
58 | * @param $profileType |
||
59 | * @param bool $raw |
||
60 | * @param bool $cache |
||
61 | * @return bool|mixed |
||
62 | */ |
||
63 | 19 | private function get($id, $system, $profileType, $raw = false, $cache = false) |
|
77 | |||
78 | /** |
||
79 | * Returns the params needed for an API call |
||
80 | * |
||
81 | * @param $id |
||
82 | * @param $system |
||
83 | * @param $profileType |
||
84 | * @param $cache |
||
85 | * @return array |
||
86 | */ |
||
87 | 19 | private function getCallParams($id, $system, $profileType, $cache) |
|
102 | |||
103 | /** |
||
104 | * Checks the response for success messages and returns the raw response or model |
||
105 | * |
||
106 | * @param $response |
||
107 | * @param $profileType |
||
108 | * @param $raw |
||
109 | * |
||
110 | * @return bool|mixed |
||
111 | */ |
||
112 | 19 | private function checkResponse($response, $profileType, $raw) |
|
124 | |||
125 | /** |
||
126 | * Setup the client |
||
127 | */ |
||
128 | 20 | private static function setupClient() |
|
129 | { |
||
130 | 20 | if (self::$client === false) { |
|
131 | 1 | self::$client = new StarCitizensClient(); |
|
132 | } |
||
133 | 20 | } |
|
134 | |||
135 | /** |
||
136 | * Fills our model in with the provided data or sends the data to a store |
||
137 | * |
||
138 | * @param $model |
||
139 | * @param $fillData |
||
140 | * |
||
141 | * @return Model |
||
142 | */ |
||
143 | 19 | private function fillModel($model, $fillData) |
|
154 | |||
155 | /** |
||
156 | * Magic call function based on the config information |
||
157 | * |
||
158 | * @param $name |
||
159 | * @param $arguments |
||
160 | * @return bool|mixed |
||
161 | * @throws \Exception |
||
162 | */ |
||
163 | 20 | public function __call($name, $arguments) |
|
171 | |||
172 | /** |
||
173 | * This is the real call function |
||
174 | * |
||
175 | * @param $system |
||
176 | * @param array $arguments |
||
177 | * @return bool|mixed |
||
178 | */ |
||
179 | 19 | private function doCall($system, array $arguments = []) |
|
191 | |||
192 | /** |
||
193 | * Get the standard arguments for a find call and checks that we |
||
194 | * have the correct arguments passed to the magic function |
||
195 | * |
||
196 | * @param array $arguments |
||
197 | * @return array |
||
198 | */ |
||
199 | 19 | private function standardGetArguments(array $arguments) |
|
200 | { |
||
201 | |||
202 | $defaults = [ |
||
203 | 19 | 'id' => '', |
|
204 | 'action' => '', |
||
205 | 'raw' => false, |
||
206 | 'cache' => false, |
||
207 | ]; |
||
208 | |||
209 | 19 | $varNames = array_keys($defaults); |
|
210 | |||
211 | 19 | for ($argumentCount = 0; $argumentCount < 4; $argumentCount++) { |
|
212 | 19 | if (array_key_exists($argumentCount, $arguments)) { |
|
213 | 19 | $defaults[$varNames[$argumentCount]] = $arguments[$argumentCount]; |
|
214 | } |
||
215 | } |
||
216 | |||
217 | 19 | return $defaults; |
|
218 | } |
||
219 | |||
220 | /** |
||
221 | * Allows our functions to be called statically, this is a bit hacky tbh. |
||
222 | * |
||
223 | * @param $name |
||
224 | * @param $arguments |
||
225 | * @return bool|mixed |
||
226 | * @throws \Exception |
||
227 | */ |
||
228 | 1 | public static function __callStatic($name, $arguments) |
|
233 | } |