Example #1
0
 /**
  * Not Found Handler
  *
  * This method defines or invokes the application-wide Not Found 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 no
  * routes match the current HTTP request. It WILL NOT invoke the callable.
  *
  * 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 404 HTTP Response
  * whose body is the output of the Not Found handler.
  *
  * @param  mixed $callable Anything that returns true for is_callable()
  */
 public function notFound($callable = null)
 {
     if (!is_null($callable)) {
         $this->router->notFound($callable);
     } else {
         ob_start();
         $customNotFoundHandler = $this->router->notFound();
         if (is_callable($customNotFoundHandler)) {
             call_user_func($customNotFoundHandler);
         } else {
             call_user_func(array($this, 'defaultNotFound'));
         }
         $this->halt(404, ob_get_clean());
     }
 }