Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/aimogen-pro/update-checker/Puc/v5p6/Utils.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
namespace YahnisElsts\PluginUpdateChecker\v5p6;
3
+
4
+
if ( !class_exists(Utils::class, false) ):
5
+
6
+
class Utils {
7
+
/**
8
+
* Get a value from a nested array or object based on a path.
9
+
*
10
+
* @param array|object|null $collection Get an entry from this array.
11
+
* @param array|string $path A list of array keys in hierarchy order, or a string path like "foo.bar.baz".
12
+
* @param mixed $default The value to return if the specified path is not found.
13
+
* @param string $separator Path element separator. Only applies to string paths.
14
+
* @return mixed
15
+
*/
16
+
public static function get($collection, $path, $default = null, $separator = '.') {
17
+
if ( is_string($path) ) {
18
+
$path = explode($separator, $path);
19
+
}
20
+
21
+
//Follow the $path into $input as far as possible.
22
+
$currentValue = $collection;
23
+
foreach ($path as $node) {
24
+
if ( is_array($currentValue) && isset($currentValue[$node]) ) {
25
+
$currentValue = $currentValue[$node];
26
+
} else if ( is_object($currentValue) && isset($currentValue->$node) ) {
27
+
$currentValue = $currentValue->$node;
28
+
} else {
29
+
return $default;
30
+
}
31
+
}
32
+
33
+
return $currentValue;
34
+
}
35
+
36
+
/**
37
+
* Get the first array element that is not empty.
38
+
*
39
+
* @param array $values
40
+
* @param mixed|null $default Returns this value if there are no non-empty elements.
41
+
* @return mixed|null
42
+
*/
43
+
public static function findNotEmpty($values, $default = null) {
44
+
if ( empty($values) ) {
45
+
return $default;
46
+
}
47
+
48
+
foreach ($values as $value) {
49
+
if ( !empty($value) ) {
50
+
return $value;
51
+
}
52
+
}
53
+
54
+
return $default;
55
+
}
56
+
57
+
/**
58
+
* Check if the input string starts with the specified prefix.
59
+
*
60
+
* @param string $input
61
+
* @param string $prefix
62
+
* @return bool
63
+
*/
64
+
public static function startsWith($input, $prefix) {
65
+
$length = strlen($prefix);
66
+
return (substr($input, 0, $length) === $prefix);
67
+
}
68
+
}
69
+
70
+
endif;
71
+