-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathGeneral.php
More file actions
172 lines (150 loc) · 2.73 KB
/
General.php
File metadata and controls
172 lines (150 loc) · 2.73 KB
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
<?php
namespace Funct;
/**
* Checks if the given key or index exists in the array
*
*
* @param mixed $key
* @param array $array
*
* @return bool
* @author Aurimas Niekis <aurimas@niekis.lt>
*/
function arrayKeyNotExists($key, array $array)
{
return false === array_key_exists($key, $array);
}
/**
* Returns true if value is false
*
* @param mixed $value
*
* @return bool
* @author Aurimas Niekis <aurimas@niekis.lt>
*/
function false($value)
{
return false === $value;
}
/**
* Returns a first non null value from function arguments
*
* @param mixed $valueA
*
* @return mixed
* @author Aurimas Niekis <aurimas@niekis.lt>
*/
function firstValue($valueA)
{
foreach (func_get_args() as $arg) {
if (null !== $arg) {
return $arg;
}
}
}
/**
* Returns a first not empty value from function arguments
*
* @param mixed $valueA
* @param mixed $valueB
*
* @return mixed
* @author Aurimas Niekis <aurimas@niekis.lt>
*/
function firstValueNotEmpty($valueA, $valueB)
{
foreach (func_get_args() as $arg) {
if (notEmpty($arg)) {
return $arg;
}
}
}
/**
* Returns true if var is not empty
*
* @param mixed $value
*
* @return bool
* @author Aurimas Niekis <aurimas@niekis.lt>
*/
function notEmpty($value)
{
return false === empty($value);
}
/**
* Checks if needle is not in array
*
* @param $needle
* @param $haystack
* @param null $strict
*
* @return bool
* @author Aurimas Niekis <aurimas@niekis.lt>
*/
function notInArray($needle, $haystack, $strict = null)
{
return false === in_array($needle, $haystack, $strict);
}
/**
* Returns true if var is not null
*
* @param mixed $value
*
* @return bool
* @author Aurimas Niekis <aurimas@niekis.lt>
*/
function notNull($value)
{
return null !== $value;
}
/**
* Returns true if value is null
*
* @param mixed $value
*
* @return bool
* @author Aurimas Niekis <aurimas@niekis.lt>
*/
function null($value)
{
return null === $value;
}
/**
* Generates temp file on systems temp folder with prefix
*
* @param string $prefix
*
* @return string
* @author Aurimas Niekis <aurimas@niekis.lt>
*/
function tempFile($prefix = 'php')
{
return tempnam(sys_get_temp_dir(), $prefix);
}
/**
* Returns true if value is true
*
* @param mixed $value
*
* @return bool
* @author Aurimas Niekis <aurimas@niekis.lt>
*/
function true($value)
{
return true === $value;
}
/**
* Returns the first param if isset or the second one or null if it doesn't
*
* @param mixed $value
* @param mixed $default
* @return mixed
* @author Christophe Jean <cj@myjob.company>
*/
function ifSetOr(&$value, $default = null)
{
if (isset($value)) {
return $value;
}
return $default;
}