示例#1
0
文件: yaml.php 项目: fchaose/qeephp
 /**
  * 载入缓存的 YAML 解析结果,如果缓存失效,则重新解析并生成缓存
  *
  * @param string $filename
  *   要解析的 yaml 文件名
  * @param array $replace
  *   对于 YAML 内容要进行自动替换的字符串对
  * @param string $cache_backend
  *   要使用的缓存后端
  *
  * @return array
  *   解析结果
  */
 static function loadCached($filename, array $replace = null, $cache_backend = null)
 {
     static $cache_obj = null;
     if (!is_file($filename)) {
         throw new QException_FileNotFound($filename);
     }
     $policy = array('lifetime' => 86400, 'serialize' => true);
     $mtime = filemtime($filename);
     $id = 'yaml_cache_' . md5($filename);
     if (is_null($cache_backend)) {
         if (is_null($cache_obj)) {
             $cache_obj = Q::getSingleton(Q::getIni('runtime_cache_backend'));
         }
         $cache = $cache_obj;
     } else {
         $cache = self::getSingleton($cache_backend);
     }
     /* @var $cache QCache_File */
     $data = $cache->get($id, $policy);
     if (!isset($data['yaml']) || empty($data['mtime']) || $data['mtime'] < $mtime) {
         // 缓存失效
         $data = array('mtime' => $mtime, 'yaml' => self::load($filename, $replace));
         $cache->set($id, $data, $policy);
     }
     return $data['yaml'];
 }
示例#2
0
文件: links.php 项目: fchaose/qeephp
 /**
  * 创建书籍记录
  *
  * @param array $authors
  * @param int $nums
  *
  * @return array
  */
 protected function insertBooks(array $authors, $nums = 10)
 {
     $tableBooks = Q::getSingleton('Table_Books');
     /* @var $tableBooks Table_Books */
     $authors = array_values($authors);
     $authors_count = count($authors);
     $books = array();
     for ($i = 0; $i < $nums; $i++) {
         $c = mt_rand(1, $authors_count);
         $rand_authors = array();
         for ($j = 0; $j < $c; $j++) {
             $rand_authors[] = $authors[mt_rand(0, $j * $j) % $authors_count];
         }
         $book = array('title' => 'BOOK ' . mt_rand(), 'intro' => 'INTRO ' . mt_rand(), 'authors' => $rand_authors);
         $books[] = $tableBooks->create($book);
     }
     return $books;
 }
示例#3
0
 /**
  * QeePHP 应用程序 MVC 模式入口
  *
  * @return mixed
  */
 function run()
 {
     // #IFDEF DEBUG
     QLog::log(__METHOD__, QLog::DEBUG);
     // #ENDIF
     // 设置默认的时区
     date_default_timezone_set($this->context->getIni('l10n_default_timezone'));
     // 设置 session 服务
     if ($this->context->getIni('runtime_session_provider')) {
         Q::loadClass($this->context->getIni('runtime_session_provider'));
     }
     // 打开 session
     if ($this->context->getIni('runtime_session_start')) {
         // #IFDEF DEBUG
         QLog::log('session_start()', QLog::DEBUG);
         // #ENDIF
         session_start();
     }
     // 设置验证失败错误处理的回调方法
     $this->context->setIni('dispatcher_on_access_denied', array($this, 'onAccessDenied'));
     // 设置处理动作方法未找到错误的回调方法
     $this->context->setIni('dispatcher_on_action_not_found', array($this, 'onActionNotFound'));
     // 从 session 中提取 flash message
     if (isset($_SESSION)) {
         $key = $this->context->getIni('app_flash_message_key');
         $arr = isset($_SESSION[$key]) ? $_SESSION[$key] : null;
         if (!is_array($arr)) {
             $arr = array(self::FLASH_MSG_INFO, $arr);
         } elseif (!isset($arr[1])) {
             $arr = array(self::FLASH_MSG_INFO, $arr[0]);
         }
         if ($arr[0] != self::FLASH_MSG_ERROR && $arr[0] != self::FLASH_MSG_INFO && $arr[0] != self::FLASH_MSG_WARNING) {
             $arr[0] = self::FLASH_MSG_INFO;
         }
         $this->_flash_message_type = $arr[0];
         $this->_flash_message = $arr[1];
         unset($_SESSION[$key]);
     }
     // 初始化访问控制对象
     $this->acl = Q::getSingleton('QACL');
     // 执行动作
     $context = QContext::instance($this->context->module_name, $this->_appid);
     return $this->_executeAction($context);
 }
示例#4
0
文件: qlog.php 项目: fchaose/qeephp
 /**
  * 追加日志到日志缓存
  *
  * @param string $msg
  * @param int $type
  */
 static function log($msg, $type = self::DEBUG)
 {
     static $instance;
     if (is_null($instance)) {
         $instance = Q::getSingleton('QLog');
     }
     /* @var $instance QLog */
     $instance->append($msg, $type);
 }