Example #1
0
 public function execute(Sabel_Bus $bus)
 {
     $response = $bus->get("response");
     if ($response->isRedirected()) {
         return;
     }
     $controller = $bus->get("controller");
     $responses = $response->getResponses();
     $contents = isset($responses["contents"]) ? $responses["contents"] : "";
     $view = $this->setTemplateName($bus->get("view"), $response->getStatus(), $bus->get("destination")->getAction(), $bus->get("IS_AJAX_REQUEST") === true);
     if (is_empty($contents)) {
         if ($location = $view->getValidLocation()) {
             $contents = $view->rendering($location, $responses);
         } elseif (!$controller->isExecuted()) {
             $response->getStatus()->setCode(Sabel_Response::NOT_FOUND);
             if ($location = $view->getValidLocation("notFound")) {
                 $contents = $view->rendering($location, $responses);
             } else {
                 $contents = "<h1>404 Not Found</h1>";
             }
         }
     }
     if ($bus->get("NO_LAYOUT")) {
         $bus->set("result", $contents);
     } else {
         $layout = isset($responses["layout"]) ? $responses["layout"] : DEFAULT_LAYOUT_NAME;
         if ($location = $view->getValidLocation($layout)) {
             $responses["contentForLayout"] = $contents;
             $bus->set("result", $view->rendering($location, $responses));
         } else {
             // no layout.
             $bus->set("result", $contents);
         }
     }
 }
Example #2
0
 public function setUp()
 {
     $bus = new Sabel_Bus();
     $request = new Sabel_Request_Object("index/index");
     $storage = new Sabel_Storage_InMemory();
     $controller = new StandardFlow();
     $destination = new Sabel_Destination("index", "index", "top");
     $controller->setup($request, $destination, $storage);
     $bus->set("request", $request);
     $bus->set("storage", $storage);
     $bus->set("controller", $controller);
     $bus->set("destination", $destination);
     $this->bus = $bus;
 }
Example #3
0
 protected function request(Sabel_Request $request, $session = null, $maxRedirects = 0)
 {
     if ($session === null) {
         $session = Sabel_Session_InMemory::create();
     }
     Sabel_Cookie_Factory::create()->set($session->getName(), $session->getId());
     if ($maxRedirects > 0) {
         return $this->requestWithRedirect($request, $session, $maxRedirects);
     } else {
         $bus = new Sabel_Bus();
         $bus->set("request", $request);
         $bus->set("session", $session);
         $bus->run(new Config_Bus());
         return $bus->get("response");
     }
 }
Example #4
0
 public function execute(Sabel_Bus $bus)
 {
     $request = $bus->get("request");
     $config = $bus->getConfig("map");
     $config->configure();
     if ($candidate = $config->getValidCandidate($request->getUri())) {
         $request->setParameterValues(array_map("urldecode", $candidate->getUriParameters()));
         $destination = $candidate->getDestination();
         l("DESTINATION: " . $destination);
         $bus->set("destination", $destination);
         Sabel_Context::getContext()->setCandidate($candidate);
     } else {
         $message = __METHOD__ . "() didn't match to any routing configuration.";
         throw new Sabel_Exception_Runtime($message);
     }
 }
Example #5
0
 public function execute(Sabel_Bus $bus)
 {
     $destination = $bus->get("destination");
     if (($controller = $this->createController($destination)) === null) {
         $controller = $this->createVirtualController();
     }
     if ($response = $bus->get("response")) {
         $controller->setResponse($response);
         if ($controller instanceof $this->virtualControllerName) {
             $response->getStatus()->setCode(Sabel_Response::NOT_FOUND);
         }
     }
     if ($request = $bus->get("request")) {
         $controller->setRequest($request);
     }
     if ($session = $bus->get("session")) {
         $controller->setSession($session);
     }
     $bus->set("controller", $controller);
 }
Example #6
0
 public function execute(Sabel_Bus $bus)
 {
     $response = $bus->get("response");
     $controller = $bus->get("controller");
     if ($response->isFailure() || $response->isRedirected()) {
         return;
     }
     $action = $bus->get("destination")->getAction();
     $controller->setAction($action);
     try {
         $controller->initialize();
         if ($response->isSuccess() && !$response->isRedirected()) {
             $controller->execute();
         }
         $controller->finalize();
     } catch (Exception $e) {
         $response->getStatus()->setCode(Sabel_Response::INTERNAL_SERVER_ERROR);
         Sabel_Context::getContext()->setException($e);
     }
     if ($controller->getAttribute("layout") === false) {
         $bus->set("NO_LAYOUT", true);
     }
 }
Example #7
0
 public function execute(Sabel_Bus $bus)
 {
     if (!$bus->has("session")) {
         $bus->set("session", Sabel_Session_PHP::create());
     }
 }
Example #8
0
 public function execute(Sabel_Bus $bus)
 {
     $bus->set("response", new Sabel_Response_Object());
 }
Example #9
0
 public function execute(Sabel_Bus $bus)
 {
     $this->a = $bus->get("a");
     $this->b = $bus->get("b");
     if ($this->a !== "10") {
         throw new Exception("test error");
     }
     if ($this->b !== "20") {
         throw new Exception("test error");
     }
     $bus->set("result", "foo_result");
 }
Example #10
0
 protected function getBus($uri)
 {
     $bus = new Sabel_Bus();
     $bus->set("request", new Sabel_Request_Object($uri));
     $bus->set("session", Sabel_Session_InMemory::create());
     return $bus;
 }