1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use IlluminateAgnostic\Str\Support\Arr; |
4
|
|
|
use IlluminateAgnostic\Str\Support\Str; |
5
|
|
|
use IlluminateAgnostic\Str\Support\Collection; |
6
|
|
|
use IlluminateAgnostic\Str\Support\Debug\Dumper; |
7
|
|
|
|
8
|
|
|
if (!class_exists(Illuminate\Support\Collection::class)) { |
9
|
|
|
if (!function_exists('collect')) { |
10
|
|
|
/** |
11
|
|
|
* Create a collection from the given value. |
12
|
|
|
* |
13
|
|
|
* @param mixed $value |
14
|
|
|
* @return \IlluminateAgnostic\Str\Support\Collection|\Illuminate\Support\Collection |
15
|
|
|
*/ |
16
|
|
|
function collect($value = null) |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
return new Collection($value); |
19
|
|
|
} |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
if (!function_exists('data_get')) { |
23
|
|
|
/** |
24
|
|
|
* Get an item from an array or object using "dot" notation. |
25
|
|
|
* |
26
|
|
|
* @param mixed $target |
27
|
|
|
* @param string|array $key |
28
|
|
|
* @param mixed $default |
29
|
|
|
* @return mixed |
30
|
|
|
*/ |
31
|
5 |
|
function data_get($target, $key, $default = null) |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
if (is_null($key)) { |
34
|
|
|
return $target; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
$key = is_array($key) ? $key : explode('.', $key); |
38
|
|
|
|
39
|
|
|
while (!is_null($segment = array_shift($key))) { |
40
|
|
|
if ($segment === '*') { |
41
|
|
|
if ($target instanceof Collection) { |
42
|
|
|
$target = $target->all(); |
43
|
|
|
} elseif (!is_array($target)) { |
44
|
|
|
return value($default); |
45
|
|
|
} |
46
|
98 |
|
|
47
|
26 |
|
$result = Arr::pluck($target, $key); |
48
|
|
|
|
49
|
|
|
return in_array('*', $key) |
50
|
86 |
|
? Arr::collapse($result) |
51
|
|
|
: $result; |
52
|
86 |
|
} |
53
|
86 |
|
|
54
|
1 |
|
if ( |
55
|
|
|
Arr::accessible($target) && |
56
|
1 |
|
Arr::exists($target, $segment) |
57
|
|
|
) { |
58
|
|
|
$target = $target[$segment]; |
59
|
|
|
} elseif (is_object($target) && isset($target->{$segment})) { |
60
|
1 |
|
$target = $target->{$segment}; |
61
|
|
|
} else { |
62
|
1 |
|
return value($default); |
63
|
|
|
} |
64
|
1 |
|
} |
65
|
|
|
|
66
|
|
|
return $target; |
67
|
|
|
} |
68
|
86 |
|
} |
69
|
86 |
|
|
70
|
|
|
if (!function_exists('value')) { |
71
|
72 |
|
/** |
72
|
29 |
|
* Return the default value of the given value. |
73
|
25 |
|
* |
74
|
|
|
* @param mixed $value |
75
|
8 |
|
* @return mixed |
76
|
|
|
*/ |
77
|
|
|
function value($value) |
|
|
|
|
78
|
|
|
{ |
79
|
86 |
|
return $value instanceof Closure ? $value() : $value; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if (!function_exists('dd')) { |
84
|
|
|
/** |
85
|
|
|
* Dump the passed variables and end the script. |
86
|
|
|
* |
87
|
|
|
* @param mixed $args |
88
|
|
|
* @return void |
89
|
|
|
*/ |
90
|
|
|
function dd(...$args) |
|
|
|
|
91
|
|
|
{ |
92
|
|
|
http_response_code(500); |
93
|
|
|
|
94
|
|
|
foreach ($args as $x) { |
95
|
|
|
(new Dumper())->dump($x); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
die(1); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.