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 | "accounts" => [ |
||
27 | "base_action" => "full_profile", |
||
28 | "actions" => [ |
||
29 | "full_profile" => '\Profile', |
||
30 | "threads" => ['\Thread', '', 'thread_id'], |
||
31 | "posts" => ['\Post', 'post', 'post_id'], |
||
32 | ] |
||
33 | ], |
||
34 | "organizations" => [ |
||
35 | "base_action" => "single_organization", |
||
36 | "actions" => [ |
||
37 | "single_organization" => '\Organisation', |
||
38 | "organization_members" => ['\OrgMember', '', 'handle'] |
||
39 | ] |
||
40 | ], |
||
41 | ]; |
||
42 | |||
43 | /** |
||
44 | * StarCitizens constructor. |
||
45 | */ |
||
46 | 20 | public function __construct() |
|
50 | |||
51 | /** |
||
52 | * Find an entity based on id and return the correct model or raw json output |
||
53 | * |
||
54 | * @param $id |
||
55 | * @param $system |
||
56 | * @param $profileType |
||
57 | * @param bool $raw |
||
58 | * @param bool $cache |
||
59 | * @return bool|mixed |
||
60 | */ |
||
61 | 19 | private function get($id, $system, $profileType, $raw = false, $cache = false) |
|
75 | |||
76 | /** |
||
77 | * Returns the params needed for an API call |
||
78 | * |
||
79 | * @param $id |
||
80 | * @param $system |
||
81 | * @param $profileType |
||
82 | * @param $cache |
||
83 | * @return array |
||
84 | */ |
||
85 | 19 | private function getCallParams($id, $system, $profileType, $cache) |
|
100 | |||
101 | /** |
||
102 | * Checks the response for success messages and returns the raw response or model |
||
103 | * |
||
104 | * @param $response |
||
105 | * @param $profileType |
||
106 | * @param $raw |
||
107 | * |
||
108 | * @return bool|mixed |
||
109 | */ |
||
110 | 19 | private function checkResponse($response, $profileType, $raw) |
|
122 | |||
123 | /** |
||
124 | * Setup the client |
||
125 | */ |
||
126 | 20 | private static function setupClient() |
|
132 | |||
133 | /** |
||
134 | * Fills our model in with the provided data or sends the data to a store |
||
135 | * |
||
136 | * @param $model |
||
137 | * @param $fillData |
||
138 | * |
||
139 | * @return Model |
||
140 | */ |
||
141 | 19 | private function fillModel($model, $fillData) |
|
152 | |||
153 | /** |
||
154 | * Magic call function based on the config information |
||
155 | * |
||
156 | * @param $name |
||
157 | * @param $arguments |
||
158 | * @return bool|mixed |
||
159 | * @throws \Exception |
||
160 | */ |
||
161 | 20 | public function __call($name, $arguments) |
|
169 | |||
170 | /** |
||
171 | * This is the real call function |
||
172 | * |
||
173 | * @param $system |
||
174 | * @param array $arguments |
||
175 | * @return bool|mixed |
||
176 | */ |
||
177 | 19 | private function doCall($system, array $arguments = []) |
|
189 | |||
190 | /** |
||
191 | * Get the standard arguments for a find call and checks that we |
||
192 | * have the correct arguments passed to the magic function |
||
193 | * |
||
194 | * @param array $arguments |
||
195 | * @return array |
||
196 | */ |
||
197 | 19 | private function standardGetArguments(array $arguments) |
|
217 | |||
218 | /** |
||
219 | * Allows our functions to be called statically, this is a bit hacky tbh. |
||
220 | * |
||
221 | * @param $name |
||
222 | * @param $arguments |
||
223 | * @return bool|mixed |
||
224 | * @throws \Exception |
||
225 | */ |
||
226 | 1 | public static function __callStatic($name, $arguments) |
|
231 | } |