Esempio n. 1
0
 public function shutdown(Sabel_Bus $bus)
 {
     $response = $bus->get("response");
     $redirector = $response->getRedirector();
     if ($redirector->isRedirected()) {
         if (($url = $redirector->getUrl()) !== "") {
             $response->setLocation($url);
         } else {
             $location = $redirector->getUri(true, false);
             if (($session = $bus->get("session")) !== null) {
                 if ($session->isStarted() && !$session->isCookieEnabled()) {
                     $glue = $redirector->hasParameters() ? "&" : "?";
                     $location .= $glue . $session->getName() . "=" . $session->getId();
                 }
             }
             if (($flagment = $redirector->getFlagment()) !== "") {
                 $location .= "#{$flagment}";
             }
             if (function_exists("get_uri_prefix")) {
                 $location = get_uri_prefix() . $location;
             }
             $response->setLocation($location);
         }
     }
     $response->outputHeader();
 }
Esempio n. 2
0
 public function shutdown(Sabel_Bus $bus)
 {
     $response = $bus->get("response");
     $redirector = $response->getRedirector();
     if ($redirector->isRedirected()) {
         if (($url = $redirector->getUrl()) !== "") {
             $response->setLocation($url);
         } else {
             $token = $bus->get("request")->getValueWithMethod("token");
             $hasToken = !empty($token);
             $hasParams = $redirector->hasParameters();
             $location = $redirector->getUri();
             if ($hasToken) {
                 $glue = $hasParams ? "&" : "?";
                 $location .= $glue . "token={$token}";
             }
             $session = $bus->get("session");
             if ($session->isStarted() && !$session->isCookieEnabled()) {
                 $glue = $hasToken || $hasParams ? "&" : "?";
                 $location .= $glue . $session->getName() . "=" . $session->getId();
             }
             if (function_exists("get_uri_prefix")) {
                 $location = get_uri_prefix() . "/" . ltrim($location, "/");
             }
             $response->setLocation($location);
         }
     }
     $response->outputHeader();
 }
Esempio n. 3
0
 public function execute(Sabel_Bus $bus)
 {
     if ($bus->has("request")) {
         $request = $bus->get("request");
     } else {
         $uri = $this->getRequestUri($bus);
         $request = new Sabel_Request_Object($uri);
         if (SBL_SECURE_MODE) {
             $_GET = remove_nullbyte($_GET);
             $_POST = remove_nullbyte($_POST);
         }
         $request->setGetValues($_GET);
         $request->setPostValues($_POST);
         $this->setFiles($request);
         if (isset($_SERVER["REQUEST_METHOD"])) {
             $request->method($_SERVER["REQUEST_METHOD"]);
         }
         $httpHeaders = array();
         foreach ($_SERVER as $key => $val) {
             if (strpos($key, "HTTP") === 0) {
                 $httpHeaders[$key] = $val;
             }
         }
         $request->setHttpHeaders($httpHeaders);
         $bus->set("request", $request);
     }
     l("REQUEST URI: /" . $request->getUri(true));
     // Ajax request.
     if ($request->getHttpHeader("X-Requested-With") === "XMLHttpRequest") {
         $bus->set("NO_LAYOUT", true);
         $bus->set("IS_AJAX_REQUEST", true);
     }
 }
Esempio n. 4
0
 public function shutdown(Sabel_Bus $bus)
 {
     $session = $bus->get("session");
     if ($session->isStarted() && !$session->isCookieEnabled() && ini_get("session.use_trans_sid") === "0") {
         output_add_rewrite_var($session->getName(), $session->getId());
     }
 }
Esempio n. 5
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);
         }
     }
 }
Esempio n. 6
0
 public function execute(Sabel_Bus $bus)
 {
     $config = $bus->getConfig("addon");
     $addons = $config->configure();
     foreach ($addons as $addon) {
         $className = ucfirst($addon) . "_Addon";
         $instance = new $className();
         $instance->execute($bus);
     }
 }
Esempio n. 7
0
 public function execute(Sabel_Bus $bus)
 {
     Sabel_Db_Config::initialize($bus->getConfig("database"));
     if (!is_cli() && ($session = $bus->get("session")) !== null) {
         $session->start();
         l("START SESSION: " . $session->getName() . "=" . $session->getId());
     }
     // default page title.
     if ($response = $bus->get("response")) {
         $response->setResponse("pageTitle", "Sabel");
     }
 }
Esempio n. 8
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;
 }
Esempio n. 9
0
 public function execute(Sabel_Bus $bus)
 {
     Sabel_Db_Config::initialize($bus->getConfig("database"));
     //Sabel::fileUsing(RUN_BASE . DS . LIB_DIR_NAME . DS . "db" . DS . "utility.php", true);
     if (!defined("SBL_BATCH")) {
         // start session.
         $session = $bus->get("session");
         $session->start();
         l("START SESSION: " . $session->getName() . "=" . $session->getId());
     }
     // default page title.
     $bus->get("response")->setResponse("pageTitle", "Sabel");
     // $request = $bus->get("request");
     // if ($request->isPost()) $this->trim($request);
 }
Esempio n. 10
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);
     }
 }
Esempio n. 11
0
 public function execute(Sabel_Bus $bus)
 {
     $destination = $bus->get("destination");
     $moduleName = $destination->getModule();
     $controllerName = $destination->getController();
     $sharedHelper = "application";
     $commonHelpers = MODULES_DIR_PATH . DS . HELPERS_DIR_NAME;
     $moduleHelpers = MODULES_DIR_PATH . DS . $moduleName . DS . HELPERS_DIR_NAME;
     $helpers = array();
     $helpers[] = $commonHelpers . DS . $sharedHelper;
     $helpers[] = $moduleHelpers . DS . $sharedHelper;
     $helpers[] = $moduleHelpers . DS . $controllerName;
     foreach ($helpers as $helper) {
         Sabel::fileUsing($helper . ".php", true);
     }
 }
Esempio n. 12
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");
     }
 }
Esempio n. 13
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);
     }
 }
Esempio n. 14
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);
 }
Esempio n. 15
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");
 }
Esempio n. 16
0
<?php

ob_start();
define("RUN_BASE", dirname(realpath(".")));
//require ("Sabel"  . DIRECTORY_SEPARATOR . "Sabel.php");
require RUN_BASE . DIRECTORY_SEPARATOR . "Sabel" . DIRECTORY_SEPARATOR . "Sabel.php";
require RUN_BASE . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "INIT.php";
require RUN_BASE . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "environment.php";
if (!defined("ENVIRONMENT")) {
    echo "SABEL FATAL ERROR: must define ENVIRONMENT in config/environment.php";
    exit;
}
if ((ENVIRONMENT & PRODUCTION) > 0) {
    Sabel::init();
    echo Sabel_Bus::create()->run(new Config_Bus());
    Sabel::shutdown();
} else {
    echo Sabel_Bus::create()->run(new Config_Bus());
}
ob_flush();
Esempio n. 17
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;
 }