Revert "feat!: add append and prepend handler instead of reverse execution"

This reverts commit f41c4a2a5a.
This commit is contained in:
Denis Sokolov
2019-12-25 12:00:00 +02:00
parent b909d8899e
commit 8957f6fb70
2 changed files with 29 additions and 77 deletions
+5 -53
View File
@@ -41,52 +41,13 @@ final class Run implements RunInterface
}
/**
* Prepends a handler to the start of the stack
* Pushes a handler to the end of the stack
*
* @throws InvalidArgumentException If argument is not callable or instance of HandlerInterface
* @param Callable|HandlerInterface $handler
* @return Run
* @deprecated use appendHandler and prependHandler instead
*/
public function pushHandler($handler)
{
return $this->prependHandler($handler);
}
/**
* Appends a handler to the end of the stack
*
* @throws InvalidArgumentException If argument is not callable or instance of HandlerInterface
* @param Callable|HandlerInterface $handler
* @return Run
*/
public function appendHandler($handler)
{
array_push($this->handlerStack, $this->resolveHandler($handler));
return $this;
}
/**
* Prepends a handler to the start of the stack
*
* @throws InvalidArgumentException If argument is not callable or instance of HandlerInterface
* @param Callable|HandlerInterface $handler
* @return Run
*/
public function prependHandler($handler)
{
array_unshift($this->handlerStack, $this->resolveHandler($handler));
return $this;
}
/**
* Create a CallbackHandler from callable and throw if handler is invalid
*
* @throws InvalidArgumentException If argument is not callable or instance of HandlerInterface
* @param Callable|HandlerInterface $handler
* @return HandlerInterface
*/
private function resolveHandler($handler)
{
if (is_callable($handler)) {
$handler = new CallbackHandler($handler);
@@ -94,12 +55,13 @@ final class Run implements RunInterface
if (!$handler instanceof HandlerInterface) {
throw new InvalidArgumentException(
"Argument to " . __METHOD__ . " must be a callable, or instance of "
"Argument to " . __METHOD__ . " must be a callable, or instance of "
. "Whoops\\Handler\\HandlerInterface"
);
}
return $handler;
$this->handlerStack[] = $handler;
return $this;
}
/**
@@ -112,16 +74,6 @@ final class Run implements RunInterface
return array_pop($this->handlerStack);
}
/**
* Removes the first handler in the stack and returns it.
* Returns null if there"s nothing else to shift.
* @return null|HandlerInterface
*/
public function shiftHandler()
{
return array_shift($this->handlerStack);
}
/**
* Returns an array with all handlers, in the
* order they were added to the stack.
@@ -309,7 +261,7 @@ final class Run implements RunInterface
$handlerContentType = null;
try {
foreach ($this->handlerStack as $handler) {
foreach (array_reverse($this->handlerStack) as $handler) {
$handler->setRun($this);
$handler->setInspector($inspector);
$handler->setException($exception);
+24 -24
View File
@@ -82,8 +82,8 @@ class RunTest extends TestCase
$handlerOne = $this->getHandler();
$handlerTwo = $this->getHandler();
$run->prependHandler($handlerOne);
$run->prependHandler($handlerTwo);
$run->pushHandler($handlerOne);
$run->pushHandler($handlerTwo);
$handlers = $run->getHandlers();
@@ -99,7 +99,7 @@ class RunTest extends TestCase
public function testPushInvalidHandler()
{
$run = $this->getRunInstance();
$run->prependHandler($banana = 'actually turnip');
$run->pushHandler($banana = 'actually turnip');
}
/**
@@ -108,7 +108,7 @@ class RunTest extends TestCase
public function testPushClosureBecomesHandler()
{
$run = $this->getRunInstance();
$run->prependHandler(function () {});
$run->pushHandler(function () {});
$this->assertInstanceOf('Whoops\\Handler\\CallbackHandler', $run->popHandler());
}
@@ -124,9 +124,9 @@ class RunTest extends TestCase
$handlerTwo = $this->getHandler();
$handlerThree = $this->getHandler();
$run->appendHandler($handlerOne);
$run->appendHandler($handlerTwo);
$run->appendHandler($handlerThree);
$run->pushHandler($handlerOne);
$run->pushHandler($handlerTwo);
$run->pushHandler($handlerThree);
$this->assertSame($handlerThree, $run->popHandler());
$this->assertSame($handlerTwo, $run->popHandler());
@@ -164,7 +164,7 @@ class RunTest extends TestCase
$run->register();
$handler = $this->getHandler();
$run->prependHandler($handler);
$run->pushHandler($handler);
$run->unregister();
throw $this->getException("I'm not supposed to be caught!");
@@ -183,10 +183,10 @@ class RunTest extends TestCase
$handlerThree = $this->getHandler();
$handlerFour = $this->getHandler();
$run->appendHandler($handlerOne);
$run->appendHandler($handlerTwo);
$run->appendHandler($handlerThree);
$run->appendHandler($handlerFour);
$run->pushHandler($handlerOne);
$run->pushHandler($handlerTwo);
$run->pushHandler($handlerThree);
$run->pushHandler($handlerFour);
$handlers = $run->getHandlers();
@@ -218,9 +218,9 @@ class RunTest extends TestCase
$handlerThree->shouldReceive('handle')
->andReturnUsing(function () use ($order) { $order[] = 3; });
$run->prependHandler($handlerOne);
$run->prependHandler($handlerTwo);
$run->prependHandler($handlerThree);
$run->pushHandler($handlerOne);
$run->pushHandler($handlerTwo);
$run->pushHandler($handlerThree);
// Get an exception to be handled, and verify that the handlers
// are given the handler, and in the inverse order they were
@@ -239,8 +239,8 @@ class RunTest extends TestCase
$handlerOne = $this->getHandler();
$handlerTwo = $this->getHandler();
$run->prependHandler($handlerOne);
$run->prependHandler($handlerTwo);
$run->pushHandler($handlerOne);
$run->pushHandler($handlerTwo);
$test = $this;
$handlerOne
@@ -268,7 +268,7 @@ class RunTest extends TestCase
$run->register();
$handler = $this->getHandler();
$run->prependHandler($handler);
$run->pushHandler($handler);
$test = $this;
$handler
@@ -289,7 +289,7 @@ class RunTest extends TestCase
$run->register();
$handler = $this->getHandler();
$run->prependHandler($handler);
$run->pushHandler($handler);
$test = $this;
$handler
@@ -318,7 +318,7 @@ class RunTest extends TestCase
$run->register();
$handler = $this->getHandler();
$run->prependHandler($handler);
$run->pushHandler($handler);
$test = $this;
$handler
@@ -344,7 +344,7 @@ class RunTest extends TestCase
$run->register();
$handler = $this->getHandler();
$run->prependHandler($handler);
$run->pushHandler($handler);
$test = $this;
$handler
@@ -367,7 +367,7 @@ class RunTest extends TestCase
$run->register();
$handler = $this->getHandler();
$run->prependHandler($handler);
$run->pushHandler($handler);
@strpos();
@@ -402,7 +402,7 @@ class RunTest extends TestCase
public function testOutputIsSent()
{
$run = $this->getRunInstance();
$run->prependHandler(function () {
$run->pushHandler(function () {
echo "hello there";
});
@@ -419,7 +419,7 @@ class RunTest extends TestCase
{
$run = $this->getRunInstance();
$run->writeToOutput(false);
$run->prependHandler(function () {
$run->pushHandler(function () {
echo "hello there";
});