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