|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of forecast.it.fill project. |
|
7
|
|
|
* (c) Patrick Jaja <[email protected]> |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace ForecastAutomation\ForecastClient; |
|
13
|
|
|
|
|
14
|
|
|
use ForecastAutomation\Cache\CacheFacade; |
|
15
|
|
|
use ForecastAutomation\ForecastClient\Business\ForecastApi; |
|
16
|
|
|
use ForecastAutomation\ForecastClient\Shared\Dto\ForecastConfigDto; |
|
17
|
|
|
use ForecastAutomation\Kernel\AbstractFactory; |
|
18
|
|
|
use ForecastAutomation\Log\LogFacade; |
|
19
|
|
|
use GuzzleHttp\Client; |
|
20
|
|
|
|
|
21
|
|
|
class ForecastClientFactory extends AbstractFactory |
|
22
|
|
|
{ |
|
23
|
|
|
public function createForecastConfigDto(): ForecastConfigDto |
|
24
|
|
|
{ |
|
25
|
|
|
return new ForecastConfigDto( |
|
26
|
|
|
$_ENV['FORECAST_HOST'], |
|
27
|
|
|
$_ENV['FORECAST_API_KEY'], |
|
28
|
|
|
$_ENV['FORECAST_PROJECT_ID'], |
|
29
|
|
|
$_ENV['FORECAST_PERSON_ID'], |
|
30
|
|
|
$_ENV['FORECAST_FALLBACK_TASK_ID'], |
|
31
|
|
|
); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
1 |
|
public function createForecastApi(): ForecastApi |
|
35
|
|
|
{ |
|
36
|
1 |
|
return new ForecastApi( |
|
37
|
1 |
|
$this->createClient(), |
|
38
|
1 |
|
$this->createForecastConfigDto(), |
|
39
|
1 |
|
$this->getLogFacade(), |
|
40
|
1 |
|
$this->getCacheFacade(), |
|
41
|
|
|
); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function createClient(): Client |
|
45
|
|
|
{ |
|
46
|
|
|
return new Client(['base_uri' => (string)$_ENV['FORECAST_HOST']]); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function getLogFacade(): LogFacade |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->getProvidedDependency(ForecastClientDependencyProvider::LOG_FACADE); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function getCacheFacade(): CacheFacade |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->getProvidedDependency(ForecastClientDependencyProvider::CACHE_FACADE); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|