1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Funct; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Checks if the given key or index exists in the array |
7
|
|
|
* |
8
|
|
|
* |
9
|
|
|
* @param mixed $key |
10
|
|
|
* @param array $array |
11
|
|
|
* |
12
|
|
|
* @return bool |
13
|
|
|
* @author Aurimas Niekis <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
function arrayKeyNotExists($key, array $array) |
16
|
|
|
{ |
17
|
1 |
|
return false === array_key_exists($key, $array); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Returns true if value is false |
23
|
|
|
* |
24
|
|
|
* @param mixed $value |
25
|
|
|
* |
26
|
|
|
* @return bool |
27
|
|
|
* @author Aurimas Niekis <[email protected]> |
28
|
|
|
*/ |
29
|
|
|
function false($value) |
30
|
|
|
{ |
31
|
2 |
|
return false === $value; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Returns a first non null value from function arguments |
37
|
|
|
* |
38
|
|
|
* @param mixed $valueA |
39
|
|
|
* |
40
|
|
|
* @return mixed |
41
|
|
|
* @author Aurimas Niekis <[email protected]> |
42
|
|
|
*/ |
43
|
|
|
function firstValue($valueA) |
|
|
|
|
44
|
|
|
{ |
45
|
4 |
|
foreach (func_get_args() as $arg) { |
46
|
4 |
|
if (null !== $arg) { |
47
|
3 |
|
return $arg; |
48
|
|
|
} |
49
|
2 |
|
} |
50
|
1 |
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Returns a first not empty value from function arguments |
55
|
|
|
* |
56
|
|
|
* @param mixed $valueA |
57
|
|
|
* @param mixed $valueB |
58
|
|
|
* |
59
|
|
|
* @return mixed |
60
|
|
|
* @author Aurimas Niekis <[email protected]> |
61
|
|
|
*/ |
62
|
|
|
function firstValueNotEmpty($valueA, $valueB) |
|
|
|
|
63
|
|
|
{ |
64
|
4 |
|
foreach (func_get_args() as $arg) { |
65
|
4 |
|
if (notEmpty($arg)) { |
66
|
3 |
|
return $arg; |
67
|
|
|
} |
68
|
3 |
|
} |
69
|
1 |
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Returns true if var is not empty |
74
|
|
|
* |
75
|
|
|
* @param mixed $value |
76
|
|
|
* |
77
|
|
|
* @return bool |
78
|
|
|
* @author Aurimas Niekis <[email protected]> |
79
|
|
|
*/ |
80
|
|
|
function notEmpty($value) |
81
|
|
|
{ |
82
|
7 |
|
return false === empty($value); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Checks if needle is not in array |
88
|
|
|
* |
89
|
|
|
* @param $needle |
90
|
|
|
* @param $haystack |
91
|
|
|
* @param null $strict |
92
|
|
|
* |
93
|
|
|
* @return bool |
94
|
|
|
* @author Aurimas Niekis <[email protected]> |
95
|
|
|
*/ |
96
|
|
|
function notInArray($needle, $haystack, $strict = null) |
97
|
|
|
{ |
98
|
1 |
|
return false === in_array($needle, $haystack, $strict); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Returns true if var is not null |
104
|
|
|
* |
105
|
|
|
* @param mixed $value |
106
|
|
|
* |
107
|
|
|
* @return bool |
108
|
|
|
* @author Aurimas Niekis <[email protected]> |
109
|
|
|
*/ |
110
|
|
|
function notNull($value) |
111
|
|
|
{ |
112
|
2 |
|
return null !== $value; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Returns true if value is null |
118
|
|
|
* |
119
|
|
|
* @param mixed $value |
120
|
|
|
* |
121
|
|
|
* @return bool |
122
|
|
|
* @author Aurimas Niekis <[email protected]> |
123
|
|
|
*/ |
124
|
|
|
function null($value) |
125
|
|
|
{ |
126
|
2 |
|
return null === $value; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Generates temp file on systems temp folder with prefix |
132
|
|
|
* |
133
|
|
|
* @param string $prefix |
134
|
|
|
* |
135
|
|
|
* @return string |
136
|
|
|
* @author Aurimas Niekis <[email protected]> |
137
|
|
|
*/ |
138
|
|
|
function tempFile($prefix = 'php') |
139
|
|
|
{ |
140
|
2 |
|
return tempnam(sys_get_temp_dir(), $prefix); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Returns true if value is true |
146
|
|
|
* |
147
|
|
|
* @param mixed $value |
148
|
|
|
* |
149
|
|
|
* @return bool |
150
|
|
|
* @author Aurimas Niekis <[email protected]> |
151
|
|
|
*/ |
152
|
|
|
function true($value) |
153
|
|
|
{ |
154
|
2 |
|
return true === $value; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Returns the first param if isset or the second one or null if it doesn't |
160
|
|
|
* |
161
|
|
|
* @param mixed $value |
162
|
|
|
* @param mixed $default |
163
|
|
|
* @return mixed |
164
|
|
|
* @author Christophe Jean <[email protected]> |
165
|
|
|
*/ |
166
|
|
|
function ifSetOr(&$value, $default = null) |
167
|
|
|
{ |
168
|
2 |
|
if (isset($value)) { |
169
|
1 |
|
return $value; |
170
|
|
|
} |
171
|
1 |
|
return $default; |
172
|
|
|
} |
173
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.