|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use System\Application; |
|
4
|
|
|
use System\File; |
|
5
|
|
|
|
|
6
|
|
|
if (!function_exists('app')) { |
|
7
|
|
|
/** |
|
8
|
|
|
* Get Application instance |
|
9
|
|
|
* |
|
10
|
|
|
* @param \System\File $file |
|
|
|
|
|
|
11
|
|
|
* @return \System\Application |
|
12
|
|
|
*/ |
|
13
|
|
|
function app() |
|
14
|
|
|
{ |
|
15
|
|
|
return Application::getInstance(new File(__DIR__)); |
|
16
|
|
|
} |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
if (!function_exists('pre')) { |
|
20
|
|
|
/** |
|
21
|
|
|
* Display the give $input |
|
22
|
|
|
* |
|
23
|
|
|
* @param string $input |
|
24
|
|
|
* @return string |
|
25
|
|
|
*/ |
|
26
|
|
|
function pre($input) |
|
27
|
|
|
{ |
|
28
|
|
|
echo '<pre>'; |
|
29
|
|
|
print_r($input); |
|
30
|
|
|
echo '</pre>'; |
|
31
|
|
|
} |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
if (!function_exists('sp')) { |
|
35
|
|
|
/** |
|
36
|
|
|
* Echo ====== |
|
37
|
|
|
* |
|
38
|
|
|
* @return void |
|
39
|
|
|
*/ |
|
40
|
|
|
function sp() |
|
41
|
|
|
{ |
|
42
|
|
|
echo '============================'; |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
if (!function_exists('_e')) { |
|
47
|
|
|
/** |
|
48
|
|
|
* Clean the fiven $value |
|
49
|
|
|
* |
|
50
|
|
|
* @param string $value |
|
51
|
|
|
* @return string |
|
52
|
|
|
*/ |
|
53
|
|
|
function _e($value) |
|
54
|
|
|
{ |
|
55
|
|
|
$value = trim($value); |
|
56
|
|
|
$value = preg_replace('# {2,}#', ' ', $value); |
|
57
|
|
|
$value = htmlspecialchars($value); |
|
58
|
|
|
return $value; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
if (!function_exists('assets')) { |
|
63
|
|
|
/** |
|
64
|
|
|
* Get the assets of the fiven $path |
|
65
|
|
|
* |
|
66
|
|
|
* @property object $url |
|
67
|
|
|
* @param string $path |
|
68
|
|
|
* @return string |
|
69
|
|
|
*/ |
|
70
|
|
|
function assets($path = null) |
|
71
|
|
|
{ |
|
72
|
|
|
return app()->url->link('public/' . ($path ? $path : '')); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
if (!function_exists('array_get')) { |
|
77
|
|
|
/** |
|
78
|
|
|
* Get the value of the given key of the given array |
|
79
|
|
|
* if the given key is not exist than return the given default |
|
80
|
|
|
* |
|
81
|
|
|
* @param array $array |
|
82
|
|
|
* @param string $key |
|
83
|
|
|
* @param mixed $default |
|
84
|
|
|
* @return mixed |
|
85
|
|
|
*/ |
|
86
|
|
|
function array_get(array $array, string $key, $default = null) |
|
87
|
|
|
{ |
|
88
|
|
|
return ($array[$key] || $array[$key] == '0') ? $array[$key] : $default; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
if (!function_exists('array_equal')) { |
|
93
|
|
|
/** |
|
94
|
|
|
* Check if the given arrays are equal |
|
95
|
|
|
* |
|
96
|
|
|
* @param array $a |
|
97
|
|
|
* @param array $b |
|
98
|
|
|
* @return bool |
|
99
|
|
|
*/ |
|
100
|
|
|
function array_equal(array $a, array $b) |
|
101
|
|
|
{ |
|
102
|
|
|
return (is_array($a) |
|
103
|
|
|
&& is_array($b) |
|
104
|
|
|
&& count($a) == count($b) |
|
105
|
|
|
&& array_diff($a, $b) === array_diff($b, $a)); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
if (!function_exists('isExtesntionAllowed')) { |
|
110
|
|
|
/** |
|
111
|
|
|
* Check if the given extension is allow to use |
|
112
|
|
|
* |
|
113
|
|
|
* @param string $key |
|
114
|
|
|
* @param string $extension |
|
115
|
|
|
* @property object $file |
|
116
|
|
|
* @return bool |
|
117
|
|
|
*/ |
|
118
|
|
|
function isExtesntionAllowed($key, $extension) |
|
119
|
|
|
{ |
|
120
|
|
|
$allowExtesntions = app()->file->call('config/uploads.php')[$key]; |
|
|
|
|
|
|
121
|
|
|
|
|
122
|
|
|
return in_array($extension, $allowExtesntions); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
if (!function_exists('isImage')) { |
|
127
|
|
|
/** |
|
128
|
|
|
* Check if the given minetype is an image |
|
129
|
|
|
* |
|
130
|
|
|
* @param string $minetype |
|
131
|
|
|
* @return bool |
|
132
|
|
|
*/ |
|
133
|
|
|
function isMinetypeisAnImage($minetype) |
|
134
|
|
|
{ |
|
135
|
|
|
return strpos($minetype, "image/") === 0; |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
if (!function_exists('notFoundPage')) { |
|
140
|
|
|
/** |
|
141
|
|
|
* Display Notfound page of admin or user depends on the user persmissions |
|
142
|
|
|
* |
|
143
|
|
|
* @property object $load |
|
144
|
|
|
* @return string |
|
145
|
|
|
*/ |
|
146
|
|
|
function notFoundPage() |
|
147
|
|
|
{ |
|
148
|
|
|
$notfound = 'Website\Notfound'; |
|
149
|
|
|
|
|
150
|
|
|
if (app()->request->isRequestToAdminManagement()) { |
|
|
|
|
|
|
151
|
|
|
$notfound = 'Admin\Notfound'; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
return (string) app()->load->action($notfound, 'index', []); |
|
|
|
|
|
|
155
|
|
|
} |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
if (!function_exists('getAllSubDires')) { |
|
160
|
|
|
/** |
|
161
|
|
|
* Getting all the sub-folders in the given path |
|
162
|
|
|
* |
|
163
|
|
|
* @param string $direPath |
|
164
|
|
|
* @return array |
|
165
|
|
|
*/ |
|
166
|
|
|
function getAllSubDires($direPath) |
|
167
|
|
|
{ |
|
168
|
|
|
$dirs = []; |
|
169
|
|
|
$directions = []; |
|
|
|
|
|
|
170
|
|
|
|
|
171
|
|
|
$directions = glob($direPath, GLOB_ONLYDIR); |
|
172
|
|
|
$dirs = array_merge($directions, $dirs); |
|
173
|
|
|
|
|
174
|
|
|
do { |
|
175
|
|
|
$direPath .= '**/'; |
|
176
|
|
|
$directions = glob($direPath, GLOB_ONLYDIR); |
|
177
|
|
|
$dirs = array_merge($directions, $dirs); |
|
178
|
|
|
} while (!empty($directions)); |
|
179
|
|
|
|
|
180
|
|
|
return $dirs; |
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.