/** * 判断是否可以合表 * @param $dao TXDAO * @return bool */ protected function checkConfig($dao) { $tMaster = is_array($this->dbConfig) ? $this->dbConfig[0] : $this->dbConfig; $tSlave = is_array($this->dbConfig) ? $this->dbConfig[1] : $this->dbConfig; $dDbConfig = $dao->getDbConfig(); $dMaster = is_array($dDbConfig) ? $dDbConfig[0] : $dDbConfig; $dSlave = is_array($dDbConfig) ? $dDbConfig[1] : $dDbConfig; if ($tMaster === $dMaster && $tSlave === $dSlave) { return true; } if ($tMaster !== $dMaster) { $tConfig = TXConfig::getAppConfig($tMaster, 'dns'); $dConfig = TXConfig::getAppConfig($dMaster, 'dns'); unset($tConfig['database']); unset($dConfig['database']); if (array_diff($tConfig, $dConfig)) { return false; } } else { if ($tSlave !== $dSlave) { $tConfig = TXConfig::getAppConfig($tSlave, 'dns'); $dConfig = TXConfig::getAppConfig($dSlave, 'dns'); unset($tConfig['database']); unset($dConfig['database']); if (array_diff($tConfig, $dConfig)) { return false; } } } return true; }
/** * @param string $name * @return TXDatabase */ public static function instance($name) { if (!isset(self::$instance[$name])) { $dbconfig = TXConfig::getAppConfig($name, 'dns'); self::$instance[$name] = new self($dbconfig); } return self::$instance[$name]; }
public static function instance() { if (null === self::$instance) { $memcacheCfg = TXConfig::getAppConfig('memcache', 'dns'); self::$instance = new self($memcacheCfg); } return self::$instance; }
public static function instance() { if (null === self::$instance) { $SocketConfig = TXConfig::getAppConfig('socket', 'dns'); self::$instance = new self($SocketConfig); } return self::$instance; }
public static function instance() { if (null === self::$_instance) { $config = TXConfig::getAppConfig('redis', 'dns'); self::$_instance = new self($config); } return self::$_instance; }
public function setDbTable($table) { if (null === $this->database) { if (is_string($this->dbConfig) && ($db = TXConfig::getAppConfig($this->dbConfig, 'dns')['database'])) { $this->database = $db; } else { if (is_array($this->dbConfig)) { $master = TXConfig::getAppConfig($this->dbConfig[0], 'dns')['database']; $slave = TXConfig::getAppConfig($this->dbConfig[1], 'dns')['database']; if ($master === $slave) { $this->database = $master; } else { throw new TXException(3008, array($slave, $master)); } } } } $this->dbTable = $this->database . ".`{$table}`"; }
/** * 构造函数 * @param string $code * @param array $params * @param string $html */ public function __construct($code, $params = array(), $html = "500") { $message = $this->fmt_code($code, $params); // \Biny\Logger::error($message, array('file'=>$this->getFile().":".$this->getLine(), 'trace'=>$this->getTraceAsString())); if (class_exists('TXEvent')) { TXEvent::trigger(onException, array($code, array($message, $this->getTraceAsString()))); } if (class_exists('TXDatabase')) { TXDatabase::rollback(); } try { if (RUN_SHELL) { echo "<b>Fatal error</b>: {$message} in <b>{$this->getFile()}</b>:<b>{$this->getLine()}</b>\nStack trace:\n{$this->getTraceAsString()}"; exit; } if ($httpCode = TXConfig::getConfig($html, 'http')) { header($httpCode); } if (SYS_DEBUG) { echo "<pre>"; echo "<b>Fatal error</b>: {$message} in <b>{$this->getFile()}</b>:<b>{$this->getLine()}</b>\nStack trace:\n{$this->getTraceAsString()}"; } else { if (TXApp::$base->request->isShowTpl() || !TXApp::$base->request->isAjax()) { $params = ['CDN_ROOT' => TXConfig::getAppConfig('CDN_ROOT')]; echo new TXResponse("error/exception", array('msg' => $this->messages[$html] ?: "系统数据异常:{$html}"), $params); } else { $data = array("flag" => false, "error" => $this->messages[$html] ?: "系统数据异常:{$html}"); echo new TXJSONResponse($data); } } die; } catch (TXException $ex) { //防止异常的死循环 echo "system Error"; exit; } }
/** * @param $view * @param array $array * @param array $objects 直接使用参数 * @return TXResponse */ public function display($view, $array = array(), $objects = array()) { $objects = array_merge(array('webRoot' => TXConfig::getAppConfig('webRoot'), 'CDN_ROOT' => TXConfig::getAppConfig('CDN_ROOT')), $objects); return parent::display($view, $array, $objects); }