Skip to content

Instantly share code, notes, and snippets.

@dhrrgn
Last active August 29, 2015 14:22
Show Gist options
  • Save dhrrgn/d8f74e1cbbe3cd6ba63b to your computer and use it in GitHub Desktop.
Save dhrrgn/d8f74e1cbbe3cd6ba63b to your computer and use it in GitHub Desktop.
<?php
namespace Core\Middleware;
use Slim\Middleware;
/**
* A Middleware implemenation which will send any exceptions to the Slim
* error handler.
* @package Core\Middleware
*/
abstract class AbstractMiddleware extends Middleware
{
/**
* Do the Middleware processing.
*/
abstract protected function process();
/**
* Wraps the middleware call in a try/catch and sends any errors
* to the Slim error handler.
*/
public function call()
{
try {
$this->process();
} catch (\Exception $e) {
try {
$this->app->error($e);
} catch (\Slim\Exception\Stop $e) {
// Do nothing
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment