@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | public function getResolveServiceMiddleware() |
| 61 | 61 | {
|
| 62 | - if(!is_null($this->serviceMiddleware)){
|
|
| 62 | + if (!is_null($this->serviceMiddleware)) {
|
|
| 63 | 63 | return $this->app->resolve($this->serviceMiddleware); |
| 64 | 64 | } |
| 65 | 65 | |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | public function handle() |
| 95 | 95 | {
|
| 96 | 96 | //set define for middleware |
| 97 | - define('middleware',true);
|
|
| 97 | + define('middleware', true);
|
|
| 98 | 98 | |
| 99 | 99 | //middleware handle process |
| 100 | 100 | $this->handleMiddlewareProcess(); |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | * @param string $method |
| 107 | 107 | * @return void|mixed |
| 108 | 108 | */ |
| 109 | - public function handleMiddlewareProcess($method='handle') |
|
| 109 | + public function handleMiddlewareProcess($method = 'handle') |
|
| 110 | 110 | {
|
| 111 | 111 | // the app instance is a global application example, |
| 112 | 112 | // and a hash is loaded as this hash. |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | // the middleware class must be subject to |
| 116 | 116 | // the ServiceMiddlewareManagerContracts interface rule to be implemented. |
| 117 | - if(!$this->getResolveServiceMiddleware() instanceof ServiceMiddlewareManagerContracts){
|
|
| 117 | + if (!$this->getResolveServiceMiddleware() instanceof ServiceMiddlewareManagerContracts) {
|
|
| 118 | 118 | exception()->badMethodCall('Service middleware does not have ServiceMiddlewareManagerContracts');
|
| 119 | 119 | } |
| 120 | 120 | |
@@ -131,17 +131,17 @@ discard block |
||
| 131 | 131 | * @param $key null |
| 132 | 132 | * @return array |
| 133 | 133 | */ |
| 134 | - public function middlewareKeyOdds($key=null) |
|
| 134 | + public function middlewareKeyOdds($key = null) |
|
| 135 | 135 | {
|
| 136 | 136 | // identifying constants for the middleware layer. |
| 137 | 137 | // with the property of the user, the user is free to determine the constants that the middleware layer wants. |
| 138 | - $method = $this->odds['method'] ?? implode("/",$this->app['routeParameters']);
|
|
| 138 | + $method = $this->odds['method'] ?? implode("/", $this->app['routeParameters']);
|
|
| 139 | 139 | $endpoint = $this->odds['endpoint'] ?? endpoint; |
| 140 | 140 | $http = $this->odds['http'] ?? $this->app['httpMethod']; |
| 141 | 141 | |
| 142 | 142 | //method can only return fixed. |
| 143 | - if(!is_null($key)){
|
|
| 144 | - if(isset($$key)) return $$key; |
|
| 143 | + if (!is_null($key)) {
|
|
| 144 | + if (isset($$key)) return $$key; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | //middleware key odds |
@@ -157,21 +157,21 @@ discard block |
||
| 157 | 157 | * |
| 158 | 158 | * @param array $middleware |
| 159 | 159 | */ |
| 160 | - public function serviceMiddleware($middleware=array()) |
|
| 160 | + public function serviceMiddleware($middleware = array()) |
|
| 161 | 161 | {
|
| 162 | 162 | $this->show = []; |
| 163 | 163 | |
| 164 | 164 | //It will be run individually according to the rules of |
| 165 | 165 | //the middleware classes specified for the service middleware middleware. |
| 166 | - foreach($middleware as $middleVal=>$middleKey){
|
|
| 166 | + foreach ($middleware as $middleVal=>$middleKey) {
|
|
| 167 | 167 | |
| 168 | 168 | // if the keys in the array in the service middleware class represent a class, |
| 169 | 169 | // this value is checked, if it does not represent the class, |
| 170 | 170 | // it is detected as a short name and is searched in the middleware directory. |
| 171 | - if(Utils::isNamespaceExists($middleVal)){
|
|
| 171 | + if (Utils::isNamespaceExists($middleVal)) {
|
|
| 172 | 172 | $middlewareNamespace = $middleVal; |
| 173 | 173 | } |
| 174 | - else{
|
|
| 174 | + else {
|
|
| 175 | 175 | $middlewareNamespace = app()->namespace()->middleware().'\\'.ucfirst($middleVal); |
| 176 | 176 | } |
| 177 | 177 | |
@@ -190,12 +190,12 @@ discard block |
||
| 190 | 190 | //it will be handled according to the following rule. |
| 191 | 191 | //The exclude class will return a callback and allocate the result as bool to the exclude variable. |
| 192 | 192 | //If the exclude variable is true then the middleware will be run. |
| 193 | - $excludeClass->exclude($this->middleware,function($exclude) use ($middleVal){
|
|
| 193 | + $excludeClass->exclude($this->middleware, function($exclude) use ($middleVal){
|
|
| 194 | 194 | |
| 195 | - if($exclude){
|
|
| 195 | + if ($exclude) {
|
|
| 196 | 196 | |
| 197 | 197 | //the condition of a specific statement to be handled |
| 198 | - if($this->checkNamespaceAndSpecificCondition()){
|
|
| 198 | + if ($this->checkNamespaceAndSpecificCondition()) {
|
|
| 199 | 199 | $this->pointer($middleVal); |
| 200 | 200 | |
| 201 | 201 | //directly registered to the middleware name show property. |
@@ -203,8 +203,8 @@ discard block |
||
| 203 | 203 | |
| 204 | 204 | // the middleware namespace must have handletraitcontract interface property. |
| 205 | 205 | // otherwise, middleware will not work. |
| 206 | - if(false === $this->app->runningInConsole() |
|
| 207 | - && $this->app->resolve($this->middleware['namespace']) instanceof HandleContracts){
|
|
| 206 | + if (false===$this->app->runningInConsole() |
|
| 207 | + && $this->app->resolve($this->middleware['namespace']) instanceof HandleContracts) {
|
|
| 208 | 208 | $this->app->resolve($this->middleware['namespace'])->handle(); |
| 209 | 209 | } |
| 210 | 210 | } |
@@ -220,10 +220,10 @@ discard block |
||
| 220 | 220 | * @param null $key |
| 221 | 221 | * @param null $value |
| 222 | 222 | */ |
| 223 | - public function setKeyOdds($key=null,$value=null) |
|
| 223 | + public function setKeyOdds($key = null, $value = null) |
|
| 224 | 224 | {
|
| 225 | 225 | //user-defined middleware constants. |
| 226 | - if(!is_null($key) && !is_null($value)){
|
|
| 226 | + if (!is_null($key) && !is_null($value)) {
|
|
| 227 | 227 | $this->odds[$key] = $value; |
| 228 | 228 | } |
| 229 | 229 | } |
@@ -240,13 +240,13 @@ discard block |
||
| 240 | 240 | |
| 241 | 241 | // if the service middleware does not represent a class, |
| 242 | 242 | // then in this case core support is assigned as a class service middleware. |
| 243 | - if(Utils::isNamespaceExists($serviceMiddleware)===false){
|
|
| 243 | + if (Utils::isNamespaceExists($serviceMiddleware)===false) {
|
|
| 244 | 244 | $serviceMiddleware = ServiceMiddlewareManager::class; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | //We are logging the kernel for the middleware class and the exclude class |
| 248 | - $this->app->register('middlewareClass',$this->app->resolve($serviceMiddleware));
|
|
| 249 | - $this->app->register('excludeClass',$this->app->resolve(ExcludeMiddleware::class));
|
|
| 248 | + $this->app->register('middlewareClass', $this->app->resolve($serviceMiddleware));
|
|
| 249 | + $this->app->register('excludeClass', $this->app->resolve(ExcludeMiddleware::class));
|
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | /** |
@@ -254,9 +254,9 @@ discard block |
||
| 254 | 254 | * |
| 255 | 255 | * @param null $serviceMiddleware |
| 256 | 256 | */ |
| 257 | - public function setserviceMiddleware($serviceMiddleware=null) |
|
| 257 | + public function setserviceMiddleware($serviceMiddleware = null) |
|
| 258 | 258 | {
|
| 259 | - if(!is_null($serviceMiddleware)){
|
|
| 259 | + if (!is_null($serviceMiddleware)) {
|
|
| 260 | 260 | $this->serviceMiddleware = $serviceMiddleware; |
| 261 | 261 | } |
| 262 | 262 | } |
@@ -271,11 +271,11 @@ discard block |
||
| 271 | 271 | {
|
| 272 | 272 | //If the all option is present, |
| 273 | 273 | //it is automatically injected into all services for the middleware application. |
| 274 | - if($key==="all") return true; |
|
| 274 | + if ($key==="all") return true; |
|
| 275 | 275 | |
| 276 | 276 | //service middleware key |
| 277 | 277 | //if it is array,check odds |
| 278 | - if(is_array($key)){
|
|
| 278 | + if (is_array($key)) {
|
|
| 279 | 279 | |
| 280 | 280 | //get middleware odd keys |
| 281 | 281 | $odds = $this->middlewareKeyOdds(); |
@@ -284,8 +284,8 @@ discard block |
||
| 284 | 284 | //then the middleware is conditioned and the services are individually checked according to |
| 285 | 285 | //the degree of conformity with the middlewareOdds method and |
| 286 | 286 | //the middleware is executed under the specified condition. |
| 287 | - foreach($key as $item){
|
|
| 288 | - if(in_array($item,$odds)){
|
|
| 287 | + foreach ($key as $item) {
|
|
| 288 | + if (in_array($item, $odds)) {
|
|
| 289 | 289 | return true; |
| 290 | 290 | } |
| 291 | 291 | } |
@@ -303,17 +303,17 @@ discard block |
||
| 303 | 303 | */ |
| 304 | 304 | private function pointer($middleValue) |
| 305 | 305 | {
|
| 306 | - if(isset($this->app['pointer']['middlewareList'])){
|
|
| 306 | + if (isset($this->app['pointer']['middlewareList'])) {
|
|
| 307 | 307 | |
| 308 | 308 | $middlewareList = $this->app['pointer']['middlewareList']; |
| 309 | 309 | |
| 310 | - if(is_array($middlewareList)){
|
|
| 311 | - $middlewareList = array_merge($middlewareList,[$middleValue]); |
|
| 312 | - $this->app->register('pointer','middlewareList',$middlewareList);
|
|
| 310 | + if (is_array($middlewareList)) {
|
|
| 311 | + $middlewareList = array_merge($middlewareList, [$middleValue]); |
|
| 312 | + $this->app->register('pointer', 'middlewareList', $middlewareList);
|
|
| 313 | 313 | } |
| 314 | 314 | } |
| 315 | - else{
|
|
| 316 | - $this->app->register('pointer','middlewareList',[$middleValue]);
|
|
| 315 | + else {
|
|
| 316 | + $this->app->register('pointer', 'middlewareList', [$middleValue]);
|
|
| 317 | 317 | } |
| 318 | 318 | } |
| 319 | 319 | } |
| 320 | 320 | \ No newline at end of file |