Пример #1
0
 /**
  * 框架启动入口函数
  */
 public static function run()
 {
     self::_loadBaseLib();
     //加载框架核心类
     date_default_timezone_set(TIME_ZONE);
     //设置默认时区
     if (APP_DEBUG) {
         Debug::start();
         error_reporting(E_ALL);
         //设置捕获系统异常
         set_error_handler(array('herosphp\\core\\Debug', 'customError'));
     } else {
         error_reporting(0);
         ini_set("display_errors", "Off");
     }
     $configs = Loader::config('system');
     //加载系统全局配置
     $appConfigs = Loader::config('*', APP_NAME);
     //加载当前应用的配置信息
     //将应用的配置信息覆盖系统的全局配置信息
     $configs = array_merge($configs, $appConfigs);
     $application = WebApplication::getInstance();
     $application->execute($configs);
     //Debug::printMessage();
 }
Пример #2
0
/**
 * 打印函数, 打印变量(数据)
 */
function __print()
{
    $_args = func_get_args();
    //获取函数的参数
    if (count($_args) < 1) {
        \herosphp\core\Debug::appendMessage('必须为myprint()参数');
        trigger_error('必须为myprint()参数');
        return;
    }
    echo '<div style="width:100%;text-align:left"><pre>';
    //循环输出参数
    foreach ($_args as $_a) {
        if (is_array($_a)) {
            print_r($_a);
            echo '<br />';
        } else {
            if (is_string($_a)) {
                echo $_a . '<br />';
            } else {
                var_dump($_a);
                echo '<br />';
            }
        }
    }
    echo '</pre></div>';
}
Пример #3
0
 /**
  * @see        ICache::get()
  */
 public function get($key, $expire = null)
 {
     if ($expire !== null) {
         $this->configs['expire'] = $expire;
     }
     $cacheFile = $this->getCacheFile($key);
     //缓存文件不存在
     if (!file_exists($cacheFile)) {
         if (APP_DEBUG) {
             Debug::appendMessage("缓存文件 {$cacheFile} 不存在.");
         }
         return false;
     }
     //缓存过期, 若$expire = 0 则表示缓存永不过期
     if ($this->configs['expire'] > 0 && time() > filemtime($cacheFile) + $this->configs['expire']) {
         if (APP_DEBUG) {
             Debug::appendMessage("缓存文件 {$cacheFile} 已经过期.");
         }
         return false;
     } else {
         $content = file_get_contents($cacheFile);
         if (ArrayUtils::isSerializedArray($content)) {
             return unserialize($content);
         } else {
             return $content;
         }
     }
 }
Пример #4
0
 /**
  * 执行一条SQL语句,不同类型的SQL语句发送到不同的服务器去执行。
  * 1. 读的SQL语句发送到读服务器
  * 2. 写入SQL语句发送到写服务器
  * 3. 此方法将抛出异常
  * @see \herosphp\db\interfaces\ICusterDB::query()
  * @throws DBException
  */
 public function query($_query)
 {
     if ($this->isReadSQL($_query)) {
         /* 读取数据操作 */
         $_db = $this->selectReadServer();
     } else {
         /* 写入数据操作 */
         $_db = $this->selectWriteServer();
     }
     try {
         $_result = $_db->query($_query);
     } catch (PDOException $e) {
         $_exception = new DBException("SQL错误!" . $e->getMessage());
         $_exception->setCode($e->getCode());
         $_exception->setQuery($_query);
         __print($_exception);
         die;
     }
     if (APP_DEBUG) {
         Debug::appendMessage($_query, 'sql');
         //添加调试信息
     }
     return $_result;
 }
Пример #5
0
 /**
  * @see Idb::excute()
  * @param string $sql
  * @return \PDOStatement
  * @throws DBException
  */
 public function excute($sql)
 {
     if ($this->link == null) {
         $this->connect();
     }
     if (DB_ESCAPE) {
         $sql = addslashes($sql);
     }
     try {
         $result = $this->link->query($sql);
     } catch (PDOException $e) {
         $exception = new DBException("SQL错误:" . $e->getMessage());
         $exception->setCode($e->getCode());
         $exception->setQuery($sql);
         if (APP_DEBUG) {
             __print($sql);
         }
         throw $exception;
     }
     Debug::appendMessage($sql, 'sql');
     //添加调试信息
     return $result;
 }
Пример #6
0
 /**
  * @see \herosphp\db\interfaces\Idb::query()
  * @throws DBException
  */
 public function query($_query)
 {
     if ($this->link == null) {
         $this->connect();
     }
     try {
         $_result = $this->link->query($_query);
     } catch (PDOException $e) {
         $_exception = new DBException("SQL错误:" . $e->getMessage());
         $_exception->setCode($e->getCode());
         $_exception->setQuery($_query);
         if (APP_DEBUG) {
             __print($_exception);
             die;
         }
     }
     if (APP_DEBUG) {
         Debug::appendMessage($_query, 'sql');
         //添加调试信息
     }
     return $_result;
 }