PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/Kernel/ThinkPHP/Mode/Amf/App.class.php

https://github.com/liujinsong668/epptime
PHP | 177 lines | 90 code | 7 blank | 80 comment | 14 complexity | 9b0b8b0c5822f2a74c34d8eea20540f3 MD5 | raw file
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2009 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: liu21st <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. // $Id$
  12. /**
  13. +------------------------------------------------------------------------------
  14. * ThinkPHP AMF模式应用程序类
  15. +------------------------------------------------------------------------------
  16. */
  17. class App
  18. {//类定义开始
  19. /**
  20. +----------------------------------------------------------
  21. * 应用程序初始化
  22. +----------------------------------------------------------
  23. * @access public
  24. +----------------------------------------------------------
  25. * @return void
  26. +----------------------------------------------------------
  27. */
  28. static public function run()
  29. {
  30. // 设定错误和异常处理
  31. set_error_handler(array('App',"appError"));
  32. set_exception_handler(array('App',"appException"));
  33. //[RUNTIME]
  34. // 检查项目是否编译过
  35. // 在部署模式下会自动在第一次执行的时候编译项目
  36. if(defined('RUNTIME_MODEL')){
  37. // 运行模式无需载入项目编译缓存
  38. }elseif(is_file(RUNTIME_PATH.'~app.php') && (!is_file(CONFIG_PATH.'config.php') || filemtime(RUNTIME_PATH.'~app.php')>filemtime(CONFIG_PATH.'config.php'))) {
  39. // 直接读取编译后的项目文件
  40. C(include RUNTIME_PATH.'~app.php');
  41. }else{
  42. // 预编译项目
  43. App::build();
  44. }
  45. //[/RUNTIME]
  46. //导入类库
  47. Vendor('Zend.Amf.Server');
  48. //实例化AMF
  49. $server = new Zend_Amf_Server();
  50. $actions = explode(',',C('APP_AMF_ACTIONS'));
  51. foreach ($actions as $action)
  52. $server -> setClass($action.'Action');
  53. echo $server -> handle();
  54. // 保存日志记录
  55. if(C('LOG_RECORD')) Log::save();
  56. return ;
  57. }
  58. //[RUNTIME]
  59. /**
  60. +----------------------------------------------------------
  61. * 读取配置信息 编译项目
  62. +----------------------------------------------------------
  63. * @access private
  64. +----------------------------------------------------------
  65. * @return string
  66. +----------------------------------------------------------
  67. */
  68. static private function build()
  69. {
  70. // 加载惯例配置文件
  71. C(include THINK_PATH.'/Common/convention.php');
  72. // 加载项目配置文件
  73. if(is_file(CONFIG_PATH.'config.php')) {
  74. C(include CONFIG_PATH.'config.php');
  75. }
  76. $common = '';
  77. $debug = C('APP_DEBUG'); // 是否调试模式
  78. // 加载项目公共文件
  79. if(is_file(COMMON_PATH.'common.php')) {
  80. include COMMON_PATH.'common.php';
  81. if(!$debug) { // 编译文件
  82. $common .= compile(COMMON_PATH.'common.php');
  83. }
  84. }
  85. // 加载项目编译文件列表
  86. if(is_file(CONFIG_PATH.'app.php')) {
  87. $list = include CONFIG_PATH.'app.php';
  88. foreach ($list as $key=>$file){
  89. // 加载并编译文件
  90. require $file;
  91. if(!$debug) {
  92. $common .= compile($file);
  93. }
  94. }
  95. }
  96. // 如果是调试模式加载调试模式配置文件
  97. if($debug) {
  98. // 加载系统默认的开发模式配置文件
  99. C(include THINK_PATH.'/Common/debug.php');
  100. if(is_file(CONFIG_PATH.'debug.php')) {
  101. // 允许项目增加开发模式配置定义
  102. C(include CONFIG_PATH.'debug.php');
  103. }
  104. }else{
  105. // 部署模式下面生成编译文件
  106. // 下次直接加载项目编译文件
  107. if(defined('RUNTIME_ALLINONE')) {
  108. // 获取用户自定义变量
  109. $defs = get_defined_constants(TRUE);
  110. $content = array_define($defs['user']);
  111. $content .= substr(file_get_contents(RUNTIME_PATH.'~runtime.php'),5);
  112. $content .= $common."\nreturn ".var_export(C(),true).';';
  113. file_put_contents(RUNTIME_PATH.'~allinone.php',strip_whitespace('<?php '.$content));
  114. }else{
  115. $content = "<?php ".$common."\nreturn ".var_export(C(),true).";\n?>";
  116. file_put_contents(RUNTIME_PATH.'~app.php',strip_whitespace($content));
  117. }
  118. }
  119. return ;
  120. }
  121. //[/RUNTIME]
  122. /**
  123. +----------------------------------------------------------
  124. * 自定义异常处理
  125. +----------------------------------------------------------
  126. * @access public
  127. +----------------------------------------------------------
  128. * @param mixed $e 异常对象
  129. +----------------------------------------------------------
  130. */
  131. static public function appException($e)
  132. {
  133. halt($e->__toString());
  134. }
  135. /**
  136. +----------------------------------------------------------
  137. * 自定义错误处理
  138. +----------------------------------------------------------
  139. * @access public
  140. +----------------------------------------------------------
  141. * @param int $errno 错误类型
  142. * @param string $errstr 错误信息
  143. * @param string $errfile 错误文件
  144. * @param int $errline 错误行数
  145. +----------------------------------------------------------
  146. * @return void
  147. +----------------------------------------------------------
  148. */
  149. static public function appError($errno, $errstr, $errfile, $errline)
  150. {
  151. switch ($errno) {
  152. case E_ERROR:
  153. case E_USER_ERROR:
  154. $errorStr = "[$errno] $errstr ".basename($errfile)." 第 $errline 行.";
  155. if(C('LOG_RECORD')){
  156. Log::write($errorStr,Log::ERR);
  157. }
  158. halt($errorStr);
  159. break;
  160. case E_STRICT:
  161. case E_USER_WARNING:
  162. case E_USER_NOTICE:
  163. default:
  164. $errorStr = "[$errno] $errstr ".basename($errfile)." 第 $errline 行.";
  165. Log::record($errorStr,Log::NOTICE);
  166. break;
  167. }
  168. }
  169. };//类定义结束
  170. ?>