|
1
|
|
|
<?php |
|
2
|
|
|
/******************************************************************************** |
|
3
|
|
|
* Apache License, Version 2.0 * |
|
4
|
|
|
* * |
|
5
|
|
|
* Copyright [2020] [Nurlan Mukhanov <[email protected]>] * |
|
6
|
|
|
* * |
|
7
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); * |
|
8
|
|
|
* you may not use this file except in compliance with the License. * |
|
9
|
|
|
* You may obtain a copy of the License at * |
|
10
|
|
|
* * |
|
11
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 * |
|
12
|
|
|
* * |
|
13
|
|
|
* Unless required by applicable law or agreed to in writing, software * |
|
14
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, * |
|
15
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * |
|
16
|
|
|
* See the License for the specific language governing permissions and * |
|
17
|
|
|
* limitations under the License. * |
|
18
|
|
|
* * |
|
19
|
|
|
********************************************************************************/ |
|
20
|
|
|
|
|
21
|
|
|
declare(strict_types=1); |
|
22
|
|
|
|
|
23
|
|
|
namespace DBD\Entity\Common; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class Utils |
|
27
|
|
|
* |
|
28
|
|
|
* @package DBD\Entity\Common |
|
29
|
|
|
*/ |
|
30
|
|
|
class Utils |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* @param object $object |
|
34
|
|
|
* |
|
35
|
|
|
* @return array |
|
36
|
|
|
*/ |
|
37
|
|
|
public static function getObjectVars($object): array |
|
38
|
|
|
{ |
|
39
|
|
|
return get_object_vars($object); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param array $bigArray |
|
44
|
|
|
* @param array $smallArray |
|
45
|
|
|
* |
|
46
|
|
|
* @return array |
|
47
|
|
|
*/ |
|
48
|
|
|
public static function arrayDiff(array $bigArray, array $smallArray): array |
|
49
|
|
|
{ |
|
50
|
|
|
foreach ($smallArray as $key => $value) { |
|
51
|
|
|
if (isset($bigArray[$key])) { |
|
52
|
|
|
unset($bigArray[$key]); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return $bigArray; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Returns value as a boolean. |
|
61
|
|
|
* |
|
62
|
|
|
* @param $variable |
|
63
|
|
|
* |
|
64
|
|
|
* @return bool|null |
|
65
|
|
|
*/ |
|
66
|
|
|
public static function convertBoolVar($variable): ?bool |
|
67
|
|
|
{ |
|
68
|
|
|
if (is_string($variable)) { |
|
69
|
|
|
$variable = strtolower(trim($variable)); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
switch ($variable) { |
|
73
|
|
|
case 't': |
|
74
|
|
|
return true; |
|
75
|
|
|
case 'f': |
|
76
|
|
|
return false; |
|
77
|
|
|
default: |
|
78
|
|
|
return filter_var($variable, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|