1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Illuminate\Support\HtmlString; |
4
|
|
|
use Illuminate\Container\Container; |
5
|
|
|
|
6
|
|
|
if (! function_exists('app')) { |
7
|
|
|
/** |
8
|
|
|
* Get the available container instance. |
9
|
|
|
* |
10
|
|
|
* @param string|null $make |
11
|
|
|
* @param array $parameters |
12
|
|
|
* @return mixed|\LumenWpApp\Application |
13
|
|
|
*/ |
14
|
|
|
function app($make = null, array $parameters = []) |
15
|
|
|
{ |
16
|
|
|
if (is_null($make)) { |
17
|
|
|
return Container::getInstance(); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
return Container::getInstance()->make($make, $parameters); |
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
if (! function_exists('base_path')) { |
25
|
|
|
/** |
26
|
|
|
* Get the path to the base of the install. |
27
|
|
|
* |
28
|
|
|
* @param string $path |
29
|
|
|
* @return string |
30
|
|
|
*/ |
31
|
|
|
function base_path($path = '') |
32
|
|
|
{ |
33
|
|
|
return app()->basePath().($path ? '/'.$path : $path); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
if (! function_exists('config')) { |
38
|
|
|
/** |
39
|
|
|
* Get / set the specified configuration value. |
40
|
|
|
* |
41
|
|
|
* If an array is passed as the key, we will assume you want to set an array of values. |
42
|
|
|
* |
43
|
|
|
* @param array|string|null $key |
44
|
|
|
* @param mixed $default |
45
|
|
|
* @return mixed |
46
|
|
|
*/ |
47
|
|
|
function config($key = null, $default = null) |
48
|
|
|
{ |
49
|
|
|
if (is_null($key)) { |
50
|
|
|
return app('config'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if (is_array($key)) { |
54
|
|
|
return app('config')->set($key); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return app('config')->get($key, $default); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if (! function_exists('resource_path')) { |
62
|
|
|
/** |
63
|
|
|
* Get the path to the resources folder. |
64
|
|
|
* |
65
|
|
|
* @param string $path |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
|
|
function resource_path($path = '') |
69
|
|
|
{ |
70
|
|
|
return app()->resourcePath($path); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
if (! function_exists('storage_path')) { |
75
|
|
|
/** |
76
|
|
|
* Get the path to the storage folder. |
77
|
|
|
* |
78
|
|
|
* @param string $path |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
|
|
function storage_path($path = '') |
82
|
|
|
{ |
83
|
|
|
return app()->storagePath($path); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
if (! function_exists('trans')) { |
88
|
|
|
/** |
89
|
|
|
* Translate the given message. |
90
|
|
|
* |
91
|
|
|
* @param string|null $id |
92
|
|
|
* @param array $replace |
93
|
|
|
* @param string|null $locale |
94
|
|
|
* @return \Illuminate\Contracts\Translation\Translator|string|array|null |
95
|
|
|
*/ |
96
|
|
|
function trans($id = null, $replace = [], $locale = null) |
97
|
|
|
{ |
98
|
|
|
if (is_null($id)) { |
99
|
|
|
return app('translator'); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return app('translator')->get($id, $replace, $locale); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
if (! function_exists('trans_choice')) { |
107
|
|
|
/** |
108
|
|
|
* Translates the given message based on a count. |
109
|
|
|
* |
110
|
|
|
* @param string $id |
111
|
|
|
* @param int|array|\Countable $number |
112
|
|
|
* @param array $replace |
113
|
|
|
* @param string|null $locale |
114
|
|
|
* @return string |
115
|
|
|
*/ |
116
|
|
|
function trans_choice($id, $number, array $replace = [], $locale = null) |
117
|
|
|
{ |
118
|
|
|
return app('translator')->choice($id, $number, $replace, $locale); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
if ( ! function_exists('mix')) { |
123
|
|
|
/** |
124
|
|
|
* Get the path to a versioned Mix file. |
125
|
|
|
* |
126
|
|
|
* @param string $path |
127
|
|
|
* @param string $manifestDirectory |
128
|
|
|
* |
129
|
|
|
* @return \Illuminate\Support\HtmlString |
130
|
|
|
* |
131
|
|
|
* @throws \Exception |
132
|
|
|
*/ |
133
|
|
|
function mix($path, $manifestDirectory = '') { |
134
|
|
|
static $manifest; |
135
|
|
|
|
136
|
|
|
if ( ! starts_with($path, '/')) { |
|
|
|
|
137
|
|
|
$path = "/{$path}"; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
if ($manifestDirectory && ! starts_with($manifestDirectory, '/')) { |
141
|
|
|
$manifestDirectory = "/{$manifestDirectory}"; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
if (file_exists(public_path($manifestDirectory . '/hot'))) { |
|
|
|
|
145
|
|
|
return new HtmlString("//localhost:8080{$path}"); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
if ( ! $manifest) { |
149
|
|
|
if ( ! file_exists($manifestPath = public_path($manifestDirectory . '/mix-manifest.json'))) { |
150
|
|
|
throw new Exception('The Mix manifest does not exist.'); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
$manifest = json_decode(file_get_contents($manifestPath), true); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
if ( ! array_key_exists($path, $manifest)) { |
157
|
|
|
throw new Exception( |
158
|
|
|
"Unable to locate Mix file: {$path}. Please check your " . |
159
|
|
|
'webpack.mix.js output paths and try again.' |
160
|
|
|
); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
return new HtmlString($manifestDirectory . $manifest[ $path ]); |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|