예제 #1
0
 /**
  * call event when you need.
  */
 public static function call()
 {
     if (!SsdPHP::isDebug()) {
         $ISCGI = 0 === strpos(PHP_SAPI, 'cgi') || false !== strpos(PHP_SAPI, 'fcgi') ? true : false;
         /* 冲刷(flush)所有响应的数据给客户端并结束请求。 这使得客户端结束连接后,需要大量时间运行的任务能够继续运行 */
         $ISCGI && fastcgi_finish_request();
     }
     foreach (self::$_events as $event) {
         $callback = array_shift($event);
         call_user_func_array($callback, $event);
     }
 }
예제 #2
0
파일: Language.php 프로젝트: ssdphp/ssdphp
 /**
  * 加载资源包文件
  * @author  xiaohuihui  <*****@*****.**>
  * @param string $srcPath
  * @param string $defaultModel
  * @param string $Lang
  */
 public static function load($srcPath = "", $defaultModel = "", $Lang = "zh")
 {
     if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         $langstr = $_SERVER['HTTP_ACCEPT_LANGUAGE'] . "";
         switch (strtolower($langstr[0] . $langstr[1])) {
             case 'zh':
                 $Lang = 'zh';
                 break;
             case 'en':
                 $Lang = 'en';
                 break;
             default:
                 $Lang = 'zh';
         }
     }
     if ($srcPath == "") {
         $srcPath = SsdPHP::getRootPath() . "resources/lang/" . $Lang . "/";
     }
     $tmpfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5(realpath($srcPath . $defaultModel));
     if (SsdPHP::isDebug() == false) {
         fileatime($srcPath);
         if (is_file($tmpfile) && filemtime($tmpfile) >= filemtime($srcPath)) {
             self::$LanguageAry = (include $tmpfile);
             return;
         }
     }
     $files = Dir::tree($srcPath, "/.php\$/");
     $Language = array();
     if ($defaultModel != "") {
         $langFile = $srcPath . $defaultModel . ".php";
         if (is_file($langFile)) {
             $Language = (include "{$langFile}");
         }
     } elseif (!empty($files)) {
         foreach ($files as $file) {
             $Language += (include "{$file}");
         }
     }
     //end if
     self::$LanguageAry = $Language;
     self::$LanguagePath = $srcPath;
     file_put_contents($tmpfile, "<?php return " . var_export($Language, true) . ";?>", LOCK_EX);
     return;
 }
예제 #3
0
파일: Config.php 프로젝트: ssdphp/ssdphp
 /**
  * 加载配置文件
  * @param $configPath 配置文件放置的目录
  * @return array|mixed
  */
 public static function load($configPath)
 {
     $tmpfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5(realpath($configPath));
     fileatime($configPath);
     if (is_file($tmpfile) && filemtime($tmpfile) >= filemtime($configPath) && !SsdPHP::isDebug()) {
         self::$config = (include $tmpfile);
         return;
     }
     $files = Dir::tree($configPath, "/.php\$/");
     $config = array();
     if (!empty($files)) {
         foreach ($files as $file) {
             $config += (include "{$file}");
         }
     }
     self::$config = $config;
     self::$configPath = $configPath;
     file_put_contents($tmpfile, "<?php return " . var_export($config, true) . ";?>", LOCK_EX);
     return;
 }
예제 #4
0
파일: Error.php 프로젝트: ssdphp/ssdphp
 /**
  * 致命错误捕获
  */
 public static function fatalError()
 {
     if ($e = error_get_last()) {
         switch ($e['type']) {
             case E_ERROR:
             case E_PARSE:
             case E_CORE_ERROR:
             case E_COMPILE_ERROR:
             case E_USER_ERROR:
                 if (PHP_SAPI != 'cli') {
                     ob_end_clean();
                     if (SsdPHP::isDebug()) {
                         echo "\n\t\t\t\t\t\t<table border='1' cellpadding='3' style='font-size: 75%;border: 1px solid #000000;border-collapse: collapse;'><tr bgcolor='red'><td colspan='4' style='color: white'>fatalError!</td></tr><tr style='background-color: #ccccff; font-weight: bold; color: #000000;'> <th >type</th><th >File</th><th >Line</th><th >Message</th></tr><tr style='background-color: #cccccc; color: #000000;'><td>{$e['type']}</td><td>{$e['file']}</td><td>{$e['line']}</td><td>{$e['message']}</td></tr></table><hr style='background-color: #cccccc; border: 0px; height: 1px;' />";
                     }
                 }
                 break;
         }
     }
 }
예제 #5
0
파일: index.php 프로젝트: ssdphp/ssdphp
    $rootpath = __DIR__ . '/../../../../';
    require $rootpath . 'vendor/autoload.php';
} elseif ($autoload = realpath(__DIR__ . "/../vendor/autoload.php")) {
    require $autoload;
}
if (!class_exists('\\SsdPHP\\SsdPHP')) {
    require dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "SsdPHP" . DIRECTORY_SEPARATOR . "SsdPHP.php";
}
use SsdPHP\Core\RegShutdownEvent, SsdPHP\Core\Route, SsdPHP\Core\Error, SsdPHP\Core\Config, SsdPHP\Core\Language, SsdPHP\SsdPHP;
use SsdPHP\Pulgins\Session\Factory as Session;
SsdPHP::setRootPath($rootpath);
if (($r = SsdPHP::Bootstrap(function () {
    date_default_timezone_set('PRC');
    RegShutdownEvent::register();
    SsdPHP::setAppDir("App");
    SsdPHP::setDebug(true);
    Error::$CONSOLE = SsdPHP::isDebug();
    Config::load(SsdPHP::getRootPath() . DIRECTORY_SEPARATOR . 'config');
    Route::set(Config::getField('ROUTE', 'home', array()));
    Language::load();
    Session::Start($config = Config::get('SessionApiUser'));
})->Run()) === false) {
    header('HTTP/1.1 404 Not Found');
    header('Status: 404 Not Found');
    echo "404 error";
} else {
    echo $r;
}
$end = microtime(true);
echo SsdPHP::isDebug() ? "<!--" . "SsdPHP" . "Framwork runtime=" . ($end - $start) . "秒" . "-->" : "";