Completed
Pull Request — master (#2433)
by
unknown
02:45
created

helpers.php ➔ app_url()   A

Complexity

Conditions 5
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 2
nop 0
dl 0
loc 14
rs 9.4888
c 0
b 0
f 0
1
<?php
2
3
use Illuminate\Support\MessageBag;
4
5
if (!function_exists('admin_path')) {
6
7
    /**
8
     * Get admin path.
9
     *
10
     * @param string $path
11
     *
12
     * @return string
13
     */
14
    function admin_path($path = '')
15
    {
16
        return ucfirst(config('admin.directory')).($path ? DIRECTORY_SEPARATOR.$path : $path);
17
    }
18
}
19
20
if (!function_exists('admin_url')) {
21
    /**
22
     * Get admin url.
23
     *
24
     * @param string $path
25
     * @param mixed  $parameters
26
     * @param bool   $secure
27
     *
28
     * @return string
29
     */
30
    function admin_url($path = '', $parameters = [], $secure = null)
31
    {
32
        if (\Illuminate\Support\Facades\URL::isValidUrl($path)) {
33
            return $path;
34
        }
35
36
        $secure = $secure ?: (config('admin.https') || config('admin.secure'));
37
38
        return url(admin_base_path($path), $parameters, $secure);
39
    }
40
}
41
42
if (!function_exists('admin_base_path')) {
43
    /**
44
     * Get admin url.
45
     *
46
     * @param string $path
47
     *
48
     * @return string
49
     */
50
    function admin_base_path($path = '')
51
    {
52
        $prefix = '/'.trim(config('admin.route.prefix'), '/');
53
54
        $prefix = ($prefix == '/') ? '' : $prefix;
55
56
        return $prefix.'/'.trim($path, '/');
57
    }
58
59
    function app_url()
60
    {
61
        $app_url = config('app.url');
62
63
        $parsed_url = parse_url($app_url);
64
        if (!isset($parsed_url['port'])
65
            && ($_SERVER['SERVER_PORT'] != ''
66
                && $_SERVER['SERVER_PORT'] != 80
67
                && $_SERVER['SERVER_PORT'] != 443)) {
68
            $app_url = preg_replace('/([^\/:])(\/|$)/', '\1:'.$_SERVER['SERVER_PORT'].'/', $app_url, 1);
69
        }
70
71
        return $app_url;
72
    }
73
}
74
75 View Code Duplication
if (!function_exists('admin_toastr')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
77
    /**
78
     * Flash a toastr message bag to session.
79
     *
80
     * @param string $message
81
     * @param string $type
82
     * @param array  $options
83
     */
84
    function admin_toastr($message = '', $type = 'success', $options = [])
85
    {
86
        $toastr = new MessageBag(get_defined_vars());
87
88
        session()->flash('toastr', $toastr);
89
    }
90
}
91
92
if (!function_exists('admin_success')) {
93
94
    /**
95
     * Flash a success message bag to session.
96
     *
97
     * @param string $title
98
     * @param string $message
99
     */
100
    function admin_success($title, $message = '')
101
    {
102
        admin_info($title, $message, 'success');
103
    }
104
}
105
106
if (!function_exists('admin_error')) {
107
108
    /**
109
     * Flash a error message bag to session.
110
     *
111
     * @param string $title
112
     * @param string $message
113
     */
114
    function admin_error($title, $message = '')
115
    {
116
        admin_info($title, $message, 'error');
117
    }
118
}
119
120
if (!function_exists('admin_warning')) {
121
122
    /**
123
     * Flash a warning message bag to session.
124
     *
125
     * @param string $title
126
     * @param string $message
127
     */
128
    function admin_warning($title, $message = '')
129
    {
130
        admin_info($title, $message, 'warning');
131
    }
132
}
133
134 View Code Duplication
if (!function_exists('admin_info')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
135
136
    /**
137
     * Flash a message bag to session.
138
     *
139
     * @param string $title
140
     * @param string $message
141
     * @param string $type
142
     */
143
    function admin_info($title, $message = '', $type = 'info')
144
    {
145
        $message = new MessageBag(get_defined_vars());
146
147
        session()->flash($type, $message);
148
    }
149
}
150
151
if (!function_exists('admin_asset')) {
152
153
    /**
154
     * @param $path
155
     *
156
     * @return string
157
     */
158
    function admin_asset($path)
159
    {
160
        return asset($path, (config('admin.https') || config('admin.secure')));
161
    }
162
}
163
164
if (!function_exists('array_delete')) {
165
166
    /**
167
     * Delete from array by value.
168
     *
169
     * @param array $array
170
     * @param mixed $value
171
     */
172
    function array_delete(&$array, $value)
173
    {
174
        foreach ($array as $index => $item) {
175
            if ($value == $item) {
176
                unset($array[$index]);
177
            }
178
        }
179
    }
180
}
181