Exemple #1
0
 /**
  * 主要测试,测试正常情况
  */
 public function testMain()
 {
     ControlResolver::setAppPath(dirname(__FILE__) . '/');
     AppHelper::Instance()->config("CMD_FILTER", '');
     //恢复默认
     $_POST["cmd"] = "test.test";
     CommandHandler::run();
     $this->assertEquals("test.test", file_get_contents(dirname(__FILE__) . "/temp/testForCmd.text"));
     $_GET["cmd"] = "";
     CommandHandler::run();
     $this->assertEquals("default.default", file_get_contents(dirname(__FILE__) . "/temp/testForCmd.text"));
     //输出异常
     $_GET["cmd"] = "test.test";
     $_GET["exc"] = "echo_exc";
     CommandHandler::run();
     $this->assertEquals("echo_exc", file_get_contents(dirname(__FILE__) . "/temp/testForCmd.text"));
     //一般异常
     $_GET["cmd"] = "test.test";
     $_GET["exc"] = "exc";
     CommandHandler::run();
     $this->assertEquals("exc", file_get_contents(dirname(__FILE__) . "/temp/testForCmd.text"));
     $_GET["cmd"] = "noHave";
     CommandHandler::run();
     $_GET["cmd"] = "Nocmd";
     CommandHandler::run();
     $_GET["cmd"] = "NoClassExist";
     CommandHandler::run();
     //测试控制过滤
     AppHelper::Instance()->config("CMD_FILTER", '/Controller$/');
     $_GET["cmd"] = "DefaultController";
     CommandHandler::run();
     $this->assertEquals("default.default", file_get_contents(dirname(__FILE__) . "/temp/testForCmd.text"));
 }
Exemple #2
0
 /**
  * 启动
  */
 public static function start()
 {
     /*
      * ------------------------------------------------------
      *  设置时区
      * ------------------------------------------------------
      */
     date_default_timezone_set("Asia/Shanghai");
     /*
      * ------------------------------------------------------
      * 安全程序:关掉魔法引号,过滤全局变量
      * ------------------------------------------------------
      */
     if (!is_php('5.4')) {
         ini_set('magic_quotes_runtime', 0);
         if ((bool) ini_get('register_globals')) {
             $_protected = array('_SERVER', '_GET', '_POST', '_FILES', '_REQUEST', '_SESSION', '_ENV', '_COOKIE', 'GLOBALS', 'HTTP_RAW_POST_DATA', '_protected', '_registered');
             $_registered = ini_get('variables_order');
             foreach (array('E' => '_ENV', 'G' => '_GET', 'P' => '_POST', 'C' => '_COOKIE', 'S' => '_SERVER') as $key => $superglobal) {
                 if (strpos($_registered, $key) === FALSE) {
                     continue;
                 }
                 foreach (array_keys(${$superglobal}) as $var) {
                     if (isset($GLOBALS[$var]) && !in_array($var, $_protected, TRUE)) {
                         $GLOBALS[$var] = NULL;
                     }
                 }
             }
         }
     }
     /*
      * ------------------------------------------------------
      *  异常处理,错误处理等,记录错误日志
      * ------------------------------------------------------
      */
     register_shutdown_function("_finish_handle");
     set_exception_handler("_exception_handle");
     set_error_handler("_error_handle");
     /*
      * ------------------------------------------------------
      *  注册自动加载方法
      * ------------------------------------------------------
      */
     spl_autoload_register("Loader::autoload");
     Loader::setClassDir((array) AppHelper::Instance()->config("APP_AUTOLOAD_PATH"));
     Loader::setSuffix((array) AppHelper::Instance()->config("CLASS_FILE_SUFFIX"));
     /*
      * ------------------------------------------------------
      * ini 设置
      * ------------------------------------------------------
      */
     //默认字符编码为UTF-8
     ini_set('default_charset', 'UTF-8');
     //日志初始
     log_message(LOG_INFO, "初始处理完毕", \Utils\UtilFactory::getLogHandle());
     //运行核心程序
     log_message(LOG_INFO, "运行核心程序................");
     CommandHandler::run();
 }