-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Adapterman.php
109 lines (90 loc) · 2.81 KB
/
Adapterman.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
<?php
/**
* This file is part of Adapterman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author Joan Miquel<https://github.com/joanhey>
* @copyright Joan Miquel<https://github.com/joanhey>
* @link https://github.com/joanhey/AdapterMan
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Adapterman;
use Workerman\Worker;
use Exception;
class Adapterman
{
public const VERSION = "0.6.1";
public const NAME = 'Adapterman/'. self::VERSION. ' (Workerman/'. Worker::VERSION. ')';
private const FUNCTIONS = [
'header',
'header_remove',
'headers_sent',
'headers_list',
'http_response_code',
'setcookie',
'session_create_id',
'session_id',
'session_name',
'session_save_path',
'session_status',
'session_start',
'session_write_close',
'session_regenerate_id',
'session_unset',
'session_get_cookie_params',
'session_set_cookie_params',
'set_time_limit',
];
public static function init(): void
{
try {
self::checkVersion();
self::checkFunctionsDisabled();
// OK initialize the functions
require __DIR__ . '/functions/AdapterFunctions.php';
require __DIR__ . '/functions/AdapterSessionFunctions.php';
class_alias(Http::class, \Protocols\Http::class);
Http::init();
} catch (Exception $e) {
fwrite(STDERR, self::NAME . ' Error:' . PHP_EOL);
fwrite(STDERR, $e->getMessage());
exit;
}
fwrite(STDOUT, self::NAME . ' OK' . PHP_EOL);
}
/**
* Check PHP version
*
* @throws Exception
* @return void
*/
private static function checkVersion(): void
{
if (\PHP_MAJOR_VERSION < 8) {
throw new Exception("* PHP version must be 8 or higher." . PHP_EOL . "* Actual PHP version: " . \PHP_VERSION . PHP_EOL);
}
}
/**
* Check that functions are disabled in php.ini
*
* @throws Exception
* @return void
*/
private static function checkFunctionsDisabled(): void
{
foreach (self::FUNCTIONS as $function) {
if (\function_exists($function)) {
throw new Exception("Functions not disabled in php.ini." . PHP_EOL . self::showConfiguration());
}
}
}
private static function showConfiguration(): string
{
$inipath = \php_ini_loaded_file();
$methods = \implode(',', self::FUNCTIONS);
return "Add in file: $inipath" . PHP_EOL . "disable_functions=$methods" . PHP_EOL;
}
}