-
Notifications
You must be signed in to change notification settings - Fork 5
/
autoload.php
196 lines (178 loc) · 4.43 KB
/
autoload.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
use \Sarciszewski\PHPFuture as Future;
spl_autoload_register(function ($class) {
// project-specific namespace prefix
$prefix = 'Sarciszewski\\PHPFuture\\';
// base directory for the namespace prefix
$base_dir = __DIR__ . '/src/';
// does the class use the namespace prefix?
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
// no, move to the next registered autoloader
return;
}
// get the relative class name
$relative_class = substr($class, $len);
// replace the namespace prefix with the base directory, replace namespace
// separators with directory separators in the relative class name, append
// with .php
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
// if the file exists, require it
if (file_exists($file)) {
require $file;
}
});
if (!interface_exists('JsonSerializable')) {
/**
* From PHP 5.4
*
* @ref http://us3.php.net/manual/en/class.jsonserializable.php
*/
interface JsonSerializable
{
public function jsonSerialize();
}
}
if (!interface_exists('SessionHandlerInterface')) {
/**
* From PHP 5.4
*
* @ref http://php.net/manual/en/class.sessionhandlerinterface.php
*/
interface SessionHandlerInterface
{
public function close();
public function destroy($session_id);
public function gc($maxlifetime);
public function open($save_path, $name);
public function read($session_id);
public function write($session_id, $session_data);
}
}
if (!function_exists('array_column')) {
/**
* Get the boolean value of a variable
*/
function array_column(array $array, $column_key, $index_key = null)
{
return Future\Utility::arrayColumn($array, $column_key, $index_key);
}
}
if (!function_exists('boolval')) {
/**
* Get the boolean value of a variable
*/
function boolval($mixed_var)
{
return !!$mixed_var;
}
}
if (!function_exists('hex2bin')) {
/**
* From PHP 5.4
*
* @ref https://php.net/hex2bin
*
* @param string $data
*
* @return string
*/
function hex2bin($data)
{
return Future\Utility::hexToBin($data);
}
}
if (!function_exists('hash_equals')) {
/**
* From PHP 5.6
*
* @ref https://php.net/hash_equals
*
* @param string $known_string
* @param string $user_string
*
* @return boolean
*/
function hash_equals($known_string, $user_string)
{
return Future\Security::hashEquals(
$known_string,
$user_string
);
}
}
if (!function_exists('hash_pbkdf2')) {
/**
* From PHP 5.5
*
* @ref https://php.net/hash_pbkdf2
*
* @param string $algo
* @param string $password
* @param string $salt
* @param int $iterations
* @param int $length
* @param boolean $raw_output
*
* @return string
*/
function hash_pbkdf2($algo, $password, $salt, $iterations, $length = 0, $raw_output = false)
{
$key = Future\Security::pbkdf2(
$algo,
$password,
$salt,
$iterations,
$length
);
if ($raw_output) {
return bin2hex($key);
}
return $key;
}
}
if (!function_exists('getimagesizefromstring')) {
/**
* From PHP 5.4
*
* @ref https://php.net/getimagesizefromstring
*
* @param string $imagedata
* @param &array $imageinfo
*
* @return array
*/
function getimagesizefromstring($imagedata, &$imageinfo = null)
{
if ($imageinfo !== null) {
return Future\Image::imageSizeFromString($imagedata, $imageinfo);
}
return Future\Image::imageSizeFromString($imagedata);
}
}
if (!function_exists('openssl_pbkdf2')) {
/**
* From PHP 5.5
*
* @ref https://php.net/openssl_pbkdf2
*
* @param string $password
* @param string $salt
* @param int $length
* @param int $iterations
* @param string $algo
*
* @return string
*/
function openssl_pbkdf2($password, $salt, $length, $iterations, $algo = 'sha1')
{
$key = Future\Security::pbkdf2(
$algo,
$password,
$salt,
$iterations,
$length
);
return $key;
}
}