This repository has been archived by the owner on Sep 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 750
/
webservice.php
49 lines (48 loc) · 1.59 KB
/
webservice.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* Web service init file.
*
* @package API
*
* @copyright YetiForce S.A.
* @license YetiForce Public License 6.5 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <[email protected]>
*/
chdir(__DIR__);
require_once __DIR__ . '/include/main/WebUI.php';
require_once __DIR__ . '/include/RequirementsValidation.php';
\App\Process::$requestMode = 'API';
\App\Log::beginProfile(\App\Request::getRequestMethod() . '::' . $_SERVER['REQUEST_URI'], 'WebServiceAPI');
try {
if (!\in_array('webservice', \App\Config::api('enabledServices'))) {
throw new \App\Exceptions\NoPermittedToApi('Webservice - Service is not active', 403);
}
$controller = Api\Controller::getInstance();
try {
$process = $controller->preProcess();
if ($process) {
$controller->process();
}
$controller->postProcess();
} catch (\Throwable $e) {
\App\Log::error($e->getMessage() . PHP_EOL . $e->__toString());
$controller->handleError($e);
if ($e instanceof \Api\Core\Exception) {
$e->handleError();
} else {
if ($e instanceof \App\Exceptions\AppException) {
$ex = new \Api\Core\Exception($e->getDisplayMessage(), $e->getCode(), $e);
} else {
$ex = new \Api\Core\Exception($e->getMessage(), $e->getCode(), $e);
}
$ex->handleError();
}
}
} catch (\Throwable $e) {
\App\Log::error($e->getMessage() . PHP_EOL . $e->__toString());
if (!headers_sent()) {
$ex = new \Api\Core\Exception($e->getMessage(), $e->getCode(), $e);
$ex->handleError();
}
}
\App\Log::endProfile(\App\Request::getRequestMethod() . '::' . $_SERVER['REQUEST_URI'], 'WebServiceAPI');