|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Anomaly\Streams\Platform\Application\Application; |
|
4
|
|
|
use Anomaly\Streams\Platform\Support\Parser; |
|
5
|
|
|
use Anomaly\Streams\Platform\Support\Str; |
|
6
|
|
|
use Anomaly\Streams\Platform\Support\Template; |
|
7
|
|
|
use Anomaly\Streams\Platform\Support\Value; |
|
8
|
|
|
use Illuminate\Support\Arr; |
|
9
|
|
|
use Illuminate\Support\Collection; |
|
10
|
|
|
|
|
11
|
|
|
if (!function_exists('app_storage_path')) { |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Get the storage path for the application. |
|
15
|
|
|
* |
|
16
|
|
|
* @param string $path |
|
17
|
|
|
* @return string |
|
18
|
|
|
*/ |
|
19
|
|
|
function app_storage_path($path = '') |
|
20
|
|
|
{ |
|
21
|
|
|
/* @var Application $application */ |
|
22
|
|
|
$application = app(Application::class); |
|
23
|
|
|
|
|
24
|
|
|
return storage_path('streams/' . $application->getReference()) . ($path ? '/' . $path : $path); |
|
25
|
|
|
} |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
if (!function_exists('str_humanize')) { |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Humanize the string. |
|
32
|
|
|
* |
|
33
|
|
|
* @param $target |
|
34
|
|
|
* @param string $separator |
|
35
|
|
|
* @return string |
|
36
|
|
|
*/ |
|
37
|
|
|
function str_humanize($target, $separator = '_') |
|
|
|
|
|
|
38
|
|
|
{ |
|
39
|
|
|
return app(Str::class)->humanize($target, $separator); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
if (!function_exists('parse')) { |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Parse the target with data. |
|
47
|
|
|
* |
|
48
|
|
|
* @param $target |
|
49
|
|
|
* @param array $data |
|
50
|
|
|
* @return mixed The parsed target. |
|
51
|
|
|
*/ |
|
52
|
|
|
function parse($target, array $data = []) |
|
|
|
|
|
|
53
|
|
|
{ |
|
54
|
|
|
return app(Parser::class)->parse($target, $data); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
if (!function_exists('render')) { |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Render the string template. |
|
62
|
|
|
* |
|
63
|
|
|
* @param $template |
|
64
|
|
|
* @param array $payload |
|
65
|
|
|
* @return string |
|
66
|
|
|
*/ |
|
67
|
|
|
function render($template, array $payload = []) |
|
|
|
|
|
|
68
|
|
|
{ |
|
69
|
|
|
return app(Template::class)->render($template, $payload); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
if (!function_exists('valuate')) { |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Make a valuation. |
|
77
|
|
|
* |
|
78
|
|
|
* @param $parameters |
|
79
|
|
|
* @param $entry |
|
80
|
|
|
* @param string $term |
|
81
|
|
|
* @param array $payload |
|
82
|
|
|
* @return mixed |
|
83
|
|
|
*/ |
|
84
|
|
|
function valuate($parameters, $entry, $term = 'entry', $payload = []) |
|
|
|
|
|
|
85
|
|
|
{ |
|
86
|
|
|
return app(Value::class)->make($parameters, $entry, $term, $payload); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
if (!function_exists('data')) { |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Get an item from an array or object using "dot" notation. |
|
94
|
|
|
* |
|
95
|
|
|
* @param mixed $target |
|
96
|
|
|
* @param string|array $key |
|
97
|
|
|
* @param mixed $default |
|
98
|
|
|
* @return mixed |
|
99
|
|
|
*/ |
|
100
|
|
|
function data($target, $key, $default = null) |
|
|
|
|
|
|
101
|
|
|
{ |
|
102
|
|
|
if (is_null($key)) { |
|
103
|
|
|
return $target; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
$key = is_array($key) ? $key : explode('.', $key); |
|
107
|
|
|
|
|
108
|
|
|
while (!is_null($segment = array_shift($key))) { |
|
109
|
|
|
if ($segment === '*') { |
|
110
|
|
|
if ($target instanceof Collection) { |
|
111
|
|
|
$target = $target->all(); |
|
112
|
|
|
} elseif (!is_array($target)) { |
|
113
|
|
|
return value($default); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
$result = Arr::pluck($target, $key); |
|
117
|
|
|
|
|
118
|
|
|
return in_array('*', $key) ? Arr::collapse($result) : $result; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
if (Arr::accessible($target) && Arr::exists($target, $segment)) { |
|
122
|
|
|
$target = $target[$segment]; |
|
123
|
|
|
} elseif (is_object($target) && isset($target->{$segment})) { |
|
124
|
|
|
$target = $target->{$segment}; |
|
125
|
|
|
} elseif (is_object($target) && method_exists($target, $segment)) { |
|
126
|
|
|
// This is different than laravel.. |
|
127
|
|
|
$target = call_user_func([$target, $segment]); |
|
128
|
|
|
} else { |
|
129
|
|
|
return value($default); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
return $target; |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
if (!function_exists('filesize')) { |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Humanize the filesizes |
|
141
|
|
|
* |
|
142
|
|
|
* @param integer $bytes The bytes |
|
143
|
|
|
* @param integer $decimals The decimals |
|
144
|
|
|
* @return string |
|
145
|
|
|
*/ |
|
146
|
|
|
function filesize($bytes, $decimals = 2) |
|
147
|
|
|
{ |
|
148
|
|
|
$size = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; |
|
149
|
|
|
$factor = floor((strlen($bytes) - 1) / 3); |
|
150
|
|
|
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)).' '.@$size[$factor]; |
|
151
|
|
|
} |
|
152
|
|
|
} |
|
153
|
|
|
|
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.