Esempio n. 1
0
 public function wait()
 {
     $data = array("request_id" => 123456789);
     file_put_contents(LOG_PATH . "request.log", date("Y-m-d H:i:s") . " wait before response\n", FILE_APPEND);
     UbinEngine::RenderJson(json_encode($data), true);
     sleep(10);
     file_put_contents(LOG_PATH . "request.log", date("Y-m-d H:i:s") . " wait after response\n", FILE_APPEND);
 }
Esempio n. 2
0
 /**
  * render html
  * @param unknown $tpl
  * @param array $data
  * @param string $async
  * @throws Exception
  */
 public static function RenderHtml($tpl, array $data, $async = false)
 {
     self::$heads["Content-Type"] = "text/html";
     if (substr($tpl, -4) != '.php') {
         $tpl .= '.php';
     }
     if (!file_exists($tpl)) {
         throw new Exception("Invalid tpl {$tpl}");
     }
     if (ob_get_length() > 0) {
         ob_end_clean();
     }
     ob_start();
     extract($data);
     include $tpl;
     self::$body = ob_get_clean();
     self::Render($async);
 }
Esempio n. 3
0
<?php

/**
 *       Filename:  index.php
 *    Description:  demo entrypoint
 *         Author:  liuyoubin@ubinliu.com
 *        Created:  2015-11-25 18:26:51
 */
define("ROOT_PATH", dirname(__FILE__));
define("CONTROLLER_PATH", ROOT_PATH . "/controllers/");
define("LIB_PAHT", ROOT_PATH . "/libs/");
define("VIEW_PATH", ROOT_PATH . "/views/");
define("LOG_PATH", ROOT_PATH . "/logs/");
require_once "UbinEngine.php";
UbinEngine::AutoLoad(CONTROLLER_PATH);
UbinEngine::AutoLoad(LIB_PAHT);
UbinEngine::AutoHandleErrors(true);
$routes = array("^\\/home" => array("ControllerDemo", "home"), "^\\/json" => array("ControllerDemo", "json"), "^\\/html" => array("ControllerDemo", "html"), "^\\/ex" => array("ControllerDemo", "exception"), "^\\/async" => array("ControllerDemo", "wait"));
UbinEngine::LoadRoute($routes);
function after()
{
    file_put_contents(LOG_PATH . "request.log", date("Y-m-d H:i:s") . " NOTICE request end\n", FILE_APPEND);
}
function before()
{
    file_put_contents(LOG_PATH . "request.log", date("Y-m-d H:i:s") . " TRACE request start\n", FILE_APPEND);
}
UbinEngine::AfterRequest("after");
UbinEngine::BeforeRequest("before");
UbinEngine::Run();