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

helpers.php ➔ app_url()   A

Complexity

Conditions 6
Paths 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
nc 3
nop 0
dl 0
loc 17
rs 9.0777
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
        if (!isset($_SERVER['SERVER_PORT']))
64
            return $app_url;
65
66
        $parsed_url = parse_url($app_url);
67
        if (!isset($parsed_url['port'])
68
            && ($_SERVER['SERVER_PORT'] != ''
69
                && $_SERVER['SERVER_PORT'] != 80
70
                && $_SERVER['SERVER_PORT'] != 443)) {
71
            $app_url = preg_replace('/([^\/:])(\/|$)/', '\1:'.$_SERVER['SERVER_PORT'].'/', $app_url, 1);
72
        }
73
74
        return $app_url;
75
    }
76
}
77
78 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...
79
80
    /**
81
     * Flash a toastr message bag to session.
82
     *
83
     * @param string $message
84
     * @param string $type
85
     * @param array  $options
86
     */
87
    function admin_toastr($message = '', $type = 'success', $options = [])
88
    {
89
        $toastr = new MessageBag(get_defined_vars());
90
91
        session()->flash('toastr', $toastr);
92
    }
93
}
94
95
if (!function_exists('admin_success')) {
96
97
    /**
98
     * Flash a success message bag to session.
99
     *
100
     * @param string $title
101
     * @param string $message
102
     */
103
    function admin_success($title, $message = '')
104
    {
105
        admin_info($title, $message, 'success');
106
    }
107
}
108
109
if (!function_exists('admin_error')) {
110
111
    /**
112
     * Flash a error message bag to session.
113
     *
114
     * @param string $title
115
     * @param string $message
116
     */
117
    function admin_error($title, $message = '')
118
    {
119
        admin_info($title, $message, 'error');
120
    }
121
}
122
123
if (!function_exists('admin_warning')) {
124
125
    /**
126
     * Flash a warning message bag to session.
127
     *
128
     * @param string $title
129
     * @param string $message
130
     */
131
    function admin_warning($title, $message = '')
132
    {
133
        admin_info($title, $message, 'warning');
134
    }
135
}
136
137 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...
138
139
    /**
140
     * Flash a message bag to session.
141
     *
142
     * @param string $title
143
     * @param string $message
144
     * @param string $type
145
     */
146
    function admin_info($title, $message = '', $type = 'info')
147
    {
148
        $message = new MessageBag(get_defined_vars());
149
150
        session()->flash($type, $message);
151
    }
152
}
153
154
if (!function_exists('admin_asset')) {
155
156
    /**
157
     * @param $path
158
     *
159
     * @return string
160
     */
161
    function admin_asset($path)
162
    {
163
        return asset($path, (config('admin.https') || config('admin.secure')));
164
    }
165
}
166
167
if (!function_exists('array_delete')) {
168
169
    /**
170
     * Delete from array by value.
171
     *
172
     * @param array $array
173
     * @param mixed $value
174
     */
175
    function array_delete(&$array, $value)
176
    {
177
        foreach ($array as $index => $item) {
178
            if ($value == $item) {
179
                unset($array[$index]);
180
            }
181
        }
182
    }
183
}
184