/
core.php
135 lines (118 loc) · 3.41 KB
/
core.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
<?php
namespace Keruald;
use Keruald\OmniTools\Debug\Debugger;
use Keruald\OmniTools\Identifiers\UUID;
use Keruald\OmniTools\Network\IP;
use Keruald\OmniTools\HTTP\Requests\RemoteAddress;
use Keruald\OmniTools\HTTP\Requests\Request;
use Keruald\OmniTools\Strings\Multibyte\StringUtilities;
/**
* Keruald, core libraries for Pluton and Xen engines.
*
* Global functions
*/
///
/// Strings
///
/**
* Pads a multibytes string to a certain length with another string
*
* @param string $input the input string
* @param int $pad_length the target string size
* @param string $pad_string the padding characters (optional, default is space)
* @param int $pad_type STR_PAD_RIGHT, STR_PAD_LEFT, or STR_PAD_BOTH (optional, default is STR_PAD_RIGHT)
* @param string $encoding the character encoding (optional)
*
* @return string the padded string
* @deprecated Use Keruald\OmniTools\Strings\Multibyte\StringUtilities::pad
*/
function mb_str_pad($input, $pad_length, $pad_string = ' ', $pad_type = STR_PAD_RIGHT, $encoding = null) {
return StringUtilities::pad($input, $pad_length, $pad_string, $pad_type, $encoding);
}
/**
* Determines whether the specified is a valid IP address
*
* @param string $string the string to validate as an IP
* @return bool true if the specified string is a valid IP address; otherwise, false
* @deprecated Use Keruald\OmniTools\Network\IP::isIP
*/
function is_ip ($string) {
return IP::isIP($string);
}
/**
* Determines whether the specified is a valid IPv4 address
*
* @param string $string the string to validate as an IP
* @return bool true if the specified string is a valid IPv4 address; otherwise, false
* @deprecated Use Keruald\OmniTools\Network\IP::isIPv4
*/
function is_ipv4 ($string) {
return IP::isIPv4($string);
}
/**
* Determines whether the specified is a valid IPv6 address
*
* @param string $string the string to validate as an IP
* @return bool true if the specified string is a valid IPv6 address; otherwise, false
* @deprecated Use Keruald\OmniTools\Network\IP::isIPv6
*/
function is_ipv6 ($string) {
return IP::isIPv6($string);
}
///
/// Identifiers
///
/**
* Generates a RFC 4211 compliant v4 UUID (random-based)
*
* @return string the UUID
* @deprecated Use Keruald\OmniTools\Identifiers\UUID::UUIDv4
*/
function uuid () {
return UUID::UUIDv4();
}
///
/// Error and debug
///
/**
* Prints human-readable information about a variable, wrapped in a <pre> block
*
* @param mixed $variable the variable to dump
*/
function dprint_r ($variable) {
Debugger::printVariable($variable);
}
/**
* Prints human-readable information about a variable, wrapped in a <pre> block
* then dies
*
* @param mixed $variable the variable to dump
*/
function dieprint_r ($variable) {
Debugger::printVariableAndDie($variable);
}
///
/// Client information
///
/**
* Returns the full header or the IP part of it
*
* @param string $value the header value
* @return string the IP part
* @deprecated
*/
function extract_client_ip_from_header ($value) {
return (new RemoteAddress($value))->getClientAddress();
}
/**
* Gets remote IP address.
*
* This is intended as a drop-in replacement for $_SERVER['REMOTE_ADDR'],
* which takes in consideration proxy values, blindly trusted.
*
* @return string the remote address
* @deprecated Use Keruald\OmniTools\HTTP\Requests\Request::getRemoteAddress()
*/
function get_remote_addr () {
return Request::getRemoteAddress();
}