|
13 | 13 | * file that was distributed with this source code.
|
14 | 14 | */
|
15 | 15 |
|
| 16 | +use Ease\Shared; |
| 17 | +use mServer\Client; |
| 18 | +use mServer\HttpException; |
| 19 | + |
| 20 | +/** |
| 21 | + * This file is part of the PohodaClientChecker package. |
| 22 | + * |
| 23 | + * https://github.com/Spoje-NET/pohoda-client-checker |
| 24 | + * |
| 25 | + * (c) Vítězslav Dvořák <http://vitexsoftware.com> |
| 26 | + * |
| 27 | + * For the full copyright and license information, please view the LICENSE |
| 28 | + * file that was distributed with this source code. |
| 29 | + */ |
| 30 | + |
16 | 31 | require_once '../vendor/autoload.php';
|
17 | 32 |
|
18 | 33 | \define('APP_NAME', 'mPohoda Check');
|
19 | 34 | $exitCode = 0;
|
| 35 | +$result = []; |
20 | 36 | $options = getopt('o::e::', ['output::', 'environment::']);
|
21 |
| -\Ease\Shared::init(['POHODA_URL', 'POHODA_USERNAME', 'POHODA_PASSWORD', 'POHODA_ICO'], \array_key_exists('environment', $options) ? $options['environment'] : '../.env'); |
22 |
| -$destination = \array_key_exists('output', $options) ? $options['output'] : \Ease\Shared::cfg('RESULT_FILE', 'php://stdout'); |
| 37 | +Shared::init(['POHODA_URL', 'POHODA_USERNAME', 'POHODA_PASSWORD', 'POHODA_ICO'], \array_key_exists('environment', $options) ? $options['environment'] : '../.env'); |
| 38 | +$destination = \array_key_exists('output', $options) ? $options['output'] : Shared::cfg('RESULT_FILE', 'php://stdout'); |
23 | 39 |
|
24 |
| -if (\Ease\Shared::cfg('EASE_LOGGER', false) === false) { |
| 40 | +if (Shared::cfg('EASE_LOGGER', false) === false) { |
25 | 41 | \define('EASE_LOGGER', 'console');
|
26 | 42 | }
|
27 | 43 |
|
28 |
| -$client = new \mServer\Client(); |
| 44 | +$client = new Client(); |
29 | 45 |
|
30 |
| -if (strtolower(\Ease\Shared::cfg('APP_DEBUG', 'false')) === 'true') { |
| 46 | +if (strtolower(Shared::cfg('APP_DEBUG', 'false')) === 'true') { |
31 | 47 | $client->logBanner();
|
32 | 48 | }
|
33 | 49 |
|
|
36 | 52 |
|
37 | 53 | if ($result['status'] === false) {
|
38 | 54 | $client->addStatusMessage(_('Connection').' problem', 'error');
|
39 |
| - $exitCode = 503; |
| 55 | + $exitCode = $client->lastResponseCode ? $client->lastResponseCode : 503 ; |
40 | 56 | }
|
41 |
| -} catch (\mServer\HttpException $ex) { |
| 57 | +} catch (HttpException $ex) { |
42 | 58 | $client->addStatusMessage($ex->getCode().': '.$ex->getMessage(), 'error');
|
43 |
| - $payments['message'] = $ex->getCode().': '.$ex->getMessage(); |
| 59 | + $result['message'] = $ex->getCode().': '.$ex->getMessage(); |
| 60 | + $result['diag'] = $client->curlInfo; |
44 | 61 | $result['status'] = false;
|
| 62 | + $exitCode = $client->lastResponseCode; |
45 | 63 | }
|
46 | 64 |
|
47 | 65 | $client->addStatusMessage(_('Connection').' '.($result['status'] ? 'OK' : 'problem'), $result['status'] ? 'success' : 'error');
|
|
72 | 90 | }
|
73 | 91 | }
|
74 | 92 |
|
75 |
| -$written = file_put_contents($destination, json_encode($result, \Ease\Shared::cfg('DEBUG') ? \JSON_PRETTY_PRINT : 0)); |
| 93 | +$written = file_put_contents($destination, json_encode($result, Shared::cfg('APP_DEBUG') ? \JSON_PRETTY_PRINT : 0)); |
76 | 94 | $client->addStatusMessage(sprintf(_('Saving result to %s'), $destination), $written ? 'success' : 'error');
|
77 | 95 |
|
78 | 96 | exit($exitCode ?: ($written ? 0 : 1));
|
0 commit comments