Esempio n. 1
0
 /**
  *
  * @return Yasc_App
  */
 public function getApp()
 {
     if (null === $this->_app) {
         $this->_app = Yasc_App::getInstance();
     }
     return $this->_app;
 }
Esempio n. 2
0
File: Url.php Progetto: nebiros/yasc
 /**
  *
  * @param string $path
  * @return string
  */
 protected function urlFor($path)
 {
     $appConfig = \Yasc_App::config()->getOption("appConfig");
     $options = array();
     if (isset($appConfig["url_force_https"])) {
         $options["url_force_https"] = (bool) $appConfig["url_force_https"];
     }
     return Yasc_App::getInstance()->getRouter()->urlFor($path, $options);
 }
Esempio n. 3
0
 /**
  *
  * @param array $functions
  */
 public function __construct(array $functions)
 {
     $this->_functions = $functions;
     $this->_request = Yasc_App::getInstance()->getRequest();
 }
Esempio n. 4
0
 /**
  *
  * @param string $name
  * @param int $type
  * @return mixed 
  */
 public function getHelper($name, $type = null)
 {
     $helperId = null;
     switch ((int) $type) {
         case self::HELPER_TYPE_FUNCTION:
             $paths = $this->getFunctionHelperPaths();
             $helperId = $name . "-" . self::HELPER_TYPE_FUNCTION;
             break;
         case self::HELPER_TYPE_VIEW:
         default:
             $paths = $this->getViewHelperPaths();
             $helperId = $name . "-" . self::HELPER_TYPE_VIEW;
             break;
     }
     $className = trim(ucfirst((string) $name));
     foreach ($paths as $classPrefix => $path) {
         $class = $classPrefix . $className;
         if (true === class_exists($class) && false === isset($this->_helpers[$helperId])) {
             if (true === is_callable(array($class, "getInstance"))) {
                 $this->_helpers[$helperId] = call_user_func(array($class, "getInstance"));
             } else {
                 $this->_helpers[$helperId] = new $class();
             }
             if (true === is_callable(array($this->_helpers[$helperId], "setView"))) {
                 $this->_helpers[$helperId]->setView(Yasc_App::getInstance()->getView());
             }
             break;
         }
     }
     if (null === $this->_helpers[$helperId]) {
         throw new Yasc_App_Exception("Helper '{$name}' was not found in '" . implode("', '", $paths) . "'");
     }
     return $this->_helpers[$helperId];
 }
Esempio n. 5
0
 /**
  *
  * @return Yasc_Function_Helper_Flash
  */
 public function messages()
 {
     /* @var $f Yasc_Function_Helper_Flash */
     $f = Yasc_App::functionHelper("flash");
     return $f;
 }
Esempio n. 6
0
 /**
  * 
  * @param string $type "json", "js", "xml"
  * @param mixed $message
  * @param Array $options (bool) "set_common_headers", (bool) "echo"
  * @return string
  */
 public function render($type, $message = "", array $options = null)
 {
     if (!isset($options["set_common_headers"])) {
         $options["set_common_headers"] = true;
     }
     if (!isset($options["echo"])) {
         $options["echo"] = true;
     }
     if ((bool) $options["set_common_headers"]) {
         $this->setCommonHeaders();
     }
     $this->setContentTypeHeaderFor($type);
     $return = "";
     switch ($type) {
         case "json":
             $return = json_encode($message, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
             break;
         case "js":
             $return = $message;
             break;
         case "xml":
             if (is_array($message)) {
                 $return = Yasc_Util::arrayToXml($message);
             } else {
                 if (is_string($message)) {
                     $return = $message;
                 }
             }
             break;
         default:
             $return = $message;
             break;
     }
     if ((bool) $options["echo"]) {
         \Yasc_App::view()->layout()->disable();
         \Yasc_App::response()->setBody($return)->sendResponse();
         exit;
     }
     return $return;
 }
Esempio n. 7
0
 public function sendResponse()
 {
     if (in_array($this->getStatus(), array(204, 304))) {
         $headers = $this->getHeaders();
         unset($headers["Content-Type"], $headers["Content-Length"]);
         $this->setHeaders($headers);
         $this->clearBody();
     }
     $this->sendHeaders();
     if ($this->isRedirection()) {
         exit;
     }
     if (!\Yasc_App::request()->isHead()) {
         $this->outputBody();
     }
 }
Esempio n. 8
0
File: app.php Progetto: nebiros/yasc
/**
 * @DELETE("/delete")
 */
function destroy()
{
    Yasc_App::view()->layout()->disable();
    // $mysql = Yasc_App::config()->getOption("db");
    // $mysql->delete("table1", "id = {$_POST["id"]}");
    return header("Location: " . Yasc_App::viewHelper("url")->url(array("path" => "/update")));
}
Esempio n. 9
0
File: App.php Progetto: nebiros/yasc
 /**
  * @return Yasc_Http_Request
  */
 public static function response()
 {
     return self::$_instance->getResponse();
 }
Esempio n. 10
0
/**
 * @GET("/")
 */
function index()
{
    $translator = Yasc_App::config()->getOption("translator");
    echo "Hello world!" . "\n\n";
    echo $translator->trans("Hello World!") . "\n\n";
}
Esempio n. 11
0
 /**
  * Route requested url, find script function to be invoked.
  *
  * @return Yasc_Function
  */
 public function route()
 {
     $route = new Yasc_Router_Route($this->_app->getFunctions());
     $requestedFunction = $route->match()->getRequestedFunction();
     return $requestedFunction;
 }
Esempio n. 12
0
 /**
  *
  * @param string $filename
  * @return Yasc_View
  */
 public function setViewScript($filename)
 {
     $this->_viewScript = null;
     $folders = Yasc_App::getInstance()->getConfig()->getViewsPaths();
     foreach ($folders as $path) {
         if (true === is_file(realpath($path . "/" . $filename . ".phtml"))) {
             $this->_viewScript = realpath($path . "/" . $filename . ".phtml");
             break;
         }
     }
     if (null === $this->_viewScript) {
         throw new Yasc_View_Exception("View file '{$filename}' not found in this paths: " . implode(", ", $folders));
     }
     return $this;
 }