Example #1
0
 public function testCanCallPageNotFoundError()
 {
     $viewMock = $this->getMock('PopHub\\View\\Error', array('showPageNotFound'));
     $viewMock->expects($this->once())->method('showPageNotFound');
     $controller = new Controller\Error($viewMock);
     $controller->pageNotFoundError("1");
 }
Example #2
0
 public function doRoute()
 {
     $klein = new Klein();
     $this->config = new Config("../app/config/app.php");
     $klein->respond("GET", $this->homePath, function () {
         $controller = new Home(new View\Home());
         $controller->index();
     });
     $klein->respond("GET", $this->loginPath . "?", function ($request, $response) {
         $url = $this->auth->index();
         $response->redirect($url);
     });
     $klein->respond("GET", "/github-callback/?", function ($request, $response) {
         if ($request->code) {
             $this->auth->getToken($request->code);
             return $response->redirect($this->userPath);
         }
         return $response->redirect($this->homePath);
     });
     $klein->respond("GET", $this->userPath . "?", function ($request, $response) {
         $session = new Session();
         $token = $session->get($this->auth->getTokenSessionName());
         if ($token) {
             return $this->auth->loggedInUser($token);
         }
         return $response->redirect($this->homePath);
     });
     $klein->respond("GET", $this->logoutPath . "?", function ($request, $response) {
         $session = new Session();
         $session->destroy($this->auth->getTokenSessionName());
         return $response->redirect($this->homePath);
     });
     $klein->with($this->usersPath, function () use($klein) {
         $klein->respond("GET", "/?", function ($request, $response) {
             $controller = new Users();
             $controller->index($request->fetchFromID);
         });
         $klein->respond("GET", "/[:username]/?", function ($request, $response) {
             $controller = new Users();
             $controller->show($request->username);
         });
     });
     $klein->respond("GET", $this->searchPath . "?", function ($request, $response) {
         $controller = new Users();
         $controller->search();
     });
     $klein->respond("GET", $this->followPath . "[:username]/?", function ($request, $response) {
         $controller = new Users();
         $controller->follow($request->username);
     });
     $klein->respond("GET", $this->unFollowPath . "[:username]/?", function ($request, $response) {
         $controller = new Users();
         $controller->unFollow($request->username);
     });
     $klein->respond("404", function ($request) {
         $page = $request->uri();
         $controller = new Error(new View\Error());
         $controller->pageNotFoundError($page);
     });
     $klein->onError(function ($klein, $err_msg) {
         if ($this->config->get("DEBUG") === true) {
             throw new \Exception($err_msg);
         } else {
             $controller = new Error(new View\Error());
             $controller->serverError();
             error_log($err_msg, 3, $this->config->get("ERROR_LOG"));
         }
     });
     $klein->dispatch();
 }