1 | <?php |
||
2 | /** |
||
3 | * Configuration file for DI container. |
||
4 | */ |
||
5 | |||
6 | return [ |
||
7 | |||
8 | // Services to add to the container. |
||
9 | "services" => [ |
||
10 | "location" => [ |
||
11 | // Is the service shared, true or false |
||
12 | // Optional, default is true |
||
13 | "shared" => true, |
||
14 | |||
15 | // Callback executed when service is activated |
||
16 | // Create the service, load its configuration (if any) |
||
17 | // and set it up. |
||
18 | "callback" => function () { |
||
19 | $locationService = new \Asti\Weather\LocationService(); |
||
20 | |||
21 | // Load the configuration files |
||
22 | $cfg = $this->get("configuration"); |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
![]() |
|||
23 | $config = $cfg->load("location.php"); |
||
24 | $settings = $config["config"] ?? null; |
||
25 | |||
26 | if ($settings["url"] ?? null) { |
||
27 | $locationService->setUrl($settings["url"]); |
||
28 | } |
||
29 | if ($settings["LOCATIONAPIKEY"] ?? null) { |
||
30 | $locationService->setKey($settings["LOCATIONAPIKEY"]); |
||
31 | } |
||
32 | |||
33 | return $locationService; |
||
34 | } |
||
35 | ], |
||
36 | ], |
||
37 | ]; |
||
38 |