Skip to content

Commit

Permalink
Merge pull request #5 from liu21st/master
Browse files Browse the repository at this point in the history
merge
  • Loading branch information
vus520 committed May 20, 2013
2 parents 2e184e0 + 6ca305d commit 31b3606
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 69 deletions.
20 changes: 11 additions & 9 deletions Extend/Driver/Db/DbSqlsrv.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,24 @@ private function getAll() {
* @return array
*/
public function getFields($tableName) {
$result = $this->query("SELECT column_name, data_type, column_default, is_nullable
FROM information_schema.tables AS t
JOIN information_schema.columns AS c
ON t.table_catalog = c.table_catalog
AND t.table_schema = c.table_schema
AND t.table_name = c.table_name
WHERE t.table_name = '$tableName'");
$info = array();
$result = $this->query("
SELECT column_name,data_type,column_default,is_nullable
FROM information_schema.tables AS t
JOIN information_schema.columns AS c
ON t.table_catalog = c.table_catalog
AND t.table_schema = c.table_schema
AND t.table_name = c.table_name
WHERE t.table_name = '{$tableName}'");
$pk = $this->query("SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME='{$tableName}'");
$info = array();
if($result) {
foreach ($result as $key => $val) {
$info[$val['column_name']] = array(
'name' => $val['column_name'],
'type' => $val['data_type'],
'notnull' => (bool) ($val['is_nullable'] === ''), // not null is empty, null is yes
'default' => $val['column_default'],
'primary' => false,
'primary' => $val['column_name'] == $pk[0]['COLUMN_NAME'],
'autoinc' => false,
);
}
Expand Down
29 changes: 14 additions & 15 deletions Extend/Engine/Cluster/Common/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,10 @@ function halt($error) {
$trace = debug_backtrace();
$e['message'] = $error;
$e['file'] = $trace[0]['file'];
$e['class'] = isset($trace[0]['class'])?$trace[0]['class']:'';
$e['function'] = isset($trace[0]['function'])?$trace[0]['function']:'';
$e['line'] = $trace[0]['line'];
$traceInfo = '';
$time = date('y-m-d H:i:m');
foreach ($trace as $t) {
$traceInfo .= '[' . $time . '] ' . $t['file'] . ' (' . $t['line'] . ') ';
$traceInfo .= $t['class'] . $t['type'] . $t['function'] . '(';
$traceInfo .= implode(', ', $t['args']);
$traceInfo .=')<br/>';
}
$e['trace'] = $traceInfo;
ob_start();
debug_print_backtrace();
$e['trace'] = ob_get_clean();
} else {
$e = $error;
}
Expand All @@ -61,6 +53,7 @@ function halt($error) {
exit;
}


/**
* 自定义异常处理
* @param string $msg 异常消息
Expand All @@ -70,7 +63,7 @@ function halt($error) {
*/
function throw_exception($msg, $type='ThinkException', $code=0) {
if (class_exists($type, false))
throw new $type($msg, $code, true);
throw new $type($msg, $code);
else
halt($msg); // 异常类型不存在则输出错误信息字串
}
Expand Down Expand Up @@ -295,11 +288,13 @@ function U($url='',$vars='',$suffix=true,$redirect=false,$domain=false) {
* @param string $name Widget名称
* @param array $data 传人的参数
* @param boolean $return 是否返回内容
* @param string $path Widget所在路径
* @return void
*/
function W($name, $data=array(), $return=false) {
function W($name, $data=array(), $return=false,$path='') {
$class = $name . 'Widget';
require_cache(BASE_LIB_PATH . 'Widget/' . $class . '.class.php');
$path = empty($path) ? BASE_LIB_PATH : $path;
require_cache($path . 'Widget/' . $class . '.class.php');
if (!class_exists($class))
throw_exception(L('_CLASS_NOT_EXIST_') . ':' . $class);
$widget = Think::instance($class);
Expand Down Expand Up @@ -390,7 +385,11 @@ function S($name,$value='',$options=null) {
}elseif(is_null($value)) { // 删除缓存
return $cache->rm($name);
}else { // 缓存数据
$expire = is_numeric($options)?$options:NULL;
if(is_array($options)) {
$expire = isset($options['expire'])?$options['expire']:NULL;
}else{
$expire = is_numeric($options)?$options:NULL;
}
return $cache->set($name, $value, $expire);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Extend/Engine/Cluster/Common/runtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
if(version_compare(PHP_VERSION,'5.2.0','<')) die('require PHP > 5.2.0 !');

// 版本信息
define('THINK_VERSION', '3.1.2');
define('THINK_VERSION', '3.1.3');

// 系统信息
if(version_compare(PHP_VERSION,'5.4.0','<')) {
Expand Down
2 changes: 1 addition & 1 deletion Extend/Engine/Cluster/DefaultApp/IO/bae.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//编译缓存文件创建方法
function runtime_set($filename,$content){
global $global_mc;
$ret=$global_mc->set($filename,$content,MEMCACHE_COMPRESSED,0);
$ret=$global_mc->set($filename,$content,0,0);
if(2==$global_mc->errno()){
header('Content-Type:text/html;charset=utf-8');
exit('您没有初始化Cache服务,请在BAE的管理平台初始化Cache服务');
Expand Down
50 changes: 11 additions & 39 deletions Extend/Engine/Cluster/Lib/Core/Action.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ abstract class Action {
*/
private $name = '';

/**
* 模板变量
* @var tVar
* @access protected
*/
protected $tVar = array();

/**
* 控制器参数
* @var config
Expand All @@ -52,6 +45,8 @@ abstract class Action {
*/
public function __construct() {
tag('action_begin',$this->config);
//实例化视图类
$this->view = Think::instance('View');
//控制器初始化
if(method_exists($this,'_initialize'))
$this->_initialize();
Expand Down Expand Up @@ -97,7 +92,6 @@ protected function isAjax() {
* @return void
*/
protected function display($templateFile='',$charset='',$contentType='',$content='',$prefix='') {
$this->initView();
$this->view->display($templateFile,$charset,$contentType,$content,$prefix);
}

Expand All @@ -111,7 +105,6 @@ protected function display($templateFile='',$charset='',$contentType='',$content
* @return mixed
*/
protected function show($content,$charset='',$contentType='',$prefix='') {
$this->initView();
$this->view->display('',$charset,$contentType,$content,$prefix);
}

Expand All @@ -126,22 +119,9 @@ protected function show($content,$charset='',$contentType='',$prefix='') {
* @return string
*/
protected function fetch($templateFile='',$content='',$prefix='') {
$this->initView();
return $this->view->fetch($templateFile,$content,$prefix);
}

/**
* 初始化视图
* @access private
* @return void
*/
private function initView(){
//实例化视图类
if(!$this->view) $this->view = Think::instance('View');
// 模板变量传值
if($this->tVar) $this->view->assign($this->tVar);
}

/**
* 创建静态页面
* @access protected
Expand Down Expand Up @@ -171,11 +151,8 @@ protected function buildHtml($htmlfile='',$htmlpath='',$templateFile='') {
* @return void
*/
protected function assign($name,$value='') {
if(is_array($name)) {
$this->tVar = array_merge($this->tVar,$name);
}else {
$this->tVar[$name] = $value;
}
$this->view->assign($name,$value);
return $this;
}

public function __set($name,$value) {
Expand All @@ -189,10 +166,7 @@ public function __set($name,$value) {
* @return mixed
*/
public function get($name='') {
if('' === $name) {
return $this->tVar;
}
return isset($this->tVar[$name])?$this->tVar[$name]:false;
return $this->view->get($name);
}

public function __get($name) {
Expand All @@ -206,7 +180,7 @@ public function __get($name) {
* @return boolean
*/
public function __isset($name) {
return isset($this->tVar[$name]);
return $this->get($name);
}

/**
Expand Down Expand Up @@ -254,9 +228,8 @@ public function __call($method,$args) {
default:
$input = $_GET;
}
if(C('VAR_URL_PARAMS')){
$params = $_GET[C('VAR_URL_PARAMS')];
$input = array_merge($input,$params);
if(C('VAR_URL_PARAMS') && isset($_GET[C('VAR_URL_PARAMS')])){
$input = array_merge($input,$_GET[C('VAR_URL_PARAMS')]);
}
break;
case '_request' : $input =& $_REQUEST; break;
Expand All @@ -283,6 +256,7 @@ public function __call($method,$args) {
}else{ // 变量默认值
$data = isset($args[2])?$args[2]:NULL;
}
Log::record('建议使用I方法替代'.$method,Log::NOTICE);
return $data;
}
}
Expand All @@ -295,7 +269,7 @@ public function __call($method,$args) {
* @param mixed $ajax 是否为Ajax方式 当数字时指定跳转时间
* @return void
*/
protected function error($message,$jumpUrl='',$ajax=false) {
protected function error($message='',$jumpUrl='',$ajax=false) {
$this->dispatchJump($message,0,$jumpUrl,$ajax);
}

Expand All @@ -307,7 +281,7 @@ protected function error($message,$jumpUrl='',$ajax=false) {
* @param mixed $ajax 是否为Ajax方式 当数字时指定跳转时间
* @return void
*/
protected function success($message,$jumpUrl='',$ajax=false) {
protected function success($message='',$jumpUrl='',$ajax=false) {
$this->dispatchJump($message,1,$jumpUrl,$ajax);
}

Expand Down Expand Up @@ -420,8 +394,6 @@ private function dispatchJump($message,$status=1,$jumpUrl='',$ajax=false) {
* @access public
*/
public function __destruct() {
// 保存日志
if(C('LOG_RECORD')) Log::save();
// 执行后续操作
tag('action_end');
}
Expand Down
26 changes: 24 additions & 2 deletions Extend/Engine/Cluster/Lib/Core/Think.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,18 @@ static public function instance($class,$method='') {
* @param mixed $e 异常对象
*/
static public function appException($e) {
halt($e->__toString());
$error = array();
$error['message'] = $e->getMessage();
$trace = $e->getTrace();
if('throw_exception'==$trace[0]['function']) {
$error['file'] = $trace[0]['file'];
$error['line'] = $trace[0]['line'];
}else{
$error['file'] = $e->getFile();
$error['line'] = $e->getLine();
}
Log::record($error['message'],Log::ERR);
halt($error);
}

/**
Expand Down Expand Up @@ -295,8 +306,19 @@ function_exists('halt')?halt($errorStr):exit('ERROR:'.$errorStr);

// 致命错误捕获
static public function fatalError() {
// 保存日志记录
if(C('LOG_RECORD')) Log::save();
if ($e = error_get_last()) {
Think::appError($e['type'],$e['message'],$e['file'],$e['line']);
switch($e['type']){
case E_ERROR:
case E_PARSE:
case E_CORE_ERROR:
case E_COMPILE_ERROR:
case E_USER_ERROR:
ob_end_clean();
function_exists('halt')?halt($e):exit('ERROR:'.$e['message']);
break;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Extend/Engine/Cluster/Lib/Template/ThinkTemplate.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public function parseVar($varStr){
$name = "$".$var;
preg_match('/(.+?)\[(.+?)\]/is',$var,$match);
$var = $match[1];
}elseif(false !==strpos($var,':') && false ===strpos($var,'::') && false ===strpos($var,'?')){
}elseif(false !==strpos($var,':') && false ===strpos($var,'(') && false ===strpos($var,'::') && false ===strpos($var,'?')){
//支持 {$var:property} 方式输出对象的属性
$vars = explode(':',$var);
$var = str_replace(':','->',$var);
Expand Down
2 changes: 1 addition & 1 deletion Extend/Engine/cluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// ThinkPHP 入口文件

//[cluster] 定义路径常量
defined('RUNTIME_PATH') or define('RUNTIME_PATH',APP_PATH.'Runtime/');
defined('CLUSTER_PATH') or define('CLUSTER_PATH',ENGINE_PATH.'Cluster/');
//[cluster] 提前系统目录定义
defined('IO_NAME') or define('IO_NAME','auto');
Expand All @@ -24,7 +25,6 @@
//[cluster] 定义加载IO配置
defined('IO_TRUE_NAME') or define('IO_TRUE_NAME',IO_NAME);
require CLUSTER_PATH.'Lib/Core/ThinkFS.class.php';
defined('RUNTIME_PATH') or define('RUNTIME_PATH',APP_PATH.'Runtime/');
defined('APP_DEBUG') or define('APP_DEBUG',false); // 是否调试模式
$runtime = defined('MODE_NAME')?'~'.strtolower(MODE_NAME).'_runtime.php':'~runtime.php';
defined('RUNTIME_FILE') or define('RUNTIME_FILE',RUNTIME_PATH.$runtime);
Expand Down
21 changes: 21 additions & 0 deletions Extend/Model/RelationModel.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ protected function getRelation(&$result,$name='',$return=false) {
$pk = $result[$mappingKey];
$mappingCondition .= " AND {$mappingFk}='{$pk}'";
$relationData = $model->where($mappingCondition)->field($mappingFields)->find();
if (!empty($val['relation_deep'])){
$model->getRelation($relationData,$val['relation_deep']);
}
break;
case BELONGS_TO:
if(strtoupper($mappingClass)==strtoupper($this->name)) {
Expand All @@ -161,6 +164,9 @@ protected function getRelation(&$result,$name='',$return=false) {
$fk = $result[$mappingFk];
$mappingCondition .= " AND {$model->getPk()}='{$fk}'";
$relationData = $model->where($mappingCondition)->field($mappingFields)->find();
if (!empty($val['relation_deep'])){
$model->getRelation($relationData,$val['relation_deep']);
}
break;
case HAS_MANY:
$pk = $result[$mappingKey];
Expand All @@ -169,6 +175,12 @@ protected function getRelation(&$result,$name='',$return=false) {
$mappingLimit = !empty($val['mapping_limit'])?$val['mapping_limit']:'';
// 延时获取关联记录
$relationData = $model->where($mappingCondition)->field($mappingFields)->order($mappingOrder)->limit($mappingLimit)->select();
if (!empty($val['relation_deep'])){
foreach($relationData as $key=>$data){
$model->getRelation($data,$val['relation_deep']);
$relationData[$key] = $data;
}
}
break;
case MANY_TO_MANY:
$pk = $result[$mappingKey];
Expand All @@ -188,6 +200,12 @@ protected function getRelation(&$result,$name='',$return=false) {
$sql .= ' LIMIT '.$mappingLimit;
}
$relationData = $this->query($sql);
if (!empty($val['relation_deep'])){
foreach($relationData as $key=>$data){
$model->getRelation($data,$val['relation_deep']);
$relationData[$key] = $data;
}
}
break;
}
if(!$return){
Expand Down Expand Up @@ -339,6 +357,9 @@ protected function opRelation($opType,$data='',$name='') {
}
break;
}
if (!empty($val['relation_deep'])){
$model->opRelation($opType,$mappingData,$val['relation_deep']);
}
}
}
}
Expand Down

0 comments on commit 31b3606

Please sign in to comment.