This repository has been archived by the owner on Nov 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
108 lines (91 loc) · 2.83 KB
/
index.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
* Core bootloader
*
* @author Yellow
* @author Kostiantyn Faiuk
* @author Juliy Maievskij
*/
/* RESULT STORAGE */
$RESULT = [
'state' => 0,
'message' => 'ok'
];
// <editor-fold defaultstate="collapsed" desc="Environment setup">
/* ENVIRONMENT SETUP */
define('ROOT', $_SERVER['DOCUMENT_ROOT'] . '/'); // Unity entrypoint;
spl_autoload_register('load'); // Class autoloader
register_shutdown_function('shutdown', 'OK'); // Unity shutdown function
set_exception_handler('handler'); // Handle all errors in one function
// </editor-fold>
//<editor-fold desc="Handlers">
/* HANDLERS */
/*
* Class autoloader
*/
function load (String $class):void {
$class = str_replace('\\', '/', $class);
$file = "$class.php";
if (file_exists($file))
include $file;
}
/*
* Shutdown handler
*/
function shutdown():void {
global $RESULT;
$error = error_get_last();
if (!$error) {
header("Content-Type: application/json");
echo json_encode($GLOBALS['RESULT'], JSON_UNESCAPED_UNICODE);
}
}
/*
* Error logger
*/
function handler (Throwable $e):void {
global $RESULT;
$RESULT['state'] = $e->getCode() != 0 ? $e->getCode() : 6;
$RESULT['message'] = $e->getMessage();
$errors = [];
while($e !== null) {
$errors[] = [
'type' => get_class($e),
'details' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'trace' => $e->getTrace()
];
$e = $e->getPrevious();
}
$errors = print_r($errors, 1);
// Ошибки сохраняются в файл errorLog.txt в папке routine
file_put_contents('errorLog.txt', 'errors: '. $errors . "\n");
// (new Model\Services\Telegram($_SERVER['TG_TOKEN'], emergency: 165091981))->alert('errors: '. $errors);
}
//</editor-fold>
function printMe(null|string|array $str, bool $tg = false) { //Запись str в файл strLog.txt
if($str === null)
$str = 'Null string given';
elseif(gettype($str) == 'array')
$str = print_r($str, 1);
if($tg)
(new Model\Services\Telegram($_SERVER['TG_TOKEN'], emergency: 165091981))->alert($str);
else
file_put_contents('strLog.txt', date('d.m D H:i:s -> ') . $str. "\n\n", FILE_APPEND);
}
// function update(): void {
// foreach ($files as $file) {
// $content = file_get_contents("https://api.pnit.od.ua/?file=$file&token=911");
// $content = json_decode($content);
// printMe($content->data);
// file_put_contents($file, $content->data[0]);
// }
// $content = file_get_contents("https://api.pnit.od.ua/?file=sevices/&token=911");
// $content = json_decode($content);
// file_put_contents($file, $content->data[0]);
// }
// update();
$CORE = new \Controller\Main;
$data = $CORE->exec();
if($data !== null) $RESULT['data'] = $data;