Exemple #1
0
 /**
  * @depends testWrite
  */
 public function testRead()
 {
     $help = AppHelper::Instance();
     $drive = new File_d();
     $key = "testFile";
     $this->assertTrue($drive->enabled(), "is drive ok?(testRead)");
     $this->assertTrue($drive->Info() == $drive->Info(), "is drive ok?(testRead)");
     $this->assertEquals($this->_val, $drive->get($key), "get the cache with the key:" . $key);
     //传入参数
     $options = array("prefix" => "newCache");
     $drive = new File_d($options);
     $this->assertEquals($this->_val . "newCache", $drive->get($key), "get the newCache with the key:" . $key);
     //关闭校验和
     $this->assertEquals($this->_val, $drive->get($key . "noCheck"), "get the newCache with the key: noCheck" . $key);
     //关闭压缩
     $this->assertEquals($this->_val, $drive->get($key . "noCompress"), "get the newCache with the key: noCompress" . $key);
     //都关闭
     $this->assertEquals($this->_val, $drive->get($key . "noAll"), "get the newCache with the key: noAll" . $key);
     //校验出错
     $options = array("temp" => __DIR__ . "/Md5");
     $drive = new File_d($options);
     //传入时间,1秒,保证过期
     $drive->set($key . "expire", $this->_val, 1);
     sleep(2);
     //传入时间,1秒,保证过期
     $this->assertEquals(false, $drive->get($key . "expire"), "the key will be out of time ");
     //校验码出错
     $this->assertEquals(false, $drive->get($key . "testMd5"), "md5 error" . $key);
     //不存在的键
     $this->assertEquals(false, $drive->get($key), "the key not exist:" . $key);
     //TODO:
     \Registers\Driver::getInstance();
 }
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();
 }
Exemple #3
0
 /**
  * 清理测试环境
  */
 public static function tearDownAfterClass()
 {
     parent::tearDownAfterClass();
     AppHelper::Instance()->config("APP_CTRL", 'TestControllers1/');
     $CPath = APPPATH . AppHelper::Instance()->config("APP_CTRL");
     rename($CPath, dirname(__FILE__) . "/TestControllers1/");
     unlink(APPPATH . "/temp/testForCmd.text");
 }
Exemple #4
0
 /**
  * 架构函数
  * @param array $arg_options 缓存参数
  * @access public
  * @throws
  */
 public function __construct($arg_options = array())
 {
     if (!$this->_enabled()) {
         throw new \Exception("no support:" . $this->info());
     }
     $this->_appHelper = \AppHelper::Instance();
     $this->_options = $arg_options;
 }
 public static function getLogHandle()
 {
     $log = Logs::getInstance();
     $logPath = \AppHelper::Instance()->config("LOG_PATH");
     $log->init(BASEPATH . $logPath . "log.log");
     $log->logInfo("返回日志句柄");
     return $log;
 }
Exemple #6
0
 public function testConfig()
 {
     try {
         $ah = AppHelper::Instance();
         $config = (include "App.config.php");
         //读取系统配置
         $this->assertEquals($config["USER_CONFIG_FILE_PATH"], $ah->config("USER_CONFIG_FILE_PATH"), "load system's config fail");
         //读取不存在
         $this->assertTrue(null === $ah->config("NO_EXIST"), "read the attributes which no exist");
         //添加不存在的配置属性
         $ah->config("NO_EXIST", True);
         $this->assertTrue($ah->config("NO_EXIST"), "add the attributes which no exist");
         //更变已存在的值
         $ah->config("NO_EXIST", False);
         $this->assertTrue(!$ah->config("NO_EXIST"), "update the attributes which no exist");
     } catch (\Exception $e) {
         $this->assertTrue(false, "some error  happen when run the test testConfig: " . $e->getMessage());
     }
 }
 /**
  * 解析命令新建对应命令控制器实例
  *
  * @param Context $arg_context 上下文 (请求内容)
  *
  * @return Controller
  * @throws \Exceptions\ResolverException
  */
 function getController(Context $arg_context)
 {
     $cmd = $arg_context->Params("cmd");
     $step = DIRECTORY_SEPARATOR;
     if (!$cmd) {
         $cmd = self::$_default_cmd;
     }
     //校验命令格式 TODO:可以在Params上校验
     $cmd_filter = AppHelper::Instance()->config("CMD_FILTER");
     if ($cmd_filter && preg_match($cmd_filter, $cmd) != 1) {
         throw new \Exceptions\ResolverException("Command cannot pass filter");
     }
     //如果存在‘.’ 则替换成文件分隔符,
     //实现控制器目录下多级组合
     $cmd = trim(str_replace(array("."), $step, $cmd));
     //应用根目录,控制器目录,文件后缀名
     $app_root = rtrim(self::$_AppPath, ' \\/');
     $app_ctrl = self::$_ctrl_namespace;
     $ctrl_suffix = AppHelper::Instance()->config("CTRL_FILE_SUFFIX");
     //构建文件目录和类
     $file_path = $app_root . $step . $app_ctrl . $step . $cmd . $ctrl_suffix;
     $class_name = "\\{$app_ctrl}\\" . (strripos($cmd, $step) ? substr($cmd, strripos($cmd, $step) + 1) : $cmd);
     //     echo "\n", $file_path, "\n", $class_name, "\n";
     if (!file_exists($file_path)) {
         throw new \Exceptions\ResolverException("Command file '{$cmd}' not found");
     }
     @(require_once "{$file_path}");
     if (!class_exists("{$class_name}")) {
         throw new \Exceptions\ResolverException("Command '{$cmd}' not found");
     }
     $cmd_class = new ReflectionClass("{$class_name}");
     if (!$cmd_class->isSubclassOf(self::$_base_cmd)) {
         throw new \Exceptions\ResolverException("Command '{$cmd}' is not a command");
     }
     return $cmd_class->newInstance();
 }
Exemple #8
0
 /**
  * 控制器无法通过过滤器异常
  *
  * @expectedException        Exceptions\ResolverException
  * @expectedExceptionMessage Command cannot pass filter
  */
 public function testNoFilter()
 {
     AppHelper::Instance()->config("CMD_FILTER", '/Controller$/');
     $_GET["cmd"] = "NoClassExist";
     $context = new Context();
     $ctrl_r = new ControlResolver();
     $ctrl = $ctrl_r->getController($context);
 }