From e559fb6958261b74f4ffbb65143ae2a042c47beb Mon Sep 17 00:00:00 2001 From: Jack Luhn Date: Fri, 22 Jul 2022 22:16:48 +0200 Subject: [PATCH] First Reimplementation of skipRemaining() and skip() --- src/Klein/Klein.php | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/Klein/Klein.php b/src/Klein/Klein.php index 587379fd..d0355faf 100644 --- a/src/Klein/Klein.php +++ b/src/Klein/Klein.php @@ -200,6 +200,15 @@ class Klein protected $app; + /** + * Skip Counter + * + * @type int + */ + protected $skips = 0; + + + /** * Methods */ @@ -585,6 +594,13 @@ public function dispatch( // Handle our response callback try { + + if($this->skips == -1) break; + if($this->skips > 0) { + $this->skips--; + continue; + } + $this->handleRouteCallback($route, $matched, $methods_matched); } catch (DispatchHaltedException $e) { @@ -592,11 +608,15 @@ public function dispatch( case DispatchHaltedException::SKIP_THIS: continue 2; break; + + /* case DispatchHaltedException::SKIP_NEXT: $skip_num = $e->getNumberOfSkips(); break; case DispatchHaltedException::SKIP_REMAINING: break 2; + */ + default: throw $e; } @@ -1095,10 +1115,11 @@ public function skipThis() */ public function skipNext($num = 1) { - $skip = new DispatchHaltedException(null, DispatchHaltedException::SKIP_NEXT); - $skip->setNumberOfSkips($num); + //$skip = new DispatchHaltedException(null, DispatchHaltedException::SKIP_NEXT); + //$skip->setNumberOfSkips($num); - throw $skip; + //throw $skip; + $this->skips = $num; } /** @@ -1109,7 +1130,8 @@ public function skipNext($num = 1) */ public function skipRemaining() { - throw new DispatchHaltedException(null, DispatchHaltedException::SKIP_REMAINING); + //throw new DispatchHaltedException(null, DispatchHaltedException::SKIP_REMAINING); + $this->skips = -1; //Remaining } /**