|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Jumilla\Addomnipot\Laravel\Environment as AddonEnvironment; |
|
4
|
|
|
|
|
5
|
|
|
if (!function_exists('runtime_get_caller_class')) { |
|
6
|
|
|
/** |
|
7
|
|
|
* @param int $level |
|
8
|
|
|
* |
|
9
|
|
|
* @return string |
|
10
|
|
|
*/ |
|
11
|
|
|
function runtime_get_caller_class($level = 1) |
|
|
|
|
|
|
12
|
|
|
{ |
|
13
|
|
|
$level += 1; |
|
14
|
|
|
|
|
15
|
|
|
$caller = debug_backtrace(0, $level)[$level - 1]; |
|
16
|
|
|
|
|
17
|
|
|
return array_get($caller, 'class'); |
|
18
|
|
|
} |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
if (!function_exists('addon')) { |
|
22
|
|
|
/** |
|
23
|
|
|
* @param string $name Addon name. |
|
24
|
|
|
* |
|
25
|
|
|
* @return \Jumilla\Addomnipot\Laravel\Addons\Addon |
|
26
|
|
|
*/ |
|
27
|
|
|
function addon($name = null) |
|
28
|
|
|
{ |
|
29
|
|
|
return app(AddonEnvironment::class)->addon($name ?: addon_name(2)); |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
if (!function_exists('addon_name')) { |
|
34
|
|
|
/** |
|
35
|
|
|
* @param string | int $class |
|
36
|
|
|
* |
|
37
|
|
|
* @return string |
|
38
|
|
|
*/ |
|
39
|
|
|
function addon_name($class = 1) |
|
|
|
|
|
|
40
|
|
|
{ |
|
41
|
|
|
if (is_numeric($class)) { |
|
42
|
|
|
$class = runtime_get_caller_class($class + 1); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$addons = app(AddonEnvironment::class)->addons(); |
|
46
|
|
|
|
|
47
|
|
|
// sort by length (DESC) |
|
48
|
|
|
usort($addons, function ($v1, $v2) { |
|
49
|
|
|
return strlen($v1->phpNamespace()) < strlen($v2->phpNamespace()) ? 1 : -1; |
|
50
|
|
|
}); |
|
51
|
|
|
|
|
52
|
|
|
foreach ($addons as $addon) { |
|
53
|
|
|
if (starts_with($class, $addon->phpNamespace().'\\')) { |
|
54
|
|
|
return $addon->name(); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
if (!function_exists('addon_path')) { |
|
63
|
|
|
/** |
|
64
|
|
|
* @param string $name Addon name. |
|
65
|
|
|
* @param string $path |
|
66
|
|
|
* |
|
67
|
|
|
* @return mixed |
|
68
|
|
|
*/ |
|
69
|
|
|
function addon_path($name, $path = null) |
|
|
|
|
|
|
70
|
|
|
{ |
|
71
|
|
|
return addon($name)->path($path); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
View Code Duplication |
if (!function_exists('addon_config')) { |
|
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param string $name Addon name. |
|
78
|
|
|
* @param string $key |
|
79
|
|
|
* @param mixed $value |
|
|
|
|
|
|
80
|
|
|
* |
|
81
|
|
|
* @return mixed |
|
82
|
|
|
*/ |
|
83
|
|
|
function addon_config($name, $key) |
|
|
|
|
|
|
84
|
|
|
{ |
|
85
|
|
|
return call_user_func_array([addon($name), 'config'], array_slice(func_get_args(), 1)); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
View Code Duplication |
if (!function_exists('addon_trans')) { |
|
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Translate the given message. |
|
92
|
|
|
* |
|
93
|
|
|
* @param string $name |
|
94
|
|
|
* @param string $id |
|
95
|
|
|
* @param array $parameters |
|
|
|
|
|
|
96
|
|
|
* @param string $domain |
|
|
|
|
|
|
97
|
|
|
* @param string $locale |
|
|
|
|
|
|
98
|
|
|
* |
|
99
|
|
|
* @return string |
|
100
|
|
|
*/ |
|
101
|
|
|
function addon_trans($name, $id) |
|
|
|
|
|
|
102
|
|
|
{ |
|
103
|
|
|
return call_user_func_array([addon($name), 'trans'], array_slice(func_get_args(), 1)); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
View Code Duplication |
if (!function_exists('addon_trans_choice')) { |
|
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Translates the given message based on a count. |
|
110
|
|
|
* |
|
111
|
|
|
* @param string $name |
|
112
|
|
|
* @param string $id |
|
113
|
|
|
* @param int $number |
|
|
|
|
|
|
114
|
|
|
* @param array $parameters |
|
|
|
|
|
|
115
|
|
|
* @param string $domain |
|
|
|
|
|
|
116
|
|
|
* @param string $locale |
|
|
|
|
|
|
117
|
|
|
* |
|
118
|
|
|
* @return string |
|
119
|
|
|
*/ |
|
120
|
|
|
function addon_trans_choice($name, $id) |
|
|
|
|
|
|
121
|
|
|
{ |
|
122
|
|
|
return call_user_func_array([addon($name), 'transChoice'], array_slice(func_get_args(), 1)); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
View Code Duplication |
if (!function_exists('addon_view')) { |
|
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Get the evaluated view contents for the given view. |
|
129
|
|
|
* |
|
130
|
|
|
* @param string $name |
|
131
|
|
|
* @param string $view |
|
132
|
|
|
* @param array $data |
|
|
|
|
|
|
133
|
|
|
* @param array $mergeData |
|
|
|
|
|
|
134
|
|
|
* |
|
135
|
|
|
* @return \Illuminate\View\View |
|
136
|
|
|
*/ |
|
137
|
|
|
function addon_view($name, $view) |
|
|
|
|
|
|
138
|
|
|
{ |
|
139
|
|
|
return call_user_func_array([addon($name), 'view'], array_slice(func_get_args(), 1)); |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
View Code Duplication |
if (!function_exists('addon_spec')) { |
|
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Get spec. |
|
146
|
|
|
* |
|
147
|
|
|
* @param string $name |
|
148
|
|
|
* @param string $path |
|
149
|
|
|
* |
|
150
|
|
|
* @return \Jumilla\Addomnipot\Laravel\Specs\InputSpec |
|
151
|
|
|
*/ |
|
152
|
|
|
function addon_spec($name, $path) |
|
|
|
|
|
|
153
|
|
|
{ |
|
154
|
|
|
return call_user_func_array([addon($name), 'spec'], array_slice(func_get_args(), 1)); |
|
155
|
|
|
} |
|
156
|
|
|
} |
|
157
|
|
|
|
Learn more about camelCase.