-
Notifications
You must be signed in to change notification settings - Fork 32
/
helper.php
95 lines (80 loc) · 2.08 KB
/
helper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
use tadmin\model\Config;
if (!function_exists('script_path')) {
function script_path()
{
if ('cli' == PHP_SAPI) {
$scriptName = realpath($_SERVER['argv'][0]);
} else {
$scriptName = $_SERVER['SCRIPT_FILENAME'];
}
return realpath(dirname($scriptName)) . '/';
}
}
if (!function_exists('app_path')) {
function app_path($path = '')
{
return env('app_path') . ltrim($path, '/');
}
}
if (!function_exists('public_path')) {
function public_path($path = '')
{
return script_path() . ltrim($path, '/');
// return app_path('../public/').ltrim($path, '/');
}
}
if (!function_exists('admin_path')) {
function admin_path($path = '')
{
return __DIR__ . '/' . ltrim($path, '/');
}
}
if (!function_exists('admin_config_path')) {
function admin_config_path($path = '')
{
return admin_path('config/') . ltrim($path, '/');
}
}
if (!function_exists('admin_route_path')) {
function admin_route_path($path = '')
{
return admin_path('route/') . ltrim($path, '/');
}
}
if (!function_exists('admin_view_path')) {
function admin_view_path($path = '')
{
return admin_path('resource/view/') . ltrim($path, '/');
}
}
if (!function_exists('site_config')) {
function site_config($key)
{
return Config::get($key);
}
}
if (!function_exists('array_deep_merge')) {
function array_deep_merge(array $a, array $b)
{
foreach ($a as $key => $val) {
if (isset($b[$key])) {
if (gettype($a[$key]) != gettype($b[$key])) {
continue;
}
if (is_array($a[$key])) {
$a[$key] = array_deep_merge($a[$key], $b[$key]);
} else {
$a[$key] = $b[$key];
}
}
}
return $a;
}
}
if (!function_exists('redirect_route')) {
function redirect_route(string $route = '', int $code = 302)
{
return redirect((string)url($route), $code);
}
}