Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First Reimplementation of skipRemaining() and skip() Issue #156 #411

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions src/Klein/Klein.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ class Klein
protected $app;


/**
* Skip Counter
*
* @type int
*/
protected $skips = 0;



/**
* Methods
*/
Expand Down Expand Up @@ -585,18 +594,29 @@ 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) {
switch ($e->getCode()) {
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;
}
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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
}

/**
Expand Down