/**
  * Call error handler
  *
  * This will invoke the custom or default error handler
  * and RETURN its output.
  *
  * @param   Exception|null  $argument
  * @return  string
  */
 protected function callErrorHandler($argument = null)
 {
     ob_start();
     $customErrorHandler = $this->router->error();
     if (is_callable($customErrorHandler)) {
         call_user_func_array($customErrorHandler, array($argument));
     } else {
         call_user_func_array(array($this, 'defaultError'), array($argument));
     }
     return ob_get_clean();
 }
 /**
  * Error Handler
  *
  * This method defines or invokes the application-wide Error handler.
  * There are two contexts in which this method may be invoked:
  *
  * 1. When declaring the handler:
  *
  * If the $callable parameter is not null and is callable, this
  * method will register the callable to be invoked when an uncaught
  * Exception or Error is detected. It WILL NOT invoke the handler.
  *
  * 2. When invoking the handler:
  *
  * If the $callable parameter is null, Slim assumes you want
  * to invoke an already-registered handler. If the handler has been
  * registered and is callable, it is invoked and sends a 500 HTTP Response
  * whose body is the output of the Error handler.
  *
  * @param   mixed $callable Anything that returns true for is_callable()
  * @return  void
  */
 public function error($callable = null)
 {
     if (!is_null($callable) && $callable instanceof Exception === false) {
         $this->router->error($callable);
     } else {
         ob_start();
         $customErrorHandler = $this->router->error();
         if (is_callable($customErrorHandler)) {
             call_user_func_array($customErrorHandler, array($callable));
         } else {
             call_user_func_array(array($this, 'defaultError'), array($callable));
         }
         $this->halt(500, ob_get_clean());
     }
 }
Example #3
0
 /**
  * Router should NOT keep reference to a callback that is not callable
  */
 public function testErrorHandlerIfNotCallable()
 {
     $router = new Slim_Router($this->req, $this->res);
     $errCallback = 'foo';
     $callback = $router->error($errCallback);
     $this->assertNull($callback);
 }
 /**
  * Router should NOT keep reference to a callback that is not callable
  */
 public function testErrorHandlerIfNotCallable()
 {
     $request = new Slim_Http_Request();
     $router = new Slim_Router($request);
     $errCallback = 'foo';
     $callback = $router->error($errCallback);
     $this->assertEquals($callback, null);
 }
Example #5
0
 /**
  * Error Handler
  *
  * This method defines or invokes the application-wide Error handler.
  * There are two contexts in which this method may be invoked:
  *
  * 1. When declaring the handler:
  *
  * If the $argument parameter is callable, this
  * method will register the callable to be invoked when an uncaught
  * Exception is detected, or when otherwise explicitly invoked.
  * The handler WILL NOT be invoked in this context.
  *
  * 2. When invoking the handler:
  *
  * If the $argument parameter is not callable, Slim assumes you want
  * to invoke an already-registered handler. If the handler has been
  * registered and is callable, it is invoked and passed the caught Exception
  * as its one and only argument. The error handler's output is captured
  * into an output buffer and sent as the body of a 500 HTTP Response.
  *
  * @param   mixed $argument Callable|Exception
  * @return  void
  */
 public function error($argument = null)
 {
     if (is_callable($argument)) {
         //Register error handler
         $this->router->error($argument);
     } else {
         //Invoke error handler
         ob_start();
         $customErrorHandler = $this->router->error();
         if (is_callable($customErrorHandler)) {
             call_user_func_array($customErrorHandler, array($argument));
         } else {
             call_user_func_array(array($this, 'defaultError'), array($argument));
         }
         $this->halt(500, ob_get_clean());
     }
 }
Example #6
0
 /**
  * Router should NOT keep reference to a callback that is not callable
  */
 public function testErrorHandlerIfNotCallable()
 {
     $router = new Slim_Router();
     $router->setResourceUri($this->req->getResourceUri());
     $errCallback = 'foo';
     $callback = $router->error($errCallback);
     $this->assertNull($callback);
 }