|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Marek\OpenWeatherMap\Factory; |
|
6
|
|
|
|
|
7
|
|
|
use Marek\OpenWeatherMap\API\Cache\HandlerInterface; |
|
8
|
|
|
use Marek\OpenWeatherMap\API\Value\Configuration\APIConfiguration; |
|
9
|
|
|
use Marek\OpenWeatherMap\Core\Weather\AirPollution; |
|
10
|
|
|
use Marek\OpenWeatherMap\Core\Weather\HourForecast; |
|
11
|
|
|
use Marek\OpenWeatherMap\Core\Weather\UltravioletIndex; |
|
12
|
|
|
use Marek\OpenWeatherMap\Core\Weather\Weather; |
|
13
|
|
|
use Marek\OpenWeatherMap\Core\WeatherServices; |
|
14
|
|
|
use Marek\OpenWeatherMap\API\Weather\WeatherServicesInterface; |
|
15
|
|
|
use Marek\OpenWeatherMap\API\Weather\Services\WeatherInterface; |
|
16
|
|
|
use Marek\OpenWeatherMap\API\Weather\Services\AirPollutionInterface; |
|
17
|
|
|
use Marek\OpenWeatherMap\API\Weather\Services\UltravioletIndexInterface; |
|
18
|
|
|
use Marek\OpenWeatherMap\API\Weather\Services\HourForecastInterface; |
|
19
|
|
|
use Marek\OpenWeatherMap\Denormalizer\AirPollutionDenormalizer; |
|
20
|
|
|
use Marek\OpenWeatherMap\Denormalizer\HourForecastDenormalizer; |
|
21
|
|
|
use Marek\OpenWeatherMap\Denormalizer\UltravioletIndexDenormalizer; |
|
22
|
|
|
use Marek\OpenWeatherMap\Denormalizer\WeatherDenormalizer; |
|
23
|
|
|
use Marek\OpenWeatherMap\Http\Client\SymfonyHttpClient; |
|
24
|
|
|
use Symfony\Component\HttpClient\HttpClient; |
|
25
|
|
|
|
|
26
|
|
|
class WeatherFactory |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var \Marek\OpenWeatherMap\API\Value\Configuration\APIConfiguration |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $configuration; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var \Marek\OpenWeatherMap\Http\Client\HttpClientInterface |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $httpClient; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var \Marek\OpenWeatherMap\API\Cache\HandlerInterface |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $cache; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var \Marek\OpenWeatherMap\Factory\UrlFactory |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $factory; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var \Marek\OpenWeatherMap\Factory\DenormalizerFactory |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $denormalizerFactory; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* WeatherFactory constructor. |
|
55
|
|
|
* |
|
56
|
|
|
* @param \Marek\OpenWeatherMap\API\Value\Configuration\APIConfiguration $configuration |
|
57
|
|
|
* @param \Marek\OpenWeatherMap\API\Cache\HandlerInterface $cache |
|
58
|
|
|
*/ |
|
59
|
|
|
public function __construct(APIConfiguration $configuration, HandlerInterface $cache) |
|
60
|
|
|
{ |
|
61
|
|
|
$this->configuration = $configuration; |
|
62
|
|
|
$this->httpClient = new SymfonyHttpClient(HttpClient::create()); |
|
63
|
|
|
$this->cache = $cache; |
|
64
|
|
|
$this->factory = new UrlFactory($this->configuration); |
|
65
|
|
|
$this->denormalizerFactory = new DenormalizerFactory(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return \Marek\OpenWeatherMap\API\Weather\WeatherServicesInterface |
|
70
|
|
|
*/ |
|
71
|
|
|
public function createWeatherServices(): WeatherServicesInterface |
|
72
|
|
|
{ |
|
73
|
|
|
return new WeatherServices( |
|
74
|
|
|
$this->createWeatherService(), |
|
75
|
|
|
$this->createHourForecastService(), |
|
76
|
|
|
$this->createUltravioletIndexService(), |
|
77
|
|
|
$this->createAirPollutionService() |
|
78
|
|
|
); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return \Marek\OpenWeatherMap\API\Weather\Services\WeatherInterface |
|
83
|
|
|
*/ |
|
84
|
|
|
public function createWeatherService(): WeatherInterface |
|
85
|
|
|
{ |
|
86
|
|
|
return new Weather( |
|
87
|
|
|
$this->httpClient, |
|
88
|
|
|
$this->factory, |
|
89
|
|
|
$this->cache, |
|
90
|
|
|
new WeatherDenormalizer($this->denormalizerFactory->create()) |
|
91
|
|
|
); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return \Marek\OpenWeatherMap\API\Weather\Services\AirPollutionInterface |
|
96
|
|
|
*/ |
|
97
|
|
|
public function createAirPollutionService(): AirPollutionInterface |
|
98
|
|
|
{ |
|
99
|
|
|
return new AirPollution( |
|
100
|
|
|
$this->httpClient, |
|
101
|
|
|
$this->factory, |
|
102
|
|
|
$this->cache, |
|
103
|
|
|
new AirPollutionDenormalizer($this->denormalizerFactory->create()) |
|
104
|
|
|
); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @return \Marek\OpenWeatherMap\API\Weather\Services\UltravioletIndexInterface |
|
109
|
|
|
*/ |
|
110
|
|
|
public function createUltravioletIndexService(): UltravioletIndexInterface |
|
111
|
|
|
{ |
|
112
|
|
|
return new UltravioletIndex( |
|
113
|
|
|
$this->httpClient, |
|
114
|
|
|
$this->factory, |
|
115
|
|
|
$this->cache, |
|
116
|
|
|
new UltravioletIndexDenormalizer($this->denormalizerFactory->create()) |
|
117
|
|
|
); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return \Marek\OpenWeatherMap\API\Weather\Services\HourForecastInterface |
|
122
|
|
|
*/ |
|
123
|
|
|
public function createHourForecastService(): HourForecastInterface |
|
124
|
|
|
{ |
|
125
|
|
|
return new HourForecast( |
|
126
|
|
|
$this->httpClient, |
|
127
|
|
|
$this->factory, |
|
128
|
|
|
$this->cache, |
|
129
|
|
|
new HourForecastDenormalizer($this->denormalizerFactory->create()) |
|
130
|
|
|
); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|