XmlQueryParser 클래스 참조

query xml을 파싱하여 캐싱을 한 후 결과를 return 더 자세히 ...

XmlQueryParser에 대한 상속 다이어그램 :

Inheritance graph
XmlQueryParser에 대한 협력 다이어그램:

Collaboration graph

모든 멤버 목록

Public 멤버 함수

 parse ($query_id, $xml_file, $cache_file)
 쿼리 파일을 찾아서 파싱하고 캐싱한다
 _setColumn ($columns)
 _setConditions ($conditions)
 _setGroup ($group_list)
 _setNavigation ($xml_obj)
 _getColumn ($columns)
 _getConditions ($conditions)
 getDefault ($name, $value)
 column, condition등의 key에 default 값을 세팅


상세한 설명

query xml을 파싱하여 캐싱을 한 후 결과를 return

작성자:
zero (zero@nzeo.com)
버전:
0.1
할일:
subquery나 union등의 확장 쿼리에 대한 지원이 필요

XmlQueryParser.class.php 파일의 11 번째 라인에서 정의되었습니다.


멤버 함수 문서화

XmlQueryParser::_getColumn ( columns  ) 

XmlQueryParser.class.php 파일의 366 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : parse().

00366                                      {
00367             $buff = '';
00368             foreach($columns as $key => $val) {
00369                 $val['default'] = $this->getDefault($val['name'], $val['default']);
00370                 if($val['var'] && strpos($val['var'],'.')===false) {
00371 
00372                     if($val['default']) $buff .= sprintf('array("name"=>"%s", "alias"=>"%s", "value"=>$args->%s?$args->%s:%s),%s', $val['name'], $val['alias'], $val['var'], $val['var'], $val['default'] ,"\n");
00373                     else $buff .= sprintf('array("name"=>"%s", "alias"=>"%s", "value"=>$args->%s),%s', $val['name'], $val['alias'], $val['var'], "\n");
00374 
00375                     if($val['default']) $default_list[$val['var']] = $val['default'];
00376                     if($val['notnull']) $notnull_list[] = $val['var'];
00377                     if($val['minlength']) $minlength_list[$val['var']] = $val['minlength'];
00378                     if($val['maxlength']) $maxlength_list[$val['var']] = $val['maxlength'];
00379                 } else {
00380                     if($val['default']) $buff .= sprintf('array("name"=>"%s", "alias"=>"%s", "value"=>%s),%s', $val['name'], $val['alias'], $val['default'] ,"\n");
00381                     else $buff .= sprintf('array("name"=>"%s", "alias"=>"%s",),%s', $val['name'], $val['alias'], "\n");
00382                 }
00383             }
00384             return $buff;
00385         }

XmlQueryParser::_getConditions ( conditions  ) 

XmlQueryParser.class.php 파일의 391 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : parse().

00391                                             {
00392             $buff = '';
00393             foreach($conditions as $key => $val) {
00394                 $buff .= sprintf('array("pipe"=>"%s",%s"condition"=>array(', $val->pipe,"\n");
00395                 foreach($val->condition as $k => $v) {
00396                     $v->default = $this->getDefault($v->column, $v->default);
00397                     if($v->var) {
00398                         if(strpos($v->var,".")===false) {
00399                             if($v->default) $default_list[$v->var] = $v->default;
00400                             if($v->filter) $filter_list[] = $v;
00401                             if($v->notnull) $notnull_list[] = $v->var;
00402                             if($v->default) $buff .= sprintf('array("column"=>"%s", "value"=>$args->%s?$args->%s:%s,"pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->var, $v->var, $v->default, $v->pipe, $v->operation, "\n");
00403                             else $buff .= sprintf('array("column"=>"%s", "value"=>$args->%s,"pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->var, $v->pipe, $v->operation, "\n");
00404                         } else {
00405                             $buff .= sprintf('array("column"=>"%s", "value"=>"%s","pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->var, $v->pipe, $v->operation, "\n");
00406                         }
00407                     } else {
00408                         if($v->default) $buff .= sprintf('array("column"=>"%s", "value"=>%s,"pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->default ,$v->pipe, $v->operation,"\n");
00409                         else $buff .= sprintf('array("column"=>"%s", "pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->pipe, $v->operation,"\n");
00410                     }
00411                 }
00412                 $buff .= ')),'."\n";
00413             }
00414             return $buff;
00415         }

XmlQueryParser::_setColumn ( columns  ) 

XmlQueryParser.class.php 파일의 253 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : parse().

00253                                      {
00254 
00255             if(!$columns) {
00256                 $output->column[] = array("*" => "*");
00257             } else {
00258                 if(!is_array($columns)) $columns = array($columns);
00259                 foreach($columns as $key => $val) {
00260                     $name = $val->attrs->name;
00261                     /*
00262                     if(strpos('.',$name)===false && count($output->tables)==1) {
00263                         $tmp = array_values($output->tables);
00264                         $name = sprintf('%s.%s', $tmp[0], $val->attrs->name);
00265                     }
00266                     */
00267 
00268                     $output->columns[] = array(
00269                         "name" => $name,
00270                         "var" => $val->attrs->var,
00271                         "default" => $val->attrs->default,
00272                         "notnull" => $val->attrs->notnull,
00273                         "filter" => $val->attrs->filter,
00274                         "minlength" => $val->attrs->minlength,
00275                         "maxlength" => $val->attrs->maxlength,
00276                         "alias" => $val->attrs->alias,
00277                     );
00278                 }
00279             }
00280             return $output;
00281         }

XmlQueryParser::_setConditions ( conditions  ) 

XmlQueryParser.class.php 파일의 284 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : parse().

00284                                             {
00285             // 조건절 정리
00286 
00287             $condition = $conditions->condition;
00288             if($condition) {
00289                 $obj->condition = $condition;
00290                 unset($condition);
00291                 $condition = array($obj);
00292             }
00293             $condition_group = $conditions->group;
00294             if($condition_group && !is_array($condition_group)) $condition_group = array($condition_group);
00295 
00296             if($condition && $condition_group) $cond = array_merge($condition, $condition_group);
00297             elseif($condition_group) $cond = $condition_group;
00298             else $cond = $condition;
00299 
00300             if($cond) {
00301                 foreach($cond as $key => $val) {
00302                     unset($cond_output);
00303 
00304                     if($val->attrs->pipe) $cond_output->pipe = $val->attrs->pipe;
00305                     else $cond_output->pipe = null;
00306 
00307                     if(!$val->condition) continue;
00308                     if(!is_array($val->condition)) $val->condition = array($val->condition);
00309 
00310                     foreach($val->condition as $k => $v) {
00311                         $obj = $v->attrs;
00312                         if(!$obj->alias) $obj->alias = $obj->column;
00313                         $cond_output->condition[] = $obj;
00314                     }
00315 
00316                     $output->conditions[] = $cond_output;
00317                 }
00318             }
00319             return $output;
00320         }

XmlQueryParser::_setGroup ( group_list  ) 

XmlQueryParser.class.php 파일의 322 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : parse().

00322                                        {
00323             // group 정리
00324 
00325             if($group_list) {
00326                 if(!is_array($group_list)) $group_list = array($group_list);
00327                 for($i=0;$i<count($group_list);$i++) {
00328                     $group = $group_list[$i];
00329                     $column = trim($group->attrs->column);
00330                     if(!$column) continue;
00331                     $group_column_list[] = $column;
00332                 }
00333                 if(count($group_column_list)) $output->groups = $group_column_list;
00334             }
00335             return $output;
00336         }

XmlQueryParser::_setNavigation ( xml_obj  ) 

XmlQueryParser.class.php 파일의 339 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : parse().

00339                                          {
00340             $navigation = $xml_obj->query->navigation;
00341             if($navigation) {
00342                 $order = $navigation->index;
00343                 if($order) {
00344                     if(!is_array($order)) $order = array($order);
00345                     foreach($order as $order_info) {
00346                         $output->order[] = $order_info->attrs;
00347                     }
00348                 }
00349 
00350                 $list_count = $navigation->list_count->attrs;
00351                 $output->list_count = $list_count;
00352 
00353                 $page_count = $navigation->page_count->attrs;
00354                 $output->page_count = $page_count;
00355 
00356                 $page = $navigation->page->attrs;
00357                 $output->page = $page ;
00358             }
00359             return $output;
00360         }

XmlQueryParser::getDefault ( name,
value 
)

column, condition등의 key에 default 값을 세팅

XmlQueryParser.class.php 파일의 426 번째 라인에서 정의되었습니다.

00426                                            {
00427             if(!$value) return;
00428             $str_pos = strpos($value, '(');
00429             if($str_pos===false) return '"'.$value.'"';
00430 
00431             $func_name = substr($value, 0, $str_pos);
00432             $args = substr($value, $str_pos+1, strlen($value)-1);
00433 
00434             switch($func_name) {
00435                 case 'ipaddress' :
00436                         $val = '$_SERVER[\'REMOTE_ADDR\']';
00437                     break;
00438                 case 'unixtime' :
00439                         $val = 'time()';
00440                     break;
00441                 case 'curdate' :
00442                         $val = 'date("YmdHis")';
00443                     break;
00444                 case 'sequence' :
00445                         $val = '$this->getNextSequence()';
00446                     break;
00447                 case 'plus' :
00448                         $args = abs($args);
00449                         $val = sprintf('"%s+%d"', $name, $args);
00450                     break;
00451                 case 'minus' :
00452                         $args = abs($args);
00453                         $val = sprintf('"%s-%d"', $name, $args);
00454                     break;
00455                 case 'multiply' :
00456                         $args = intval($args);
00457                         $val = sprintf('"%s*%d"', $name, $args);
00458                     break;
00459             }
00460 
00461             return $val;
00462         }

XmlQueryParser::parse ( query_id,
xml_file,
cache_file 
)

쿼리 파일을 찾아서 파싱하고 캐싱한다

XmlQueryParser.class.php 파일의 16 번째 라인에서 정의되었습니다.

다음을 참조함 : XmlParser::$lang, XmlParser::$output, _getColumn(), _getConditions(), _setColumn(), _setConditions(), _setGroup(), _setNavigation(), elseif, FileHandler::readDir(), FileHandler::readFile().

00016                                                           {
00017             // query xml 파일을 찾아서 파싱, 결과가 없으면 return
00018             $buff = FileHandler::readFile($xml_file);
00019             $xml_obj = parent::parse($buff);
00020             if(!$xml_obj) return;
00021             unset($buff);
00022 
00023             $id_args = explode('.', $query_id);
00024             if(count($id_args)==2) {
00025                 $target = 'modules';
00026                 $module = $id_args[0];
00027                 $id = $id_args[1];
00028             } elseif(count($id_args)==3) {
00029                 $target = $id_args[0];
00030                 if(!in_array($target, array('modules','addons','widgets'))) return;
00031                 $module = $id_args[1];
00032                 $id = $id_args[2];
00033             }
00034 
00035             // insert, update, delete, select등의 action
00036             $action = strtolower($xml_obj->query->attrs->action);
00037             if(!$action) return;
00038 
00039             // 테이블 정리 (배열코드로 변환)
00040             $tables = $xml_obj->query->tables->table;
00041             $output->left_tables = array();
00042 
00043             $left_conditions = array();
00044 
00045             if(!$tables) return;
00046             if(!is_array($tables)) $tables = array($tables);
00047             foreach($tables as $key => $val) {
00048 
00049                 // 테이블과 alias의 이름을 구함
00050                 $table_name = $val->attrs->name;
00051                 $alias = $val->attrs->alias;
00052                 if(!$alias) $alias = $table_name;
00053 
00054                 $output->tables[$alias] = $table_name;
00055 
00056                 if(in_array($val->attrs->type,array('left join','left outer join','right join','right outer join')) && count($val->conditions)){
00057                     $output->left_tables[$alias] =  $val->attrs->type;
00058                     $left_conditions[$alias] = $val->conditions;
00059                 }
00060 
00061                 // 테이블을 찾아서 컬럼의 속성을 구함
00062                 $table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $module, $table_name);
00063                 if(!file_exists($table_file)) {
00064                     $searched_list = FileHandler::readDir(_XE_PATH_.'modules');
00065                     $searched_count = count($searched_list);
00066                     for($i=0;$i<$searched_count;$i++) {
00067                         $table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $searched_list[$i], $table_name);
00068                         if(file_exists($table_file)) break;
00069                     }
00070                 }
00071 
00072                 if(file_exists($table_file)) {
00073                     $table_xml = FileHandler::readFile($table_file);
00074                     $table_obj = parent::parse($table_xml);
00075                     if($table_obj->table) {
00076                         if(isset($table_obj->table->column) && !is_array($table_obj->table->column))
00077                         {
00078                             $table_obj->table->column = array($table_obj->table->column);
00079                         }
00080 
00081                         foreach($table_obj->table->column as $k => $v) {
00082                             $buff .= sprintf('$output->column_type["%s"] = "%s";%s', $v->attrs->name, $v->attrs->type, "\n");
00083                         }
00084                     }
00085                 }
00086             }
00087 
00088 
00089             // 컬럼 정리
00090             $columns = $xml_obj->query->columns->column;
00091             $out = $this->_setColumn($columns);
00092             $output->columns = $out->columns;
00093 
00094             $conditions = $xml_obj->query->conditions;
00095             $out = $this->_setConditions($conditions);
00096             $output->conditions = $out->conditions;
00097 
00098             foreach($output->left_tables as $key => $val){
00099                 if($left_conditions[$key]){
00100                     $out = $this->_setConditions($left_conditions[$key]);
00101                     $output->left_conditions[$key] = $out->conditions;
00102                 }
00103             }
00104 
00105             $group_list = $xml_obj->query->groups->group;
00106             $out = $this->_setGroup($group_list);
00107             $output->groups = $out->groups;
00108 
00109             // 네비게이션 정리
00110             $out = $this->_setNavigation($xml_obj);
00111             $output->order = $out->order;
00112             $output->list_count = $out->list_count;
00113             $output->page_count = $out->page_count;
00114             $output->page = $out->page;
00115 
00116 
00117             $column_count = count($output->columns);
00118             $condition_count = count($output->conditions);
00119 
00120             $buff .= '$output->tables = array( ';
00121             foreach($output->tables as $key => $val) {
00122                 if(!array_key_exists($key,$output->left_tables)){
00123                     $buff .= sprintf('"%s"=>"%s",', $key, $val);
00124                 }
00125             }
00126             $buff .= ' );'."\n";
00127 
00128 
00129             // php script 생성
00130             $buff .= '$output->_tables = array( ';
00131             foreach($output->tables as $key => $val) {
00132                 $buff .= sprintf('"%s"=>"%s",', $key, $val);
00133             }
00134             $buff .= ' );'."\n";
00135 
00136 
00137 
00138             if(count($output->left_tables)){
00139                 $buff .= '$output->left_tables = array( ';
00140                 foreach($output->left_tables as $key => $val) {
00141                     $buff .= sprintf('"%s"=>"%s",', $key, $val);
00142                 }
00143                 $buff .= ' );'."\n";
00144             }
00145 
00146 
00147             // column 정리
00148             if($column_count) {
00149                 $buff .= '$output->columns = array ( ';
00150                 $buff .= $this->_getColumn($output->columns);
00151                 $buff .= ' );'."\n";
00152             }
00153 
00154             // conditions 정리
00155             if($condition_count) {
00156                 $buff .= '$output->conditions = array ( ';
00157                 $buff .= $this->_getConditions($output->conditions);
00158                 $buff .= ' );'."\n";
00159             }
00160 
00161             // conditions 정리
00162             if(count($output->left_conditions)) {
00163                 $buff .= '$output->left_conditions = array ( ';
00164                 foreach($output->left_conditions as $key => $val){
00165                     $buff .= "'{$key}' => array ( ";
00166                     $buff .= $this->_getConditions($val);
00167                     $buff .= "),\n";
00168                 }
00169                 $buff .= ' );'."\n";
00170             }
00171 
00172 
00173 
00174             // order 정리
00175             if($output->order) {
00176                 $buff .= '$output->order = array(';
00177                 foreach($output->order as $key => $val) {
00178                     $buff .= sprintf('array($args->%s?$args->%s:"%s",in_array($args->%s,array("asc","desc"))?$args->%s:("%s"?"%s":"asc")),', $val->var, $val->var, $val->default, $val->order, $val->order, $val->order, $val->order);
00179                 }
00180                 $buff .= ');'."\n";
00181             }
00182 
00183             // list_count 정리
00184             if($output->list_count) {
00185                 $buff .= sprintf('$output->list_count = array("var"=>"%s", "value"=>$args->%s?$args->%s:"%s");%s', $output->list_count->var, $output->list_count->var, $output->list_count->var, $output->list_count->default,"\n");
00186             }
00187 
00188             // page_count 정리
00189             if($output->page_count) {
00190                 $buff .= sprintf('$output->page_count = array("var"=>"%s", "value"=>$args->%s?$args->%s:"%s");%s', $output->page_count->var, $output->page_count->var, $output->page_count->var, $output->list_count->default,"\n");
00191             }
00192 
00193             // page 정리
00194             if($output->page) {
00195                 $buff .= sprintf('$output->page = array("var"=>"%s", "value"=>$args->%s?$args->%s:"%s");%s', $output->page->var, $output->page->var, $output->page->var, $output->list->default,"\n");
00196             }
00197 
00198             // group by 정리
00199             if($output->groups) {
00200                 $buff .= sprintf('$output->groups = array("%s");%s', implode('","',$output->groups),"\n");
00201             }
00202 
00203             // default check
00204             if(count($default_list)) {
00205                 foreach($default_list as $key => $val) {
00206                     $pre_buff .= 'if(!isset($args->'.$key.')) $args->'.$key.' = '.$val.';'."\n";
00207                 }
00208             }
00209 
00210             // not null check
00211             if(count($notnull_list)) {
00212                 foreach($notnull_list as $key => $val) {
00213                     $pre_buff .= 'if(!isset($args->'.$val.')) return new Object(-1, sprintf($lang->filter->isnull, $lang->'.$val.'?$lang->'.$val.':\''.$val.'\'));'."\n";
00214                 }
00215             }
00216 
00217             // minlength check
00218             if(count($minlength_list)) {
00219                 foreach($minlength_list as $key => $val) {
00220                     $pre_buff .= 'if($args->'.$key.'&&strlen($args->'.$key.')<'.$val.') return new Object(-1, sprintf($lang->filter->outofrange, $lang->'.$key.'?$lang->'.$key.':\''.$key.'\'));'."\n";
00221                 }
00222             }
00223 
00224             // maxlength check
00225             if(count($maxlength_list)) {
00226                 foreach($maxlength_list as $key => $val) {
00227                     $pre_buff .= 'if($args->'.$key.'&&strlen($args->'.$key.')>'.$val.') return new Object(-1, sprintf($lang->filter->outofrange, $lang->'.$key.'?$lang->'.$key.':\''.$key.'\'));'."\n";
00228                 }
00229             }
00230 
00231             // filter check
00232             if(count($filter_list)) {
00233                 foreach($filter_list as $key => $val) {
00234                     if(!$notnull_list[$key]) continue;
00235                     $pre_buff .= sprintf('unset($_output); $_output = $this->checkFilter("%s",$args->%s,"%s"); if(!$_output->toBool()) return $_output;%s',$val->var,$val->var,$val->filter,"\n");
00236                 }
00237             }
00238 
00239             $buff = "<?php if(!defined('__ZBXE__')) exit();\n"
00240                   . sprintf('$output->query_id = "%s";%s', $query_id, "\n")
00241                   . sprintf('$output->action = "%s";%s', $action, "\n")
00242                   . $pre_buff
00243                   . $buff
00244                   . 'return $output; ?>';
00245 
00246             // 저장
00247             FileHandler::writeFile($cache_file, $buff);
00248         }

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:


이 클래스에 대한 문서화 페이지는 다음의 파일로부터 생성되었습니다.:

생성시간 : Wed Jun 3 15:17:20 2009, 프로젝트명 : XpressEngine, 생성자 :   doxygen 1.5.8