@@ -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,10 +189,10 @@ 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 | \ No newline at end of file |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * @param ApplicationContracts $app |
| 24 | 24 | * @param null|object $route |
| 25 | 25 | */ |
| 26 | - public function __construct(ApplicationContracts $app, $route=null) |
|
| 26 | + public function __construct(ApplicationContracts $app, $route = null) |
|
| 27 | 27 | { |
| 28 | 28 | parent::__construct($app); |
| 29 | 29 | |
@@ -39,53 +39,53 @@ discard block |
||
| 39 | 39 | { |
| 40 | 40 | $routes = $this->route->getRoutes(); |
| 41 | 41 | |
| 42 | - if(!isset($routes['pattern'])){ |
|
| 42 | + if (!isset($routes['pattern'])) { |
|
| 43 | 43 | return []; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | $patterns = $routes['pattern']; |
| 47 | - $urlRoute = array_filter(route(),'strlen'); |
|
| 47 | + $urlRoute = array_filter(route(), 'strlen'); |
|
| 48 | 48 | |
| 49 | 49 | $patternList = []; |
| 50 | 50 | |
| 51 | - foreach($routes['data'] as $patternKey=>$routeData){ |
|
| 52 | - if($routeData['http']==httpMethod()){ |
|
| 53 | - $patternList[$patternKey]=$patterns[$patternKey]; |
|
| 51 | + foreach ($routes['data'] as $patternKey=>$routeData) { |
|
| 52 | + if ($routeData['http']==httpMethod()) { |
|
| 53 | + $patternList[$patternKey] = $patterns[$patternKey]; |
|
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - $patternList = $this->matchingUrlMethod($patternList,$urlRoute); |
|
| 57 | + $patternList = $this->matchingUrlMethod($patternList, $urlRoute); |
|
| 58 | 58 | |
| 59 | - foreach ($patternList as $key=>$pattern){ |
|
| 59 | + foreach ($patternList as $key=>$pattern) { |
|
| 60 | 60 | |
| 61 | - $pattern = array_filter($pattern,'strlen'); |
|
| 62 | - $diff = Arr::arrayDiffKey($pattern,$urlRoute); |
|
| 61 | + $pattern = array_filter($pattern, 'strlen'); |
|
| 62 | + $diff = Arr::arrayDiffKey($pattern, $urlRoute); |
|
| 63 | 63 | |
| 64 | - if($diff){ |
|
| 64 | + if ($diff) { |
|
| 65 | 65 | |
| 66 | 66 | $matches = true; |
| 67 | 67 | |
| 68 | - foreach ($pattern as $patternKey=>$patternValue){ |
|
| 69 | - if(!$this->route->isMatchVaribleRegexPattern($patternValue)){ |
|
| 70 | - if($patternValue!==$urlRoute[$patternKey]){ |
|
| 68 | + foreach ($pattern as $patternKey=>$patternValue) { |
|
| 69 | + if (!$this->route->isMatchVaribleRegexPattern($patternValue)) { |
|
| 70 | + if ($patternValue!==$urlRoute[$patternKey]) { |
|
| 71 | 71 | $matches = false; |
| 72 | 72 | } |
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - if($matches){ |
|
| 76 | + if ($matches) { |
|
| 77 | 77 | |
| 78 | - $isArrayEqual = $this->route->checkArrayEqual($patternList,$urlRoute); |
|
| 78 | + $isArrayEqual = $this->route->checkArrayEqual($patternList, $urlRoute); |
|
| 79 | 79 | |
| 80 | - if($isArrayEqual===null){ |
|
| 80 | + if ($isArrayEqual===null) { |
|
| 81 | 81 | return $key; |
| 82 | 82 | } |
| 83 | 83 | return $isArrayEqual; |
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - if(count($pattern)-1 == count(route())){ |
|
| 88 | - if(preg_match('@\{[a-z]+\?\}@is',end($pattern))){ |
|
| 87 | + if (count($pattern)-1==count(route())) { |
|
| 88 | + if (preg_match('@\{[a-z]+\?\}@is', end($pattern))) { |
|
| 89 | 89 | return $key; |
| 90 | 90 | } |
| 91 | 91 | } |
@@ -99,38 +99,38 @@ discard block |
||
| 99 | 99 | * @param $urlMethod |
| 100 | 100 | * @return array |
| 101 | 101 | */ |
| 102 | - public function matchingUrlMethod($patterns,$urlMethod) |
|
| 102 | + public function matchingUrlMethod($patterns, $urlMethod) |
|
| 103 | 103 | { |
| 104 | - if(isset($urlMethod[0])){ |
|
| 104 | + if (isset($urlMethod[0])) { |
|
| 105 | 105 | |
| 106 | 106 | $list = []; |
| 107 | 107 | |
| 108 | - foreach ($patterns as $key=>$pattern){ |
|
| 108 | + foreach ($patterns as $key=>$pattern) { |
|
| 109 | 109 | |
| 110 | 110 | // if the initial value of the pattern data is present |
| 111 | 111 | // and the first value from urlmethod does not match |
| 112 | 112 | // and does not match the custom regex variable, |
| 113 | 113 | // we empty the contents of the data. |
| 114 | - if(isset($pattern[0])){ |
|
| 115 | - if($pattern[0] !== $urlMethod[0] && !$this->route->isMatchVaribleRegexPattern($pattern[0])){ |
|
| 114 | + if (isset($pattern[0])) { |
|
| 115 | + if ($pattern[0]!==$urlMethod[0] && !$this->route->isMatchVaribleRegexPattern($pattern[0])) { |
|
| 116 | 116 | $list[$key] = []; |
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | // if the contents of the directory are not normally emptied, |
| 121 | 121 | // we continue to save the list according to keyin status. |
| 122 | - if(!isset($list[$key])){ |
|
| 122 | + if (!isset($list[$key])) { |
|
| 123 | 123 | $list[$key] = $pattern; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | // This is very important. |
| 127 | 127 | // Route matches can be variable-based or static string-based. |
| 128 | 128 | // In this case, we remove the other matches based on the static string match. |
| 129 | - if(isset($pattern[0]) && $pattern[0]==$urlMethod[0]){ |
|
| 129 | + if (isset($pattern[0]) && $pattern[0]==$urlMethod[0]) { |
|
| 130 | 130 | |
| 131 | 131 | // static matches will not be deleted retrospectively. |
| 132 | 132 | // this condition will check this. |
| 133 | - if($this->unset===false){ |
|
| 133 | + if ($this->unset===false) { |
|
| 134 | 134 | unset($list); |
| 135 | 135 | $this->unset = true; |
| 136 | 136 | } |