@@ -42,13 +42,13 @@ discard block |
||
| 42 | 42 | * @param $urlRoute |
| 43 | 43 | * @return int|string |
| 44 | 44 | */ |
| 45 | - public static function checkArrayEqual($patterns,$urlRoute) |
|
| 45 | + public static function checkArrayEqual($patterns, $urlRoute) |
|
| 46 | 46 | {
|
| 47 | 47 | // calculates the equality difference between |
| 48 | 48 | // the route pattern and the urlRoute value. |
| 49 | - foreach ($patterns as $key=>$pattern){
|
|
| 49 | + foreach ($patterns as $key=>$pattern) {
|
|
| 50 | 50 | |
| 51 | - if(Utils::isArrayEqual($pattern,$urlRoute)){
|
|
| 51 | + if (Utils::isArrayEqual($pattern, $urlRoute)) {
|
|
| 52 | 52 | return $key; |
| 53 | 53 | } |
| 54 | 54 | } |
@@ -68,14 +68,14 @@ discard block |
||
| 68 | 68 | // get routes data and the resolving pattern |
| 69 | 69 | // Both are interrelated. |
| 70 | 70 | $routes = self::getRoutes(); |
| 71 | - $patternResolve = app()->resolve(RouteMatching::class,['route'=>new self()])->getPatternResolve(); |
|
| 71 | + $patternResolve = app()->resolve(RouteMatching::class, ['route'=>new self()])->getPatternResolve(); |
|
| 72 | 72 | |
| 73 | 73 | //if routes data is available in pattern resolve. |
| 74 | - if(isset($routes['data'][$patternResolve])){
|
|
| 74 | + if (isset($routes['data'][$patternResolve])) {
|
|
| 75 | 75 | |
| 76 | 76 | // if the incoming http value is |
| 77 | 77 | // the same as the real request method, the data is processed. |
| 78 | - if($routes['data'][$patternResolve]['http'] == strtolower(httpMethod)){
|
|
| 78 | + if ($routes['data'][$patternResolve]['http']==strtolower(httpMethod)) {
|
|
| 79 | 79 | |
| 80 | 80 | // we are set the solved pattern to a variable. |
| 81 | 81 | $resolve = $routes['data'][$patternResolve]; |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | {
|
| 101 | 101 | // we will record the path data for the route. |
| 102 | 102 | // We set the routeMapper variables and the route path. |
| 103 | - self::setPath(function(){
|
|
| 103 | + self::setPath(function() {
|
|
| 104 | 104 | |
| 105 | 105 | // we are sending |
| 106 | 106 | // the controller and routes.php path. |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | // in the paths data, |
| 114 | 114 | // we run the route mapper values and the route files one by one. |
| 115 | - foreach (self::$paths as $mapper=>$controller){
|
|
| 115 | + foreach (self::$paths as $mapper=>$controller) {
|
|
| 116 | 116 | core()->fileSystem->callFile($mapper); |
| 117 | 117 | } |
| 118 | 118 | } |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | {
|
| 127 | 127 | $routeDefinitor = call_user_func($callback); |
| 128 | 128 | |
| 129 | - if(isset($routeDefinitor['controllerPath']) && isset($routeDefinitor['routePath'])){
|
|
| 129 | + if (isset($routeDefinitor['controllerPath']) && isset($routeDefinitor['routePath'])) {
|
|
| 130 | 130 | |
| 131 | 131 | //the route paths to be saved to the mappers static property. |
| 132 | 132 | static::$mappers['routePaths'][] = $routeDefinitor['routePath']; |
@@ -134,22 +134,22 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | // if there is endpoint, |
| 136 | 136 | // then only that endpoint is transferred into the path |
| 137 | - if(defined('endpoint')){
|
|
| 137 | + if (defined('endpoint')) {
|
|
| 138 | 138 | |
| 139 | 139 | $routeName = endpoint.'Route.php'; |
| 140 | 140 | $routeMapper = $routeDefinitor['routePath'].''.DIRECTORY_SEPARATOR.''.$routeName; |
| 141 | 141 | |
| 142 | - if(file_exists($routeMapper) && !isset(static::$paths[$routeMapper])){
|
|
| 142 | + if (file_exists($routeMapper) && !isset(static::$paths[$routeMapper])) {
|
|
| 143 | 143 | static::$paths[$routeMapper] = $routeDefinitor['controllerPath']; |
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | - else{
|
|
| 146 | + else {
|
|
| 147 | 147 | |
| 148 | 148 | // if there is no endpoint, |
| 149 | 149 | // all files in the path of the route are transferred to path. |
| 150 | 150 | $allFilesInThatRoutePath = Utils::glob($routeDefinitor['routePath']); |
| 151 | 151 | |
| 152 | - foreach ($allFilesInThatRoutePath as $item){
|
|
| 152 | + foreach ($allFilesInThatRoutePath as $item) {
|
|
| 153 | 153 | static::$paths[$item] = $routeDefinitor['controllerPath']; |
| 154 | 154 | } |
| 155 | 155 | } |
@@ -163,13 +163,13 @@ discard block |
||
| 163 | 163 | * @param $function |
| 164 | 164 | * @param null $controller |
| 165 | 165 | */ |
| 166 | - public static function setRoute($params,$function,$controller=null) |
|
| 166 | + public static function setRoute($params, $function, $controller = null) |
|
| 167 | 167 | {
|
| 168 | - [$pattern,$route] = $params; |
|
| 169 | - [$class,$method] = explode("@",$route);
|
|
| 168 | + [$pattern, $route] = $params; |
|
| 169 | + [$class, $method] = explode("@", $route);
|
|
| 170 | 170 | |
| 171 | 171 | $patternList = array_values( |
| 172 | - array_filter(explode("/",$pattern),'strlen')
|
|
| 172 | + array_filter(explode("/", $pattern), 'strlen')
|
|
| 173 | 173 | ); |
| 174 | 174 | |
| 175 | 175 | static::$routes['pattern'][] = $patternList; |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | 'http' => $function, |
| 180 | 180 | 'controller' => $controller, |
| 181 | 181 | 'namespace' => static::$namespace, |
| 182 | - 'endpoint' => strtolower(str_replace(StaticPathList::$controllerBundleName,'',static::$namespace)) |
|
| 182 | + 'endpoint' => strtolower(str_replace(StaticPathList::$controllerBundleName, '', static::$namespace)) |
|
| 183 | 183 | ]; |
| 184 | 184 | } |
| 185 | 185 | |
@@ -189,11 +189,11 @@ discard block |
||
| 189 | 189 | * @param null $value |
| 190 | 190 | * @return bool |
| 191 | 191 | */ |
| 192 | - public static function isMatchVaribleRegexPattern($value=null) |
|
| 192 | + public static function isMatchVaribleRegexPattern($value = null) |
|
| 193 | 193 | {
|
| 194 | 194 | // determines if the variable that can be used |
| 195 | 195 | // in the route file meets the regex rule. |
| 196 | - return (preg_match('@\{(.*?)\}@is',$value)) ? true : false;
|
|
| 196 | + return (preg_match('@\{(.*?)\}@is', $value)) ? true : false;
|
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | |
@@ -203,11 +203,11 @@ discard block |
||
| 203 | 203 | * @param null $value |
| 204 | 204 | * @return bool |
| 205 | 205 | */ |
| 206 | - public static function isOptionalVaribleRegexPattern($value=null) |
|
| 206 | + public static function isOptionalVaribleRegexPattern($value = null) |
|
| 207 | 207 | {
|
| 208 | 208 | // determines if the variable that can be used |
| 209 | 209 | // in the route file meets the regex rule. |
| 210 | - return preg_match('@\{[a-z]+\?\}@is',$value) ? true : false;
|
|
| 210 | + return preg_match('@\{[a-z]+\?\}@is', $value) ? true : false;
|
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * @param ApplicationContracts $app |
| 19 | 19 | * @param null|object $route |
| 20 | 20 | */ |
| 21 | - public function __construct(ApplicationContracts $app, $route=null) |
|
| 21 | + public function __construct(ApplicationContracts $app, $route = null) |
|
| 22 | 22 | { |
| 23 | 23 | parent::__construct($app); |
| 24 | 24 | |
@@ -34,51 +34,51 @@ discard block |
||
| 34 | 34 | { |
| 35 | 35 | $routes = $this->route->getRoutes(); |
| 36 | 36 | |
| 37 | - if(!isset($routes['pattern'])){ |
|
| 37 | + if (!isset($routes['pattern'])) { |
|
| 38 | 38 | return []; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | $patterns = $routes['pattern']; |
| 42 | - $urlRoute = array_filter(route(),'strlen'); |
|
| 42 | + $urlRoute = array_filter(route(), 'strlen'); |
|
| 43 | 43 | |
| 44 | 44 | $patternList = []; |
| 45 | 45 | |
| 46 | - foreach($routes['data'] as $patternKey=>$routeData){ |
|
| 47 | - if($routeData['http']==httpMethod()){ |
|
| 48 | - $patternList[$patternKey]=$patterns[$patternKey]; |
|
| 46 | + foreach ($routes['data'] as $patternKey=>$routeData) { |
|
| 47 | + if ($routeData['http']==httpMethod()) { |
|
| 48 | + $patternList[$patternKey] = $patterns[$patternKey]; |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | $scoredList = []; |
| 53 | 53 | |
| 54 | - foreach ($patternList as $key=>$pattern){ |
|
| 54 | + foreach ($patternList as $key=>$pattern) { |
|
| 55 | 55 | |
| 56 | 56 | $patternCount = $this->getPatternRealCount($pattern); |
| 57 | 57 | |
| 58 | - if(isset($patternCount['optional'])){ |
|
| 59 | - $optionalCount = count($patternCount['default']) + count($patternCount['optional']); |
|
| 58 | + if (isset($patternCount['optional'])) { |
|
| 59 | + $optionalCount = count($patternCount['default'])+count($patternCount['optional']); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - if(count($urlRoute) == count($patternCount['default']) || |
|
| 62 | + if (count($urlRoute)==count($patternCount['default']) || |
|
| 63 | 63 | (isset($optionalCount) && count($urlRoute)>count($patternCount['default']) && $optionalCount>=count($urlRoute)) |
| 64 | - ){ |
|
| 64 | + ) { |
|
| 65 | 65 | |
| 66 | - foreach ($pattern as $pkey=>$item){ |
|
| 66 | + foreach ($pattern as $pkey=>$item) { |
|
| 67 | 67 | |
| 68 | - if($this->route->isMatchVaribleRegexPattern($item)===false){ |
|
| 69 | - if(isset($urlRoute[$pkey]) && $urlRoute[$pkey]==$item){ |
|
| 68 | + if ($this->route->isMatchVaribleRegexPattern($item)===false) { |
|
| 69 | + if (isset($urlRoute[$pkey]) && $urlRoute[$pkey]==$item) { |
|
| 70 | 70 | $scoredList[$key][] = 3; |
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - if($this->route->isMatchVaribleRegexPattern($item) && !$this->route->isOptionalVaribleRegexPattern($item)){ |
|
| 75 | - if(isset($urlRoute[$pkey])){ |
|
| 74 | + if ($this->route->isMatchVaribleRegexPattern($item) && !$this->route->isOptionalVaribleRegexPattern($item)) { |
|
| 75 | + if (isset($urlRoute[$pkey])) { |
|
| 76 | 76 | $scoredList[$key][] = 2; |
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - if($this->route->isMatchVaribleRegexPattern($item) && $this->route->isOptionalVaribleRegexPattern($item)){ |
|
| 81 | - if(isset($urlRoute[$pkey])){ |
|
| 80 | + if ($this->route->isMatchVaribleRegexPattern($item) && $this->route->isOptionalVaribleRegexPattern($item)) { |
|
| 81 | + if (isset($urlRoute[$pkey])) { |
|
| 82 | 82 | $scoredList[$key][] = 1; |
| 83 | 83 | } |
| 84 | 84 | } |
@@ -101,14 +101,14 @@ discard block |
||
| 101 | 101 | { |
| 102 | 102 | $list = []; |
| 103 | 103 | |
| 104 | - foreach ($pattern as $key=>$value){ |
|
| 105 | - if(($this->route->isMatchVaribleRegexPattern($value)===false) || ($this->route->isMatchVaribleRegexPattern($value) |
|
| 106 | - && !$this->route->isOptionalVaribleRegexPattern($value))){ |
|
| 104 | + foreach ($pattern as $key=>$value) { |
|
| 105 | + if (($this->route->isMatchVaribleRegexPattern($value)===false) || ($this->route->isMatchVaribleRegexPattern($value) |
|
| 106 | + && !$this->route->isOptionalVaribleRegexPattern($value))) { |
|
| 107 | 107 | $list['default'][$key] = $value; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - if(($this->route->isMatchVaribleRegexPattern($value) |
|
| 111 | - && $this->route->isOptionalVaribleRegexPattern($value))){ |
|
| 110 | + if (($this->route->isMatchVaribleRegexPattern($value) |
|
| 111 | + && $this->route->isOptionalVaribleRegexPattern($value))) { |
|
| 112 | 112 | $list['optional'][] = true; |
| 113 | 113 | } |
| 114 | 114 | } |
@@ -122,16 +122,16 @@ discard block |
||
| 122 | 122 | * @param array $scoredList |
| 123 | 123 | * @return false|int|string |
| 124 | 124 | */ |
| 125 | - private function showKeyAccordingToScoredList($scoredList=array()) |
|
| 125 | + private function showKeyAccordingToScoredList($scoredList = array()) |
|
| 126 | 126 | { |
| 127 | 127 | $scored = []; |
| 128 | 128 | |
| 129 | - foreach($scoredList as $key=>$item){ |
|
| 129 | + foreach ($scoredList as $key=>$item) { |
|
| 130 | 130 | $scored[$key] = array_sum($item); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - if(count($scored)){ |
|
| 134 | - return array_search(max($scored),$scored); |
|
| 133 | + if (count($scored)) { |
|
| 134 | + return array_search(max($scored), $scored); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | return null; |
@@ -149,8 +149,8 @@ discard block |
||
| 149 | 149 | $route = route(); |
| 150 | 150 | |
| 151 | 151 | foreach ($pattern as $key=>$item) { |
| 152 | - if($this->route->isMatchVaribleRegexPattern($item)===false){ |
|
| 153 | - if(isset($route[$key]) && $item!==$route[$key]){ |
|
| 152 | + if ($this->route->isMatchVaribleRegexPattern($item)===false) { |
|
| 153 | + if (isset($route[$key]) && $item!==$route[$key]) { |
|
| 154 | 154 | return false; |
| 155 | 155 | } |
| 156 | 156 | } |