1 | <?php |
||
12 | class WsdlManager |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * @var WebServiceFactoryInterface |
||
17 | */ |
||
18 | protected $webServiceFactory; |
||
19 | |||
20 | /** |
||
21 | * @var Config |
||
22 | */ |
||
23 | protected $config; |
||
24 | |||
25 | /** |
||
26 | * Aliasy webových služeb pro rychlý přístup |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $aliases = [ |
||
31 | "user" => "UserManagement", |
||
32 | "usr" => "UserManagement", |
||
33 | "org" => "OrganizationUnit", |
||
34 | "app" => "ApplicationManagement", |
||
35 | "event" => "Events", |
||
36 | "events" => "Events", |
||
37 | ]; |
||
38 | |||
39 | /** |
||
40 | * Dostupné webové služby SkautISu |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $supportedWebServices = [ |
||
45 | "ApplicationManagement", |
||
46 | "ContentManagement", |
||
47 | "Evaluation", |
||
48 | "Events", |
||
49 | "Exports", |
||
50 | "GoogleApps", |
||
51 | "Journal", |
||
52 | "Material", |
||
53 | "Message", |
||
54 | "OrganizationUnit", |
||
55 | "Power", |
||
56 | "Reports", |
||
57 | "Summary", |
||
58 | "Task", |
||
59 | "Telephony", |
||
60 | "UserManagement", |
||
61 | "Vivant", |
||
62 | "Welcome", |
||
63 | ]; |
||
64 | |||
65 | /** |
||
66 | * @var array |
||
67 | */ |
||
68 | protected $webServiceListeners = []; |
||
69 | |||
70 | /** |
||
71 | * Pole aktivních webových služeb |
||
72 | * |
||
73 | * @var array |
||
74 | */ |
||
75 | protected $webServices = []; |
||
76 | |||
77 | |||
78 | /** |
||
79 | * @param WebServiceFactoryInterface $webServiceFactory továrna pro vytváření objektů webových služeb |
||
80 | * @param Config $config |
||
81 | */ |
||
82 | 3 | public function __construct(WebServiceFactoryInterface $webServiceFactory, Config $config) |
|
87 | |||
88 | /** |
||
89 | * @return Config |
||
90 | */ |
||
91 | public function getConfig() |
||
95 | |||
96 | /** |
||
97 | * Získá objekt webové služby |
||
98 | * |
||
99 | * @param string $name jméno nebo alias webové služby |
||
100 | * @param string|null $loginId skautIS login token |
||
101 | * @return WebServiceInterface |
||
102 | */ |
||
103 | 1 | public function getWebService($name, $loginId = null) |
|
104 | { |
||
105 | 1 | $name = $this->getWebServiceName($name); |
|
106 | 1 | $key = $loginId . '_' . $name . ($this->config->isTestMode() ? '_Test' : ''); |
|
107 | |||
108 | 1 | if (!isset($this->webServices[$key])) { |
|
109 | 1 | $options = $this->config->getSoapOptions(); |
|
110 | 1 | $options[User::ID_LOGIN] = $loginId; |
|
111 | 1 | $this->webServices[$key] = $this->createWebService($name, $options); |
|
112 | } |
||
113 | |||
114 | 1 | return $this->webServices[$key]; |
|
115 | } |
||
116 | |||
117 | /** |
||
118 | * Vytváří objekt webové služby |
||
119 | * |
||
120 | * @param string $name jméno webové služby |
||
121 | * @param array $options volby pro SoapClient |
||
122 | * @return WebService|mixed |
||
123 | */ |
||
124 | 1 | public function createWebService($name, array $options = []) |
|
125 | { |
||
126 | 1 | $webService = $this->webServiceFactory->createWebService($this->getWebServiceUrl($name), $options); |
|
127 | |||
128 | 1 | if ($webService instanceof EventDispatcherInterface) { |
|
129 | // Zaregistruj listenery na vytvořeném objektu webové služby, pokud je to podporováno |
||
130 | foreach ($this->webServiceListeners as $listener) { |
||
131 | $webService->subscribe($listener['eventName'], $listener['callback']); |
||
132 | } |
||
133 | } |
||
134 | |||
135 | 1 | return $webService; |
|
136 | } |
||
137 | |||
138 | /** |
||
139 | * Vrací celé jméno webové služby |
||
140 | * |
||
141 | * @param string $name jméno nebo alias webové služby |
||
142 | * @return string |
||
143 | * @throws WsdlException |
||
144 | */ |
||
145 | 1 | protected function getWebServiceName($name) |
|
157 | |||
158 | /** |
||
159 | * Vrací URL webové služby podle jejího jména |
||
160 | * |
||
161 | * @param string $name celé jméno webové služby |
||
162 | * @return string |
||
163 | */ |
||
164 | 1 | protected function getWebServiceUrl($name) |
|
168 | |||
169 | /** |
||
170 | * Vrací seznam webových služeb, které podporuje |
||
171 | * |
||
172 | * @return array |
||
173 | */ |
||
174 | 1 | public function getSupportedWebServices() |
|
178 | |||
179 | /** |
||
180 | * @return bool |
||
181 | */ |
||
182 | public function isMaintenance() |
||
187 | |||
188 | /** |
||
189 | * Přidá listener na spravovaných vytvářených webových služeb. |
||
190 | * |
||
191 | * @param string $eventName |
||
192 | * @param callable $callback |
||
193 | */ |
||
194 | public function addWebServiceListener($eventName, callable $callback) |
||
201 | } |
||
202 |