@@ -43,13 +43,13 @@ discard block |
||
43 | 43 | * @param $urlRoute |
44 | 44 | * @return int|string |
45 | 45 | */ |
46 | - private static function checkArrayEqual($patterns,$urlRoute) |
|
46 | + private static function checkArrayEqual($patterns, $urlRoute) |
|
47 | 47 | { |
48 | 48 | // calculates the equality difference between |
49 | 49 | // the route pattern and the urlRoute value. |
50 | - foreach ($patterns as $key=>$pattern){ |
|
50 | + foreach ($patterns as $key=>$pattern) { |
|
51 | 51 | |
52 | - if(Utils::isArrayEqual($pattern,$urlRoute)){ |
|
52 | + if (Utils::isArrayEqual($pattern, $urlRoute)) { |
|
53 | 53 | return $key; |
54 | 54 | } |
55 | 55 | } |
@@ -66,38 +66,38 @@ discard block |
||
66 | 66 | * @param $urlMethod |
67 | 67 | * @return array |
68 | 68 | */ |
69 | - private static function matchingUrlMethod($patterns,$urlMethod) |
|
69 | + private static function matchingUrlMethod($patterns, $urlMethod) |
|
70 | 70 | { |
71 | - if(isset($urlMethod[0])){ |
|
71 | + if (isset($urlMethod[0])) { |
|
72 | 72 | |
73 | 73 | $list = []; |
74 | 74 | |
75 | - foreach ($patterns as $key=>$pattern){ |
|
75 | + foreach ($patterns as $key=>$pattern) { |
|
76 | 76 | |
77 | 77 | // if the initial value of the pattern data is present |
78 | 78 | // and the first value from urlmethod does not match |
79 | 79 | // and does not match the custom regex variable, |
80 | 80 | // we empty the contents of the data. |
81 | - if(isset($pattern[0])){ |
|
82 | - if($pattern[0] !== $urlMethod[0] && !self::isMatchVaribleRegexPattern($pattern[0])){ |
|
81 | + if (isset($pattern[0])) { |
|
82 | + if ($pattern[0]!==$urlMethod[0] && !self::isMatchVaribleRegexPattern($pattern[0])) { |
|
83 | 83 | $list[$key] = []; |
84 | 84 | } |
85 | 85 | } |
86 | 86 | |
87 | 87 | // if the contents of the directory are not normally emptied, |
88 | 88 | // we continue to save the list according to keyin status. |
89 | - if(!isset($list[$key])){ |
|
89 | + if (!isset($list[$key])) { |
|
90 | 90 | $list[$key] = $pattern; |
91 | 91 | } |
92 | 92 | |
93 | 93 | // This is very important. |
94 | 94 | // Route matches can be variable-based or static string-based. |
95 | 95 | // In this case, we remove the other matches based on the static string match. |
96 | - if(isset($pattern[0]) && $pattern[0]==$urlMethod[0]){ |
|
96 | + if (isset($pattern[0]) && $pattern[0]==$urlMethod[0]) { |
|
97 | 97 | |
98 | 98 | // static matches will not be deleted retrospectively. |
99 | 99 | // this condition will check this. |
100 | - if(isset($list[$key-1],$list[$key-1][0]) && $list[$key-1][0]!==$urlMethod[0]){ |
|
100 | + if (isset($list[$key-1], $list[$key-1][0]) && $list[$key-1][0]!==$urlMethod[0]) { |
|
101 | 101 | unset($list[$key-1]); |
102 | 102 | } |
103 | 103 | |
@@ -120,53 +120,53 @@ discard block |
||
120 | 120 | { |
121 | 121 | $routes = self::getRoutes(); |
122 | 122 | |
123 | - if(!isset($routes['pattern'])){ |
|
123 | + if (!isset($routes['pattern'])) { |
|
124 | 124 | return []; |
125 | 125 | } |
126 | 126 | |
127 | 127 | $patterns = $routes['pattern']; |
128 | - $urlRoute = array_filter(route(),'strlen'); |
|
128 | + $urlRoute = array_filter(route(), 'strlen'); |
|
129 | 129 | |
130 | 130 | $patternList = []; |
131 | 131 | |
132 | - foreach($routes['data'] as $patternKey=>$routeData){ |
|
133 | - if($routeData['http']==httpMethod()){ |
|
134 | - $patternList[$patternKey]=$patterns[$patternKey]; |
|
132 | + foreach ($routes['data'] as $patternKey=>$routeData) { |
|
133 | + if ($routeData['http']==httpMethod()) { |
|
134 | + $patternList[$patternKey] = $patterns[$patternKey]; |
|
135 | 135 | } |
136 | 136 | } |
137 | 137 | |
138 | - $patternList = self::matchingUrlMethod($patternList,$urlRoute); |
|
138 | + $patternList = self::matchingUrlMethod($patternList, $urlRoute); |
|
139 | 139 | |
140 | - foreach ($patternList as $key=>$pattern){ |
|
140 | + foreach ($patternList as $key=>$pattern) { |
|
141 | 141 | |
142 | - $pattern = array_filter($pattern,'strlen'); |
|
143 | - $diff = Arr::arrayDiffKey($pattern,$urlRoute); |
|
142 | + $pattern = array_filter($pattern, 'strlen'); |
|
143 | + $diff = Arr::arrayDiffKey($pattern, $urlRoute); |
|
144 | 144 | |
145 | - if($diff){ |
|
145 | + if ($diff) { |
|
146 | 146 | |
147 | 147 | $matches = true; |
148 | 148 | |
149 | - foreach ($pattern as $patternKey=>$patternValue){ |
|
150 | - if(!self::isMatchVaribleRegexPattern($patternValue)){ |
|
151 | - if($patternValue!==$urlRoute[$patternKey]){ |
|
149 | + foreach ($pattern as $patternKey=>$patternValue) { |
|
150 | + if (!self::isMatchVaribleRegexPattern($patternValue)) { |
|
151 | + if ($patternValue!==$urlRoute[$patternKey]) { |
|
152 | 152 | $matches = false; |
153 | 153 | } |
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
157 | - if($matches){ |
|
157 | + if ($matches) { |
|
158 | 158 | |
159 | - $isArrayEqual = self::checkArrayEqual($patternList,$urlRoute); |
|
159 | + $isArrayEqual = self::checkArrayEqual($patternList, $urlRoute); |
|
160 | 160 | |
161 | - if($isArrayEqual===null){ |
|
161 | + if ($isArrayEqual===null) { |
|
162 | 162 | return $key; |
163 | 163 | } |
164 | 164 | return $isArrayEqual; |
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
168 | - if(count($pattern)-1 == count(route())){ |
|
169 | - if(preg_match('@\{[a-z]+\?\}@is',end($pattern))){ |
|
168 | + if (count($pattern)-1==count(route())) { |
|
169 | + if (preg_match('@\{[a-z]+\?\}@is', end($pattern))) { |
|
170 | 170 | return $key; |
171 | 171 | } |
172 | 172 | } |
@@ -186,11 +186,11 @@ discard block |
||
186 | 186 | $patternResolve = self::getPatternResolve(); |
187 | 187 | |
188 | 188 | //if routes data is available in pattern resolve. |
189 | - if(isset($routes['data'][$patternResolve])){ |
|
189 | + if (isset($routes['data'][$patternResolve])) { |
|
190 | 190 | |
191 | 191 | // if the incoming http value is |
192 | 192 | // the same as the real request method, the data is processed. |
193 | - if($routes['data'][$patternResolve]['http'] == strtolower(httpMethod)){ |
|
193 | + if ($routes['data'][$patternResolve]['http']==strtolower(httpMethod)) { |
|
194 | 194 | |
195 | 195 | // we are set the solved pattern to a variable. |
196 | 196 | $resolve = $routes['data'][$patternResolve]; |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | { |
216 | 216 | // we will record the path data for the route. |
217 | 217 | // We set the routeMapper variables and the route path. |
218 | - self::setPath(function(){ |
|
218 | + self::setPath(function() { |
|
219 | 219 | |
220 | 220 | // we are sending |
221 | 221 | // the controller and routes.php path. |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | |
228 | 228 | // in the paths data, |
229 | 229 | // we run the route mapper values and the route files one by one. |
230 | - foreach (self::$paths as $mapper=>$controller){ |
|
230 | + foreach (self::$paths as $mapper=>$controller) { |
|
231 | 231 | core()->fileSystem->callFile($mapper); |
232 | 232 | } |
233 | 233 | } |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | { |
242 | 242 | $routeDefinitor = call_user_func($callback); |
243 | 243 | |
244 | - if(isset($routeDefinitor['controllerPath']) && isset($routeDefinitor['routePath'])){ |
|
244 | + if (isset($routeDefinitor['controllerPath']) && isset($routeDefinitor['routePath'])) { |
|
245 | 245 | |
246 | 246 | //the route paths to be saved to the mappers static property. |
247 | 247 | static::$mappers['routePaths'][] = $routeDefinitor['routePath']; |
@@ -249,22 +249,22 @@ discard block |
||
249 | 249 | |
250 | 250 | // if there is endpoint, |
251 | 251 | // then only that endpoint is transferred into the path |
252 | - if(defined('endpoint')){ |
|
252 | + if (defined('endpoint')) { |
|
253 | 253 | |
254 | 254 | $routeName = endpoint.'Route.php'; |
255 | 255 | $routeMapper = $routeDefinitor['routePath'].''.DIRECTORY_SEPARATOR.''.$routeName; |
256 | 256 | |
257 | - if(file_exists($routeMapper) && !isset(static::$paths[$routeMapper])){ |
|
257 | + if (file_exists($routeMapper) && !isset(static::$paths[$routeMapper])) { |
|
258 | 258 | static::$paths[$routeMapper] = $routeDefinitor['controllerPath']; |
259 | 259 | } |
260 | 260 | } |
261 | - else{ |
|
261 | + else { |
|
262 | 262 | |
263 | 263 | // if there is no endpoint, |
264 | 264 | // all files in the path of the route are transferred to path. |
265 | 265 | $allFilesInThatRoutePath = Utils::glob($routeDefinitor['routePath']); |
266 | 266 | |
267 | - foreach ($allFilesInThatRoutePath as $item){ |
|
267 | + foreach ($allFilesInThatRoutePath as $item) { |
|
268 | 268 | static::$paths[$item] = $routeDefinitor['controllerPath']; |
269 | 269 | } |
270 | 270 | } |
@@ -278,13 +278,13 @@ discard block |
||
278 | 278 | * @param $function |
279 | 279 | * @param null $controller |
280 | 280 | */ |
281 | - public static function setRoute($params,$function,$controller=null) |
|
281 | + public static function setRoute($params, $function, $controller = null) |
|
282 | 282 | { |
283 | - [$pattern,$route] = $params; |
|
284 | - [$class,$method] = explode("@",$route); |
|
283 | + [$pattern, $route] = $params; |
|
284 | + [$class, $method] = explode("@", $route); |
|
285 | 285 | |
286 | 286 | $patternList = array_values( |
287 | - array_filter(explode("/",$pattern),'strlen') |
|
287 | + array_filter(explode("/", $pattern), 'strlen') |
|
288 | 288 | ); |
289 | 289 | |
290 | 290 | static::$routes['pattern'][] = $patternList; |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | 'http' => $function, |
295 | 295 | 'controller' => $controller, |
296 | 296 | 'namespace' => static::$namespace, |
297 | - 'endpoint' => strtolower(str_replace(StaticPathList::$controllerBundleName,'',static::$namespace)) |
|
297 | + 'endpoint' => strtolower(str_replace(StaticPathList::$controllerBundleName, '', static::$namespace)) |
|
298 | 298 | ]; |
299 | 299 | } |
300 | 300 | |
@@ -304,10 +304,10 @@ discard block |
||
304 | 304 | * @param null $value |
305 | 305 | * @return bool |
306 | 306 | */ |
307 | - public static function isMatchVaribleRegexPattern($value=null) |
|
307 | + public static function isMatchVaribleRegexPattern($value = null) |
|
308 | 308 | { |
309 | 309 | // determines if the variable that can be used |
310 | 310 | // in the route file meets the regex rule. |
311 | - return (preg_match('@\{(.*?)\}@is',$value)) ? true : false; |
|
311 | + return (preg_match('@\{(.*?)\}@is', $value)) ? true : false; |
|
312 | 312 | } |
313 | 313 | } |
314 | 314 | \ No newline at end of file |