1<?php
2/*
3** Zabbix
4** Copyright (C) 2001-2021 Zabbix SIA
5**
6** This program is free software; you can redistribute it and/or modify
7** it under the terms of the GNU General Public License as published by
8** the Free Software Foundation; either version 2 of the License, or
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program; if not, write to the Free Software
18** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19**/
20
21
22class API {
23
24	/**
25	 * API wrapper that all of the calls will go through.
26	 *
27	 * @var CApiWrapper
28	 */
29	private static $wrapper;
30
31	/**
32	 * Factory for creating API services.
33	 *
34	 * @var CRegistryFactory
35	 */
36	private static $apiServiceFactory;
37
38	/**
39	 * Sets the API wrapper.
40	 *
41	 * @param CApiWrapper|null $wrapper
42	 */
43	public static function setWrapper(CApiWrapper $wrapper = null) {
44		self::$wrapper = $wrapper;
45	}
46
47	/**
48	 * Set the service factory.
49	 *
50	 * @param CRegistryFactory $factory
51	 */
52	public static function setApiServiceFactory(CRegistryFactory $factory) {
53		self::$apiServiceFactory = $factory;
54	}
55
56	/**
57	 * Returns the API wrapper.
58	 *
59	 * @return CApiWrapper|null
60	 */
61	public static function getWrapper() {
62		return self::$wrapper;
63	}
64
65	/**
66	 * Returns an object that can be used for making API calls.  If a wrapper is used, returns a CApiWrapper,
67	 * otherwise - returns a CApiService object.
68	 *
69	 * @param $name
70	 *
71	 * @return CApiWrapper|CApiService
72	 */
73	public static function getApi($name) {
74		if (self::$wrapper) {
75			self::$wrapper->api = $name;
76
77			return self::$wrapper;
78		}
79		else {
80			return self::getApiService($name);
81		}
82	}
83
84	/**
85	 * Returns the CApiInstance object for the requested API.
86	 *
87	 * NOTE: This method must only be called from other CApiService objects.
88	 *
89	 * @param string $name
90	 *
91	 * @return CApiService
92	 */
93	public static function getApiService($name = null) {
94		return self::$apiServiceFactory->getObject($name ? $name : 'api');
95	}
96
97	/**
98	 * @return CAction
99	 */
100	public static function Action() {
101		return self::getApi('action');
102	}
103
104	/**
105	 * @return CAlert
106	 */
107	public static function Alert() {
108		return self::getApi('alert');
109	}
110
111	/**
112	 * @return CAPIInfo
113	 */
114	public static function APIInfo() {
115		return self::getApi('apiinfo');
116	}
117
118	/**
119	 * @return CAuditLog
120	 */
121	public static function AuditLog() {
122		return self::getApi('auditlog');
123	}
124
125	/**
126	 * @return CAuthentication
127	 */
128	public static function Authentication() {
129		return self::getApi('authentication');
130	}
131
132	/**
133	 * @return CAutoregistration
134	 */
135	public static function Autoregistration() {
136		return self::getApi('autoregistration');
137	}
138
139	/**
140	 * @return CConfiguration
141	 */
142	public static function Configuration() {
143		return self::getApi('configuration');
144	}
145
146	/**
147	 * @return CCorrelation
148	 */
149	public static function Correlation() {
150		return self::getApi('correlation');
151	}
152
153	/**
154	 * @return CDashboard
155	 */
156	public static function Dashboard() {
157		return self::getApi('dashboard');
158	}
159
160	/**
161	 * @return CDCheck
162	 */
163	public static function DCheck() {
164		return self::getApi('dcheck');
165	}
166
167	/**
168	 * @return CDHost
169	 */
170	public static function DHost() {
171		return self::getApi('dhost');
172	}
173
174	/**
175	 * @return CDiscoveryRule
176	 */
177	public static function DiscoveryRule() {
178		return self::getApi('discoveryrule');
179	}
180
181	/**
182	 * @return CDRule
183	 */
184	public static function DRule() {
185		return self::getApi('drule');
186	}
187
188	/**
189	 * @return CDService
190	 */
191	public static function DService() {
192		return self::getApi('dservice');
193	}
194
195	/**
196	 * @return CEvent
197	 */
198	public static function Event() {
199		return self::getApi('event');
200	}
201
202	/**
203	 * @return CGraph
204	 */
205	public static function Graph() {
206		return self::getApi('graph');
207	}
208
209	/**
210	 * @return CGraphItem
211	 */
212	public static function GraphItem() {
213		return self::getApi('graphitem');
214	}
215
216	/**
217	 * @return CGraphPrototype
218	 */
219	public static function GraphPrototype() {
220		return self::getApi('graphprototype');
221	}
222
223	/**
224	 * @return CHistory
225	 */
226	public static function History() {
227		return self::getApi('history');
228	}
229
230	/**
231	 * @return CHost
232	 */
233	public static function Host() {
234		return self::getApi('host');
235	}
236
237	/**
238	 * @return CHostPrototype
239	 */
240	public static function HostPrototype() {
241		return self::getApi('hostprototype');
242	}
243
244	/**
245	 * @return CHostGroup
246	 */
247	public static function HostGroup() {
248		return self::getApi('hostgroup');
249	}
250
251	/**
252	 * @return CHostInterface
253	 */
254	public static function HostInterface() {
255		return self::getApi('hostinterface');
256	}
257
258	/**
259	 * @return CHousekeeping
260	 */
261	public static function Housekeeping() {
262		return self::getApi('housekeeping');
263	}
264
265	/**
266	 * @return CImage
267	 */
268	public static function Image() {
269		return self::getApi('image');
270	}
271
272	/**
273	 * @return CIconMap
274	 */
275	public static function IconMap() {
276		return self::getApi('iconmap');
277	}
278
279	/**
280	 * @return CItem
281	 */
282	public static function Item() {
283		return self::getApi('item');
284	}
285
286	/**
287	 * @return CItemPrototype
288	 */
289	public static function ItemPrototype() {
290		return self::getApi('itemprototype');
291	}
292
293	/**
294	 * @return CMaintenance
295	 */
296	public static function Maintenance() {
297		return self::getApi('maintenance');
298	}
299
300	/**
301	 * @return CModule
302	 */
303	public static function Module() {
304		return self::getApi('module');
305	}
306
307	/**
308	 * @return CMap
309	 */
310	public static function Map() {
311		return self::getApi('map');
312	}
313
314	/**
315	 * @return CMediaType
316	 */
317	public static function MediaType() {
318		return self::getApi('mediatype');
319	}
320
321	/**
322	 * @return CProblem
323	 */
324	public static function Problem() {
325		return self::getApi('problem');
326	}
327
328	/**
329	 * @return CProxy
330	 */
331	public static function Proxy() {
332		return self::getApi('proxy');
333	}
334
335	/**
336	 * @return CReport
337	 */
338	public static function Report() {
339		return self::getApi('report');
340	}
341
342	/**
343	 * @return CRole
344	 */
345	public static function Role() {
346		return self::getApi('role');
347	}
348
349	/**
350	 * @return CScript
351	 */
352	public static function Script() {
353		return self::getApi('script');
354	}
355
356	/**
357	 * @return CService
358	 */
359	public static function Service() {
360		return self::getApi('service');
361	}
362
363	/**
364	 * @return CSettings
365	 */
366	public static function Settings() {
367		return self::getApi('settings');
368	}
369
370	/**
371	 * @return CTask
372	 */
373	public static function Task() {
374		return self::getApi('task');
375	}
376
377	/**
378	 * @return CTemplate
379	 */
380	public static function Template() {
381		return self::getApi('template');
382	}
383
384	/**
385	 * @return CTemplateDashboard
386	 */
387	public static function TemplateDashboard() {
388		return self::getApi('templatedashboard');
389	}
390
391	/**
392	 * @return CToken
393	 */
394	public static function Token() {
395		return self::getApi('token');
396	}
397
398	/**
399	 * @return CTrend
400	 */
401	public static function Trend() {
402		return self::getApi('trend');
403	}
404
405	/**
406	 * @return CTrigger
407	 */
408	public static function Trigger() {
409		return self::getApi('trigger');
410	}
411
412	/**
413	 * @return CTriggerPrototype
414	 */
415	public static function TriggerPrototype() {
416		return self::getApi('triggerprototype');
417	}
418
419	/**
420	 * @return CUser
421	 */
422	public static function User() {
423		return self::getApi('user');
424	}
425
426	/**
427	 * @return CUserGroup
428	 */
429	public static function UserGroup() {
430		return self::getApi('usergroup');
431	}
432
433	/**
434	 * @return CUserMacro
435	 */
436	public static function UserMacro() {
437		return self::getApi('usermacro');
438	}
439
440	/**
441	 * @return CValueMap
442	 */
443	public static function ValueMap() {
444		return self::getApi('valuemap');
445	}
446
447	/**
448	 * @return CHttpTest
449	 */
450	public static function HttpTest() {
451		return self::getApi('httptest');
452	}
453}
454