/** * * @return Yasc_App */ public function getApp() { if (null === $this->_app) { $this->_app = Yasc_App::getInstance(); } return $this->_app; }
/** * * @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); }
/** * * @param array $functions */ public function __construct(array $functions) { $this->_functions = $functions; $this->_request = Yasc_App::getInstance()->getRequest(); }
/** * * @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]; }
/** * * @return Yasc_Function_Helper_Flash */ public function messages() { /* @var $f Yasc_Function_Helper_Flash */ $f = Yasc_App::functionHelper("flash"); return $f; }
/** * * @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; }
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(); } }
/** * @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"))); }
/** * @return Yasc_Http_Request */ public static function response() { return self::$_instance->getResponse(); }
/** * @GET("/") */ function index() { $translator = Yasc_App::config()->getOption("translator"); echo "Hello world!" . "\n\n"; echo $translator->trans("Hello World!") . "\n\n"; }
/** * 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; }
/** * * @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; }