Skip to content

Commit 246bcb8

Browse files
committed
Middleware returns ResponseInterface with a status code other than 200-299; The procedure is abandoned early.
1 parent 8627191 commit 246bcb8

File tree

6 files changed

+18
-6
lines changed

6 files changed

+18
-6
lines changed

src/Exception/InvalidArgumentException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
88
* @copyright Copyright © 2022 Muhammet ŞAFAK
99
* @license ./LICENSE MIT
10-
* @version 1.1.1
10+
* @version 1.1.2
1111
* @link https://www.muhammetsafak.com.tr
1212
*/
1313

src/Exception/PageNotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
88
* @copyright Copyright © 2022 Muhammet ŞAFAK
99
* @license ./LICENSE MIT
10-
* @version 1.1.1
10+
* @version 1.1.2
1111
* @link https://www.muhammetsafak.com.tr
1212
*/
1313

src/Exception/RouterException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
88
* @copyright Copyright © 2022 Muhammet ŞAFAK
99
* @license ./LICENSE MIT
10-
* @version 1.1.1
10+
* @version 1.1.2
1111
* @link https://www.muhammetsafak.com.tr
1212
*/
1313

src/Middleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
88
* @copyright Copyright © 2022 Muhammet ŞAFAK
99
* @license ./LICENSE MIT
10-
* @version 1.1.1
10+
* @version 1.1.2
1111
* @link https://www.muhammetsafak.com.tr
1212
*/
1313

src/Router.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
88
* @copyright Copyright © 2022 Muhammet ŞAFAK
99
* @license ./LICENSE MIT
10-
* @version 1.1.1
10+
* @version 1.1.2
1111
* @link https://www.muhammetsafak.com.tr
1212
*/
1313

@@ -719,6 +719,10 @@ public function dispatch(): ResponseInterface
719719
}
720720

721721
$this->middleware_handle($filters['before'], $arguments, self::BEFORE);
722+
$responseStatusCode = (int)$this->response->getStatusCode();
723+
if($responseStatusCode < 200 || $responseStatusCode > 299){
724+
return $this->response;
725+
}
722726

723727
if(\is_callable($route['execute'])){
724728
\define('INITPHP_ROUTER_CURRENT_CONTROLLER', '__CALLABLE__');
@@ -732,6 +736,10 @@ public function dispatch(): ResponseInterface
732736
$this->middleware_handle($this->controller_middlewares_property($controller, $parse['method'], self::BEFORE), $arguments, self::BEFORE);
733737
\define('INITPHP_ROUTER_CURRENT_CONTROLLER', \get_class($controller));
734738
\define('INITPHP_ROUTER_CURRENT_METHOD', $parse['method']);
739+
$responseStatusCode = (int)$this->response->getStatusCode();
740+
if($responseStatusCode < 200 || $responseStatusCode > 299){
741+
return $this->response;
742+
}
735743
$this->response = $this->execute([$controller, $parse['method']], $arguments);
736744
$after_middleware = $this->controller_middlewares_property($controller, $parse['method'], self::AFTER);
737745
if(!empty($after_middleware)){
@@ -910,6 +918,10 @@ private function middleware_handle(array $filters, $arguments, int $pos): void
910918
}
911919
if($res instanceof ResponseInterface){
912920
$this->response = $res;
921+
$statusCode = (int)$res->getStatusCode();
922+
if($statusCode < 200 || $statusCode > 299){
923+
break;
924+
}
913925
continue;
914926
}
915927
if($res === null){

src/Uri.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
88
* @copyright Copyright © 2022 Muhammet ŞAFAK
99
* @license ./LICENSE MIT
10-
* @version 1.1.1
10+
* @version 1.1.2
1111
* @link https://www.muhammetsafak.com.tr
1212
*/
1313

0 commit comments

Comments
 (0)