/**
  * 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()
  * @return  void
  */
 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());
     }
 }
Ejemplo n.º 2
0
 /**
  * Router should NOT keep reference to a callback that is not callable
  */
 public function testNotFoundHandlerIfNotCallable()
 {
     $request = new Slim_Http_Request();
     $router = new Slim_Router($request);
     $notFoundCallback = 'foo';
     $callback = $router->notFound($notFoundCallback);
     $this->assertEquals($callback, null);
 }
Ejemplo n.º 3
0
 /**
  * Router should NOT keep reference to a callback that is not callable
  */
 public function testNotFoundHandlerIfNotCallable()
 {
     $router = new Slim_Router($this->req, $this->res);
     $notFoundCallback = 'foo';
     $callback = $router->notFound($notFoundCallback);
     $this->assertNull($callback);
 }
Ejemplo n.º 4
0
 /**
  * Router should NOT keep reference to a callback that is not callable
  */
 public function testNotFoundHandlerIfNotCallable()
 {
     $router = new Slim_Router();
     $router->setResourceUri($this->req->getResourceUri());
     $notFoundCallback = 'foo';
     $callback = $router->notFound($notFoundCallback);
     $this->assertNull($callback);
 }