1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Yproximite\Api\Service; |
5
|
|
|
|
6
|
|
|
use Yproximite\Api\Client\Client; |
7
|
|
|
use Yproximite\Api\Factory\ModelFactory; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class ServiceAggregator |
11
|
|
|
*/ |
12
|
|
|
class ServiceAggregator |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var Client |
16
|
|
|
*/ |
17
|
|
|
private $client; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var ModelFactory |
21
|
|
|
*/ |
22
|
|
|
private $modelFactory; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var ServiceInterface[] |
26
|
|
|
*/ |
27
|
|
|
private $services = []; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* ServiceAggregator constructor. |
31
|
|
|
* |
32
|
|
|
* @param Client $client |
33
|
|
|
*/ |
34
|
|
|
public function __construct(Client $client) |
35
|
|
|
{ |
36
|
|
|
$this->client = $client; |
37
|
|
|
$this->modelFactory = new ModelFactory(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return ArticleService |
42
|
|
|
*/ |
43
|
|
|
public function article(): ArticleService |
44
|
|
|
{ |
45
|
|
|
/** @var ArticleService $service */ |
46
|
|
|
$service = $this->getService(ArticleService::class); |
47
|
|
|
|
48
|
|
|
return $service; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return CallTrackingService |
53
|
|
|
*/ |
54
|
|
|
public function callTracking(): CallTrackingService |
55
|
|
|
{ |
56
|
|
|
/** @var CallTrackingService $service */ |
57
|
|
|
$service = $this->getService(CallTrackingService::class); |
58
|
|
|
|
59
|
|
|
return $service; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return CompanyService |
64
|
|
|
*/ |
65
|
|
|
public function company(): CompanyService |
66
|
|
|
{ |
67
|
|
|
/** @var CompanyService $service */ |
68
|
|
|
$service = $this->getService(CompanyService::class); |
69
|
|
|
|
70
|
|
|
return $service; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return FieldService |
75
|
|
|
*/ |
76
|
|
|
public function field(): FieldService |
77
|
|
|
{ |
78
|
|
|
/** @var FieldService $service */ |
79
|
|
|
$service = $this->getService(FieldService::class); |
80
|
|
|
|
81
|
|
|
return $service; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return LocationService |
86
|
|
|
*/ |
87
|
|
|
public function location(): LocationService |
88
|
|
|
{ |
89
|
|
|
/** @var LocationService $service */ |
90
|
|
|
$service = $this->getService(LocationService::class); |
91
|
|
|
|
92
|
|
|
return $service; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return MediaService |
97
|
|
|
*/ |
98
|
|
|
public function media(): MediaService |
99
|
|
|
{ |
100
|
|
|
/** @var MediaService $service */ |
101
|
|
|
$service = $this->getService(MediaService::class); |
102
|
|
|
|
103
|
|
|
return $service; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return SiteService |
108
|
|
|
*/ |
109
|
|
|
public function site(): SiteService |
110
|
|
|
{ |
111
|
|
|
/** @var SiteService $service */ |
112
|
|
|
$service = $this->getService(SiteService::class); |
113
|
|
|
|
114
|
|
|
return $service; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return UserService |
119
|
|
|
*/ |
120
|
|
|
public function user(): UserService |
121
|
|
|
{ |
122
|
|
|
/** @var UserService $service */ |
123
|
|
|
$service = $this->getService(UserService::class); |
124
|
|
|
|
125
|
|
|
return $service; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @param string $class |
130
|
|
|
* |
131
|
|
|
* @return ServiceInterface |
132
|
|
|
*/ |
133
|
|
|
private function getService(string $class): ServiceInterface |
134
|
|
|
{ |
135
|
|
|
if (!array_key_exists($class, $this->services)) { |
136
|
|
|
$this->services[$class] = new $class($this->client, $this->modelFactory); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
return $this->services[$class]; |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|