mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-30 07:42:11 +09:00
Remove legacy DB classes and XML query parser classes
This commit is contained in:
parent
978d3d167a
commit
ad5169bc7a
55 changed files with 7 additions and 8717 deletions
|
|
@ -1,114 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* File containing the XE 1.5 XmlQueryParserClass
|
||||
*/
|
||||
if(!defined('__XE_LOADED_XML_CLASS__'))
|
||||
{
|
||||
define('__XE_LOADED_XML_CLASS__', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* New XmlQueryParser class <br />
|
||||
* Parses XE XML query files
|
||||
*
|
||||
* @author Corina Udrescu (corina.udrescu@arnia.ro)
|
||||
* @package classes\xml
|
||||
* @version 0.1
|
||||
*/
|
||||
class XmlQueryParser extends XmlParser
|
||||
{
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @return void
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create XmlQueryParser instance for Singleton
|
||||
*
|
||||
* @return XmlQueryParser object
|
||||
*/
|
||||
function &getInstance()
|
||||
{
|
||||
static $theInstance = NULL;
|
||||
if(!isset($theInstance))
|
||||
{
|
||||
$theInstance = new XmlQueryParser();
|
||||
}
|
||||
return $theInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an XML query file
|
||||
*
|
||||
* 1. Read xml file<br />
|
||||
* 2. Check the action<br />
|
||||
* 3. Parse and write cache file <br />
|
||||
*
|
||||
* @param $query_id
|
||||
* @param $xml_file
|
||||
* @param $cache_file
|
||||
*
|
||||
* @return QueryParser object
|
||||
*/
|
||||
function &parse_xml_query($query_id, $xml_file, $cache_file)
|
||||
{
|
||||
// Read xml file
|
||||
$xml_obj = $this->getXmlFileContent($xml_file);
|
||||
|
||||
// insert, update, delete, select action
|
||||
$action = strtolower($xml_obj->query->attrs->action);
|
||||
if(!$action)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Write query cache file
|
||||
$parser = new QueryParser($xml_obj->query);
|
||||
FileHandler::writeFile($cache_file, $parser->toString());
|
||||
|
||||
return $parser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override for parent "parse" method
|
||||
*
|
||||
* @param null $query_id
|
||||
* @param null $xml_file
|
||||
* @param null $cache_file
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function parse($query_id = NULL, $xml_file = NULL, $cache_file = NULL)
|
||||
{
|
||||
$this->parse_xml_query($query_id, $xml_file, $cache_file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns XML file contents as an object
|
||||
* or NULL in case of error
|
||||
*
|
||||
* @param $xml_file
|
||||
* @return array|NULL
|
||||
*/
|
||||
function getXmlFileContent($xml_file)
|
||||
{
|
||||
$buff = FileHandler::readFile($xml_file);
|
||||
$xml_obj = parent::parse($buff);
|
||||
if(!$xml_obj)
|
||||
{
|
||||
return;
|
||||
}
|
||||
unset($buff);
|
||||
return $xml_obj;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file XmlQueryParser.class.php */
|
||||
/* Location: ./classes/xml/XmlQueryParser.class.php */
|
||||
|
|
@ -1,333 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* File containing the DBParser class
|
||||
*/
|
||||
|
||||
/**
|
||||
* Escapes query statements: <br />
|
||||
* - column names: member.member_srl => "member"."member_srl" <br />
|
||||
* - expressions: SUM(member.member_srl) => SUM("member"."member_srl") <br />
|
||||
*
|
||||
* @author Corina Udrescu (corina.udrescu@arnia.ro)
|
||||
* @package classes\xml\xmlquery
|
||||
* @version 0.1
|
||||
*/
|
||||
class DBParser
|
||||
{
|
||||
|
||||
/**
|
||||
* Character for escape target value on the left
|
||||
*
|
||||
* For example, in CUBRID left and right escape
|
||||
* chars are the same, the double quote - " <br />
|
||||
* But for SQL Server, the escape is made with
|
||||
* [double brackets], so the left and right char differ
|
||||
*
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $escape_char_left;
|
||||
|
||||
/**
|
||||
* Character for escape target value on the right
|
||||
*
|
||||
* For example, in CUBRID left and right escape
|
||||
* chars are the same, the double quote - " <br />
|
||||
* But for SQL Server, the escape is made with
|
||||
* [double brackets], so the left and right char differ
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $escape_char_right;
|
||||
|
||||
/**
|
||||
* Table prefix string
|
||||
*
|
||||
* Default is "xe_"
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $table_prefix;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $escape_char_left
|
||||
* @param string $escape_char_right
|
||||
* @param string $table_prefix
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function __construct($escape_char_left, $escape_char_right = "", $table_prefix = "xe_")
|
||||
{
|
||||
$this->escape_char_left = $escape_char_left;
|
||||
if($escape_char_right !== "")
|
||||
{
|
||||
$this->escape_char_right = $escape_char_right;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->escape_char_right = $escape_char_left;
|
||||
}
|
||||
$this->table_prefix = $table_prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get escape character
|
||||
*
|
||||
* @param string $leftOrRight left or right
|
||||
* @return string
|
||||
*/
|
||||
function getEscapeChar($leftOrRight)
|
||||
{
|
||||
if($leftOrRight === 'left')
|
||||
{
|
||||
return $this->escape_char_left;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->escape_char_right;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape the value
|
||||
*
|
||||
* @param mixed $name
|
||||
* @return string
|
||||
*/
|
||||
function escape($name)
|
||||
{
|
||||
return $this->escape_char_left . $name . $this->escape_char_right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape the string value
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
function escapeString($name)
|
||||
{
|
||||
return "'" . $this->escapeStringValue($name) . "'";
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape the string value
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
function escapeStringValue($value)
|
||||
{
|
||||
if($value == "*")
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
if(is_string($value))
|
||||
{
|
||||
return $value = str_replace("'", "''", $value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return table full name
|
||||
*
|
||||
* @param string $name table name without table prefix
|
||||
*
|
||||
* @return string table full name with table prefix
|
||||
*/
|
||||
function parseTableName($name)
|
||||
{
|
||||
return $this->table_prefix . $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return column name after escape
|
||||
*
|
||||
* @param string $name column name before escape
|
||||
*
|
||||
* @return string column name after escape
|
||||
*/
|
||||
function parseColumnName($name)
|
||||
{
|
||||
return $this->escapeColumn($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape column name
|
||||
*
|
||||
* @param string $column_name
|
||||
* @return string column name with db name
|
||||
*/
|
||||
function escapeColumn($column_name)
|
||||
{
|
||||
if($this->isUnqualifiedColumnName($column_name))
|
||||
{
|
||||
return $this->escape($column_name);
|
||||
}
|
||||
if($this->isQualifiedColumnName($column_name))
|
||||
{
|
||||
list($table, $column) = explode('.', $column_name);
|
||||
// $table can also be an alias, so the prefix should not be added
|
||||
return $this->escape($table) . '.' . $this->escape($column);
|
||||
//return $this->escape($this->parseTableName($table)).'.'.$this->escape($column);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a given column name is unqualified
|
||||
*
|
||||
* Ex: "member_srl" -> unqualified <br />
|
||||
* "member"."member_srl" -> qualified
|
||||
*
|
||||
* @param string $column_name
|
||||
* @return bool
|
||||
*/
|
||||
function isUnqualifiedColumnName($column_name)
|
||||
{
|
||||
if(strpos($column_name, '.') === FALSE && strpos($column_name, '(') === FALSE)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a given column name is qualified
|
||||
*
|
||||
* Ex: "member_srl" -> unqualified <br />
|
||||
* "member"."member_srl" -> qualified
|
||||
*
|
||||
* @param string $column_name
|
||||
* @return bool
|
||||
*/
|
||||
function isQualifiedColumnName($column_name)
|
||||
{
|
||||
if(strpos($column_name, '.') !== FALSE && strpos($column_name, '(') === FALSE)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes a query expression
|
||||
*
|
||||
* An expression can be: <br />
|
||||
* <ul>
|
||||
* <li> a column name: "member_srl" or "xe_member"."member_srl"
|
||||
* <li> an expression:
|
||||
* <ul>
|
||||
* <li> LEFT(UPPER("content")) <br />
|
||||
* <li> readed_count + voted_count <br />
|
||||
* <li> CAST(regdate as DATE) </li>
|
||||
* </ul>
|
||||
* </li>
|
||||
* </ul>
|
||||
*
|
||||
* @param $column_name
|
||||
* @return string
|
||||
*/
|
||||
function parseExpression($column_name)
|
||||
{
|
||||
$functions = preg_split('/([\+\-\*\/\ ])/', $column_name, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||
foreach($functions as $k => $v)
|
||||
{
|
||||
$function = &$functions[$k];
|
||||
if(strlen($function) == 1)
|
||||
{
|
||||
continue; // skip delimiters
|
||||
}
|
||||
$pos = strrpos("(", $function);
|
||||
$matches = preg_split('/([a-zA-Z0-9_*]+)/', $function, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||
$total_brackets = substr_count($function, "(");
|
||||
$brackets = 0;
|
||||
foreach($matches as $i => $j)
|
||||
{
|
||||
$match = &$matches[$i];
|
||||
if($match == '(')
|
||||
{
|
||||
$brackets++;
|
||||
continue;
|
||||
}
|
||||
if(strpos($match, ')') !== FALSE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(in_array($match, array(',', '.')))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if($brackets == $total_brackets)
|
||||
{
|
||||
if(!is_numeric($match) && !in_array(strtoupper($match), array('UNSIGNED', 'INTEGER', 'AS')) && !preg_match('/^[A-Z]+$/', $match))
|
||||
{
|
||||
$match = $this->escapeColumnExpression($match);
|
||||
}
|
||||
}
|
||||
}
|
||||
$function = implode('', $matches);
|
||||
}
|
||||
return implode('', $functions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a given argument is an asterisk
|
||||
*
|
||||
* @param string $column_name
|
||||
* @return bool
|
||||
*/
|
||||
function isStar($column_name)
|
||||
{
|
||||
if(substr($column_name, -1) == '*')
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if expression is an aggregate star function
|
||||
* like count(*)
|
||||
*
|
||||
* @param string $column_name
|
||||
* @return bool
|
||||
*/
|
||||
function isStarFunction($column_name)
|
||||
{
|
||||
if(strpos($column_name, "(*)") !== FALSE)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return column name after escape
|
||||
* @param string $column_name
|
||||
* @return string
|
||||
*/
|
||||
function escapeColumnExpression($column_name)
|
||||
{
|
||||
if($this->isStar($column_name))
|
||||
{
|
||||
return $column_name;
|
||||
}
|
||||
if($this->isStarFunction($column_name))
|
||||
{
|
||||
return $column_name;
|
||||
}
|
||||
if(stripos($column_name, 'distinct') !== FALSE)
|
||||
{
|
||||
return $column_name;
|
||||
}
|
||||
return $this->escapeColumn($column_name);
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file DBParser.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/DBParser.class.php */
|
||||
|
|
@ -1,127 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* File containing the QueryParser class
|
||||
*/
|
||||
|
||||
/**
|
||||
* Parses an XML Object and returns a string used for generating the PHP cache file <br />
|
||||
* The XML Object structure must be the one defined in the XmlParser class
|
||||
*
|
||||
* @author Corina Udrescu (corina.udrescu@arnia.ro)
|
||||
* @package classes\xml\xmlquery
|
||||
* @version 0.1
|
||||
*/
|
||||
class QueryParser
|
||||
{
|
||||
|
||||
/**
|
||||
* Property containing the associated QueryTag object
|
||||
*
|
||||
* @var QueryTag object
|
||||
*/
|
||||
var $queryTag;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param object $query XML object obtained after reading the XML Query file
|
||||
* @param bool $isSubQuery
|
||||
* @return void
|
||||
*/
|
||||
function __construct($query = NULL, $isSubQuery = FALSE)
|
||||
{
|
||||
if($query)
|
||||
{
|
||||
$this->queryTag = new QueryTag($query, $isSubQuery);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns table information
|
||||
*
|
||||
* Used for finding column type info (string/numeric) <br />
|
||||
* Obtains the table info from XE's XML schema files
|
||||
*
|
||||
* @param object $query_id
|
||||
* @param bool $table_name
|
||||
* @return array
|
||||
*/
|
||||
function getTableInfo($query_id, $table_name)
|
||||
{
|
||||
$column_type = array();
|
||||
$module = '';
|
||||
|
||||
$id_args = explode('.', $query_id);
|
||||
if(count($id_args) == 2)
|
||||
{
|
||||
$target = 'modules';
|
||||
$module = $id_args[0];
|
||||
$id = $id_args[1];
|
||||
}
|
||||
else if(count($id_args) == 3)
|
||||
{
|
||||
$target = $id_args[0];
|
||||
$targetList = array('modules' => 1, 'addons' => 1, 'widgets' => 1);
|
||||
if(!isset($targetList[$target]))
|
||||
{
|
||||
return;
|
||||
}
|
||||
$module = $id_args[1];
|
||||
$id = $id_args[2];
|
||||
}
|
||||
|
||||
// get column properties from the table
|
||||
$table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $module, $table_name);
|
||||
if(!file_exists($table_file))
|
||||
{
|
||||
$searched_list = FileHandler::readDir(_XE_PATH_ . 'modules');
|
||||
$searched_count = count($searched_list);
|
||||
for($i = 0; $i < $searched_count; $i++)
|
||||
{
|
||||
$table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $searched_list[$i], $table_name);
|
||||
if(file_exists($table_file))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(file_exists($table_file))
|
||||
{
|
||||
$table_xml = FileHandler::readFile($table_file);
|
||||
$xml_parser = new XmlParser();
|
||||
$table_obj = $xml_parser->parse($table_xml);
|
||||
if($table_obj->table)
|
||||
{
|
||||
if(isset($table_obj->table->column) && !is_array($table_obj->table->column))
|
||||
{
|
||||
$table_obj->table->column = array($table_obj->table->column);
|
||||
}
|
||||
|
||||
foreach($table_obj->table->column as $k => $v)
|
||||
{
|
||||
$column_type[$v->attrs->name] = $v->attrs->type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $column_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contents for the query cache file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function toString()
|
||||
{
|
||||
return "<?php if(!defined('__XE__')) exit();\n"
|
||||
. $this->queryTag->toString()
|
||||
. 'return $query; ?>';
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file QueryParser.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/QueryParser.class.php */
|
||||
|
|
@ -1,396 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* Argument class
|
||||
* @author NAVER (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery/argument
|
||||
* @version 0.1
|
||||
*/
|
||||
class Argument
|
||||
{
|
||||
|
||||
/**
|
||||
* argument value
|
||||
* @var mixed
|
||||
*/
|
||||
var $value;
|
||||
|
||||
/**
|
||||
* argument name
|
||||
* @var string
|
||||
*/
|
||||
var $name;
|
||||
|
||||
/**
|
||||
* argument type
|
||||
* @var string
|
||||
*/
|
||||
var $type;
|
||||
|
||||
/**
|
||||
* result of argument type check
|
||||
* @var bool
|
||||
*/
|
||||
var $isValid;
|
||||
|
||||
/**
|
||||
* error message
|
||||
* @var BaseObject
|
||||
*/
|
||||
var $errorMessage;
|
||||
|
||||
/**
|
||||
* column operation
|
||||
*/
|
||||
var $column_operation;
|
||||
|
||||
/**
|
||||
* Check if arg value is user submnitted or default
|
||||
* @var mixed
|
||||
*/
|
||||
var $uses_default_value;
|
||||
|
||||
/**
|
||||
* Caches escaped and toString value so that the parsing won't happen multiple times
|
||||
* @var mixed
|
||||
*/
|
||||
var $_value; //
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
|
||||
function __construct($name, $value)
|
||||
{
|
||||
$this->value = $value;
|
||||
$this->name = $name;
|
||||
$this->isValid = TRUE;
|
||||
}
|
||||
|
||||
function getType()
|
||||
{
|
||||
if(isset($this->type))
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
if(is_string($this->value))
|
||||
{
|
||||
return 'column_name';
|
||||
}
|
||||
|
||||
return 'number';
|
||||
}
|
||||
|
||||
function setColumnType($value)
|
||||
{
|
||||
$this->type = $value;
|
||||
}
|
||||
|
||||
function setColumnOperation($operation)
|
||||
{
|
||||
$this->column_operation = $operation;
|
||||
}
|
||||
|
||||
function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
function getValue()
|
||||
{
|
||||
if(!isset($this->_value))
|
||||
{
|
||||
$value = $this->getEscapedValue();
|
||||
$this->_value = $this->toString($value);
|
||||
}
|
||||
return $this->_value;
|
||||
}
|
||||
|
||||
function getPureValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
function getColumnOperation()
|
||||
{
|
||||
return $this->column_operation;
|
||||
}
|
||||
|
||||
function getEscapedValue()
|
||||
{
|
||||
return $this->escapeValue($this->value);
|
||||
}
|
||||
|
||||
function getUnescapedValue()
|
||||
{
|
||||
if($this->value === 'null')
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* mixed value to string
|
||||
* @param mixed $value
|
||||
* @return string
|
||||
*/
|
||||
function toString($value)
|
||||
{
|
||||
if(is_array($value))
|
||||
{
|
||||
if(count($value) === 0)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
if(count($value) === 1 && $value[0] === '')
|
||||
{
|
||||
return '';
|
||||
}
|
||||
return '(' . implode(',', $value) . ')';
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* escape value
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
*/
|
||||
function escapeValue($value)
|
||||
{
|
||||
$column_type = $this->getType();
|
||||
if($column_type == 'column_name')
|
||||
{
|
||||
$dbParser = DB::getParser();
|
||||
return $dbParser->parseExpression($value);
|
||||
}
|
||||
if(!isset($value))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$columnTypeList = array('date' => 1, 'varchar' => 1, 'char' => 1, 'text' => 1, 'bigtext' => 1);
|
||||
if(isset($columnTypeList[$column_type]))
|
||||
{
|
||||
if(!is_array($value))
|
||||
{
|
||||
$value = $this->_escapeStringValue($value);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach($value as $key=>$val)
|
||||
{
|
||||
$value[$key] = $this->_escapeStringValue($val);
|
||||
}
|
||||
}
|
||||
}
|
||||
if($this->uses_default_value)
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
if($column_type == 'number')
|
||||
{
|
||||
if(is_array($value))
|
||||
{
|
||||
foreach($value AS $key => $val)
|
||||
{
|
||||
if(isset($val) && $val !== '')
|
||||
{
|
||||
$value[$key] = (int) $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$value = (int) $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* escape string value
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
function _escapeStringValue($value)
|
||||
{
|
||||
// Remove non-utf8 chars.
|
||||
$regex = '@((?:[\x00-\x7F]|[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}){1,100})|([\xF0-\xF7][\x80-\xBF]{3})|([\x80-\xBF])|([\xC0-\xFF])@x';
|
||||
|
||||
$value = preg_replace_callback($regex, array($this, 'utf8Replacer'), $value);
|
||||
$db = DB::getInstance();
|
||||
$value = $db->addQuotes($value);
|
||||
return '\'' . $value . '\'';
|
||||
}
|
||||
|
||||
function utf8Replacer($captures)
|
||||
{
|
||||
if(strlen($captures[1]))
|
||||
{
|
||||
// Valid byte sequence. Return unmodified.
|
||||
return $captures[1];
|
||||
}
|
||||
else if(strlen($captures[2]))
|
||||
{
|
||||
// Remove user defined area
|
||||
if("\xF3\xB0\x80\x80" <= $captures[2])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
return $captures[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function isValid()
|
||||
{
|
||||
return $this->isValid;
|
||||
}
|
||||
|
||||
function isColumnName()
|
||||
{
|
||||
$type = $this->getType();
|
||||
$value = $this->getUnescapedValue();
|
||||
if($type == 'column_name')
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
if($type == 'number' && is_null($value))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if($type == 'number' && !is_numeric($value) && $this->uses_default_value)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
function getErrorMessage()
|
||||
{
|
||||
return $this->errorMessage;
|
||||
}
|
||||
|
||||
function ensureDefaultValue($default_value)
|
||||
{
|
||||
if($this->value === NULL || $this->value === '')
|
||||
{
|
||||
$this->value = $default_value;
|
||||
$this->uses_default_value = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* check filter by filter type
|
||||
* @param string $filter_type
|
||||
* @return void
|
||||
*/
|
||||
function checkFilter($filter_type)
|
||||
{
|
||||
if(isset($this->value) && $this->value != '')
|
||||
{
|
||||
global $lang;
|
||||
$val = $this->value;
|
||||
$key = $this->name;
|
||||
switch($filter_type)
|
||||
{
|
||||
case 'email' :
|
||||
case 'email_address' :
|
||||
if(!preg_match('/^[\w-]+((?:\.|\+|\~)[\w-]+)*@[\w-]+(\.[\w-]+)+$/is', $val))
|
||||
{
|
||||
$this->isValid = FALSE;
|
||||
$this->errorMessage = new BaseObject(-1, sprintf($lang->filter->invalid_email, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
case 'homepage' :
|
||||
if(!preg_match('/^(http|https)+(:\/\/)+[0-9a-z_-]+\.[^ ]+$/is', $val))
|
||||
{
|
||||
$this->isValid = FALSE;
|
||||
$this->errorMessage = new BaseObject(-1, sprintf($lang->filter->invalid_homepage, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
case 'userid' :
|
||||
case 'user_id' :
|
||||
if(!preg_match('/^[a-zA-Z]+([_0-9a-zA-Z]+)*$/is', $val))
|
||||
{
|
||||
$this->isValid = FALSE;
|
||||
$this->errorMessage = new BaseObject(-1, sprintf($lang->filter->invalid_userid, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
case 'number' :
|
||||
case 'numbers' :
|
||||
if(is_array($val))
|
||||
{
|
||||
$val = join(',', $val);
|
||||
}
|
||||
if(!preg_match('/^(-?)[0-9]+(,\-?[0-9]+)*$/is', $val))
|
||||
{
|
||||
$this->isValid = FALSE;
|
||||
$this->errorMessage = new BaseObject(-1, sprintf($lang->filter->invalid_number, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
case 'alpha' :
|
||||
if(!preg_match('/^[a-z]+$/is', $val))
|
||||
{
|
||||
$this->isValid = FALSE;
|
||||
$this->errorMessage = new BaseObject(-1, sprintf($lang->filter->invalid_alpha, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
case 'alpha_number' :
|
||||
if(!preg_match('/^[0-9a-z]+$/is', $val))
|
||||
{
|
||||
$this->isValid = FALSE;
|
||||
$this->errorMessage = new BaseObject(-1, sprintf($lang->filter->invalid_alpha_number, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkMaxLength($length)
|
||||
{
|
||||
if($this->value && (strlen($this->value) > $length))
|
||||
{
|
||||
global $lang;
|
||||
$this->isValid = FALSE;
|
||||
$key = $this->name;
|
||||
$this->errorMessage = new BaseObject(-1, sprintf($lang->filter->outofrange, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
}
|
||||
|
||||
function checkMinLength($length)
|
||||
{
|
||||
if($this->value && (strlen($this->value) < $length))
|
||||
{
|
||||
global $lang;
|
||||
$this->isValid = FALSE;
|
||||
$key = $this->name;
|
||||
$this->errorMessage = new BaseObject(-1, sprintf($lang->filter->outofrange, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
}
|
||||
|
||||
function checkNotNull()
|
||||
{
|
||||
if(!isset($this->value))
|
||||
{
|
||||
global $lang;
|
||||
$this->isValid = FALSE;
|
||||
$key = $this->name;
|
||||
$this->errorMessage = new BaseObject(-1, sprintf($lang->filter->isnull, $lang->{$key} ? $lang->{$key} : $key));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file Argument.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/argument/Argument.class.php */
|
||||
|
|
@ -1,153 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* ConditionArgument class
|
||||
* @author NAVER (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery/argument
|
||||
* @version 0.1
|
||||
*/
|
||||
class ConditionArgument extends Argument
|
||||
{
|
||||
|
||||
/**
|
||||
* Operator keyword. for example 'in', 'notint', 'between'
|
||||
* @var string
|
||||
*/
|
||||
var $operation;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @param string $operation
|
||||
* @return void
|
||||
*/
|
||||
function __construct($name, $value, $operation)
|
||||
{
|
||||
$operationList = array('in' => 1, 'notin' => 1, 'not_in' => 1, 'between' => 1);
|
||||
if(isset($value) && isset($operationList[$operation]) && !is_array($value) && $value != '')
|
||||
{
|
||||
$value = str_replace(' ', '', $value);
|
||||
$value = str_replace('\'', '', $value);
|
||||
$value = explode(',', $value);
|
||||
}
|
||||
parent::__construct($name, $value);
|
||||
$this->operation = $operation;
|
||||
}
|
||||
|
||||
/**
|
||||
* create condition value. set $this->value
|
||||
* @return void
|
||||
*/
|
||||
function createConditionValue()
|
||||
{
|
||||
if(!isset($this->value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$operation = $this->operation;
|
||||
$value = $this->value;
|
||||
|
||||
switch($operation)
|
||||
{
|
||||
case 'like_prefix' :
|
||||
if(defined('__CUBRID_VERSION__') && __CUBRID_VERSION__ >= '8.4.1')
|
||||
{
|
||||
$this->value = '^' . str_replace('%', '(.*)', preg_quote($value));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->value = $value . '%';
|
||||
}
|
||||
break;
|
||||
case 'like_tail' :
|
||||
if(defined('__CUBRID_VERSION__') && __CUBRID_VERSION__ >= '8.4.1')
|
||||
{
|
||||
$this->value = str_replace('%', '(.*)', preg_quote($value)) . '$';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->value = '%' . $value;
|
||||
}
|
||||
break;
|
||||
case 'like' :
|
||||
if(defined('__CUBRID_VERSION__') && __CUBRID_VERSION__ >= '8.4.1')
|
||||
{
|
||||
$this->value = str_replace('%', '(.*)', preg_quote($value));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->value = '%' . $value . '%';
|
||||
}
|
||||
break;
|
||||
case 'notlike' :
|
||||
$this->value = '%' . $value . '%';
|
||||
break;
|
||||
case 'notlike_prefix' :
|
||||
$this->value = $value . '%';
|
||||
break;
|
||||
case 'notlike_tail' :
|
||||
$this->value = '%' . $value;
|
||||
break;
|
||||
case 'in':
|
||||
if(!is_array($value))
|
||||
{
|
||||
$this->value = array($value);
|
||||
}
|
||||
break;
|
||||
case 'notin':
|
||||
case 'not_in':
|
||||
if(!is_array($value))
|
||||
{
|
||||
$this->value = array($value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Since ConditionArgument is used in WHERE clause,
|
||||
* where the argument value is compared to a table column,
|
||||
* it is assumed that all arguments have type. There are cases though
|
||||
* where the column does not have any type - if it was removed from
|
||||
* the XML schema for example - see the is_secret column in xe_documents table.
|
||||
* In this case, the column type is retrieved according to argument
|
||||
* value type (using the PHP function is_numeric).
|
||||
*
|
||||
* @return type string
|
||||
*/
|
||||
function getType()
|
||||
{
|
||||
if($this->type)
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
else if(!is_numeric($this->value))
|
||||
{
|
||||
return 'varchar';
|
||||
}
|
||||
else
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function setColumnType($column_type)
|
||||
{
|
||||
if(!isset($this->value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if($column_type === '')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->type = $column_type;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file ConditionArgument.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/argument/ConditionArgument.class.php */
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* SortArgument class
|
||||
* @author NAVER (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery/argument
|
||||
* @version 0.1
|
||||
*/
|
||||
class SortArgument extends Argument
|
||||
{
|
||||
|
||||
function getValue()
|
||||
{
|
||||
return $this->getUnescapedValue();
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file SortArgument.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/argument/SortArgument.class.php */
|
||||
|
|
@ -1,177 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* DefaultValue class
|
||||
* @author NAVER (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery/queryargument
|
||||
* @version 0.1
|
||||
*/
|
||||
class DefaultValue
|
||||
{
|
||||
|
||||
/**
|
||||
* Column name
|
||||
* @var string
|
||||
*/
|
||||
var $column_name;
|
||||
|
||||
/**
|
||||
* Value
|
||||
* @var mixed
|
||||
*/
|
||||
var $value;
|
||||
|
||||
/**
|
||||
* sequnence status
|
||||
* @var bool
|
||||
*/
|
||||
var $is_sequence = FALSE;
|
||||
|
||||
/**
|
||||
* operation status
|
||||
* @var bool
|
||||
*/
|
||||
var $is_operation = FALSE;
|
||||
|
||||
/**
|
||||
* operation
|
||||
* @var string
|
||||
*/
|
||||
var $operation = '';
|
||||
|
||||
/**
|
||||
* Checks if value is plain string or name of XE function (ipaddress, plus, etc).
|
||||
* @var bool
|
||||
*/
|
||||
var $_is_string = FALSE;
|
||||
|
||||
/**
|
||||
* Checks if value is string resulted from evaluating a piece of PHP code (see $_SERVER[REMOTE_ADDR])
|
||||
* @var bool
|
||||
*/
|
||||
var $_is_string_from_function = FALSE;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string $column_name column name
|
||||
* @param mixed $value value
|
||||
* @return void
|
||||
*/
|
||||
function __construct($column_name, $value)
|
||||
{
|
||||
$dbParser = DB::getParser();
|
||||
$this->column_name = $dbParser->parseColumnName($column_name);
|
||||
$this->value = $value;
|
||||
$this->value = $this->_setValue();
|
||||
}
|
||||
|
||||
function isString()
|
||||
{
|
||||
return $this->_is_string;
|
||||
$str_pos = strpos($this->value, '(');
|
||||
if($str_pos === false)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
function isStringFromFunction()
|
||||
{
|
||||
return $this->_is_string_from_function;
|
||||
}
|
||||
|
||||
function isSequence()
|
||||
{
|
||||
return $this->is_sequence;
|
||||
}
|
||||
|
||||
function isOperation()
|
||||
{
|
||||
return $this->is_operation;
|
||||
}
|
||||
|
||||
function getOperation()
|
||||
{
|
||||
return $this->operation;
|
||||
}
|
||||
|
||||
function _setValue()
|
||||
{
|
||||
if(!isset($this->value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// If value contains comma separated values and does not contain paranthesis
|
||||
// -> default value is an array
|
||||
if(strpos($this->value, ',') !== FALSE && strpos($this->value, '(') === FALSE)
|
||||
{
|
||||
return sprintf('array(%s)', $this->value);
|
||||
}
|
||||
|
||||
$str_pos = strpos($this->value, '(');
|
||||
// // TODO Replace this with parseExpression
|
||||
if($str_pos === FALSE)
|
||||
{
|
||||
$this->_is_string = TRUE;
|
||||
return '\'' . $this->value . '\'';
|
||||
}
|
||||
//if($str_pos===false) return $this->value;
|
||||
|
||||
$func_name = substr($this->value, 0, $str_pos);
|
||||
$args = substr($this->value, $str_pos + 1, -1);
|
||||
|
||||
switch($func_name)
|
||||
{
|
||||
case 'ipaddress' :
|
||||
$val = '\\RX_CLIENT_IP';
|
||||
$this->_is_string_from_function = TRUE;
|
||||
break;
|
||||
case 'unixtime' :
|
||||
$val = '\\RX_TIME';
|
||||
$this->_is_string_from_function = TRUE;
|
||||
break;
|
||||
case 'curdate' :
|
||||
$val = 'getInternalDateTime()';
|
||||
$this->_is_string_from_function = TRUE;
|
||||
break;
|
||||
case 'sequence' :
|
||||
$this->is_sequence = TRUE;
|
||||
$val = '$sequence';
|
||||
break;
|
||||
case 'plus' :
|
||||
$args = abs($args);
|
||||
$this->is_operation = TRUE;
|
||||
$this->operation = '+';
|
||||
$val = sprintf('%d', $args);
|
||||
break;
|
||||
case 'minus' :
|
||||
$args = abs($args);
|
||||
$this->is_operation = TRUE;
|
||||
$this->operation = '-';
|
||||
$val = sprintf('%d', $args);
|
||||
break;
|
||||
case 'multiply' :
|
||||
$args = intval($args);
|
||||
$this->is_operation = TRUE;
|
||||
$this->operation = '*';
|
||||
$val = sprintf('%d', $args);
|
||||
break;
|
||||
default :
|
||||
$val = '\'' . $this->value . '\'';
|
||||
//$val = $this->value;
|
||||
}
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
function toString()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file DefaultValue.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/queryargument/DefaultValue.class.php */
|
||||
|
|
@ -1,191 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* QueryArgument class
|
||||
* @author NAVER (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery/queryargument
|
||||
* @version 0.1
|
||||
*/
|
||||
class QueryArgument
|
||||
{
|
||||
|
||||
/**
|
||||
* Argument name
|
||||
* @var string
|
||||
*/
|
||||
var $argument_name;
|
||||
|
||||
/**
|
||||
* Variable name
|
||||
* @var string
|
||||
*/
|
||||
var $variable_name;
|
||||
|
||||
/**
|
||||
* Argument validator
|
||||
* @var QueryArgumentValidator
|
||||
*/
|
||||
var $argument_validator;
|
||||
|
||||
/**
|
||||
* Column name
|
||||
* @var string
|
||||
*/
|
||||
var $column_name;
|
||||
|
||||
/**
|
||||
* Table name
|
||||
* @var string
|
||||
*/
|
||||
var $table_name;
|
||||
|
||||
/**
|
||||
* Operation
|
||||
* @var string
|
||||
*/
|
||||
var $operation;
|
||||
|
||||
/**
|
||||
* Ignore value
|
||||
* @var bool
|
||||
*/
|
||||
var $ignore_value;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param object $tag tag object
|
||||
* @param bool $ignore_value
|
||||
* @return void
|
||||
*/
|
||||
function __construct($tag, $ignore_value = FALSE)
|
||||
{
|
||||
static $number_of_arguments = 0;
|
||||
|
||||
$this->argument_name = $tag->attrs->var;
|
||||
if(!$this->argument_name)
|
||||
{
|
||||
$this->argument_name = str_replace('.', '_', $tag->attrs->name);
|
||||
}
|
||||
if(!$this->argument_name)
|
||||
{
|
||||
$this->argument_name = str_replace('.', '_', $tag->attrs->column);
|
||||
}
|
||||
|
||||
$this->variable_name = $this->argument_name;
|
||||
|
||||
$number_of_arguments++;
|
||||
$this->argument_name .= $number_of_arguments;
|
||||
|
||||
$name = $tag->attrs->name;
|
||||
if(!$name)
|
||||
{
|
||||
$name = $tag->attrs->column;
|
||||
}
|
||||
if(strpos($name, '.') === FALSE)
|
||||
{
|
||||
$this->column_name = $name;
|
||||
}
|
||||
else
|
||||
{
|
||||
list($prefix, $name) = explode('.', $name);
|
||||
$this->column_name = $name;
|
||||
$this->table_name = $prefix;
|
||||
}
|
||||
|
||||
if($tag->attrs->operation)
|
||||
{
|
||||
$this->operation = $tag->attrs->operation;
|
||||
}
|
||||
|
||||
$this->argument_validator = new QueryArgumentValidator($tag, $this);
|
||||
$this->ignore_value = $ignore_value;
|
||||
}
|
||||
|
||||
function getArgumentName()
|
||||
{
|
||||
return $this->argument_name;
|
||||
}
|
||||
|
||||
function getColumnName()
|
||||
{
|
||||
return $this->column_name;
|
||||
}
|
||||
|
||||
function getTableName()
|
||||
{
|
||||
return $this->table_name;
|
||||
}
|
||||
|
||||
function getValidatorString()
|
||||
{
|
||||
return $this->argument_validator->toString();
|
||||
}
|
||||
|
||||
function isConditionArgument()
|
||||
{
|
||||
if($this->operation)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change QueryArgument object to string
|
||||
* @return string
|
||||
*/
|
||||
function toString()
|
||||
{
|
||||
if($this->isConditionArgument())
|
||||
{
|
||||
// Instantiation
|
||||
$arg = sprintf("\n" . '${\'%s_argument\'} = new ConditionArgument(\'%s\', %s, \'%s\');' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->variable_name
|
||||
, '$args->' . $this->variable_name
|
||||
, $this->operation
|
||||
);
|
||||
// Call methods to validate argument and ensure default value
|
||||
$arg .= $this->argument_validator->toString();
|
||||
|
||||
// Prepare condition string
|
||||
$arg .= sprintf('${\'%s_argument\'}->createConditionValue();' . "\n"
|
||||
, $this->argument_name
|
||||
);
|
||||
|
||||
// Check that argument passed validation, else return
|
||||
$arg .= sprintf('if(!${\'%s_argument\'}->isValid()) return ${\'%s_argument\'}->getErrorMessage();' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->argument_name
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$arg = sprintf("\n" . '${\'%s_argument\'} = new Argument(\'%s\', %s);' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->variable_name
|
||||
, $this->ignore_value ? 'NULL' : '$args->{\'' . $this->variable_name . '\'}');
|
||||
|
||||
$arg .= $this->argument_validator->toString();
|
||||
|
||||
$arg .= sprintf('if(!${\'%s_argument\'}->isValid()) return ${\'%s_argument\'}->getErrorMessage();' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->argument_name
|
||||
);
|
||||
}
|
||||
|
||||
// If the argument is null, skip it
|
||||
if($this->argument_validator->isIgnorable())
|
||||
{
|
||||
$arg = sprintf("if(isset(%s)) {", '$args->' . $this->variable_name)
|
||||
. $arg
|
||||
. sprintf("} else\n" . '${\'%s_argument\'} = NULL;', $this->argument_name);
|
||||
}
|
||||
|
||||
return $arg;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file QueryArgument.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/queryargument/QueryArgument.class.php */
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* SortQueryArgument class
|
||||
* @author NAVER (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery/queryargument
|
||||
* @version 0.1
|
||||
*/
|
||||
class SortQueryArgument extends QueryArgument
|
||||
{
|
||||
|
||||
/**
|
||||
* Change SortQueryArgument object to string
|
||||
* @return string
|
||||
*/
|
||||
function toString()
|
||||
{
|
||||
$arg = sprintf("\n" . '${\'%s_argument\'} = new SortArgument(\'%s\', %s);' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->argument_name
|
||||
, '$args->' . $this->variable_name);
|
||||
$arg .= $this->argument_validator->toString();
|
||||
|
||||
$arg .= sprintf('if(!${\'%s_argument\'}->isValid()) return ${\'%s_argument\'}->getErrorMessage();' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->argument_name
|
||||
);
|
||||
return $arg;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file DefaultValue.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/queryargument/DefaultValue.class.php */
|
||||
|
|
@ -1,135 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* QueryArgumentValidator class
|
||||
* @author NAVER (developers@xpressengine.com)
|
||||
* @package /classes/xml/xmlquery/queryargument/validator
|
||||
* @version 0.1
|
||||
*/
|
||||
class QueryArgumentValidator
|
||||
{
|
||||
|
||||
/**
|
||||
* Argument name
|
||||
* @var string
|
||||
*/
|
||||
var $argument_name;
|
||||
|
||||
/**
|
||||
* Default value
|
||||
* @var string
|
||||
*/
|
||||
var $default_value;
|
||||
|
||||
/**
|
||||
* Notnull status setting, if value should be not null, this value is 'notnull'
|
||||
* @var string
|
||||
*/
|
||||
var $notnull;
|
||||
|
||||
/**
|
||||
* Filter for value type, for example number
|
||||
* @var string
|
||||
*/
|
||||
var $filter;
|
||||
|
||||
/**
|
||||
* Minimum length for value
|
||||
* @var int
|
||||
*/
|
||||
var $min_length;
|
||||
|
||||
/**
|
||||
* Maximum length for value
|
||||
* @var int
|
||||
*/
|
||||
var $max_length;
|
||||
var $validator_string;
|
||||
|
||||
/**
|
||||
* Query argument for validate
|
||||
* @var QueryArgument object
|
||||
*/
|
||||
var $argument;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param Xml_Node_ $tag tag object by Query xml file parse
|
||||
* @param QueryArgument $argument
|
||||
* @return void
|
||||
*/
|
||||
function __construct($tag, $argument)
|
||||
{
|
||||
$this->argument = $argument;
|
||||
$this->argument_name = $this->argument->getArgumentName();
|
||||
|
||||
$this->default_value = $tag->attrs->default;
|
||||
$this->notnull = $tag->attrs->notnull;
|
||||
$this->filter = $tag->attrs->filter;
|
||||
$this->min_length = $tag->attrs->min_length;
|
||||
$this->max_length = $tag->attrs->max_length;
|
||||
}
|
||||
|
||||
function isIgnorable()
|
||||
{
|
||||
if(isset($this->default_value) || isset($this->notnull))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
function toString()
|
||||
{
|
||||
$validator = '';
|
||||
if($this->filter)
|
||||
{
|
||||
$validator .= sprintf('${\'%s_argument\'}->checkFilter(\'%s\');' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->filter
|
||||
);
|
||||
}
|
||||
if($this->min_length)
|
||||
{
|
||||
$validator .= sprintf('${\'%s_argument\'}->checkMinLength(%s);' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->min_length
|
||||
);
|
||||
}
|
||||
if($this->max_length)
|
||||
{
|
||||
$validator .= sprintf('${\'%s_argument\'}->checkMaxLength(%s);' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->max_length
|
||||
);
|
||||
}
|
||||
if(isset($this->default_value))
|
||||
{
|
||||
$this->default_value = new DefaultValue($this->argument_name, $this->default_value);
|
||||
if($this->default_value->isSequence())
|
||||
$validator .= '$db = DB::getInstance(); $sequence = $db->getNextSequence(); ';
|
||||
if($this->default_value->isOperation())
|
||||
{
|
||||
$validator .= sprintf('${\'%s_argument\'}->setColumnOperation(\'%s\');' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->default_value->getOperation()
|
||||
);
|
||||
}
|
||||
$validator .= sprintf('${\'%s_argument\'}->ensureDefaultValue(%s);' . "\n"
|
||||
, $this->argument_name
|
||||
, $this->default_value->toString()
|
||||
);
|
||||
}
|
||||
if($this->notnull)
|
||||
{
|
||||
$validator .= sprintf('${\'%s_argument\'}->checkNotNull();' . "\n"
|
||||
, $this->argument_name
|
||||
);
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file QueryArgumentValidator.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/queryargument/validator/QueryArgumentValidator.class.php */
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* Models the <column> tag inside an XML Query file <br />
|
||||
* Since the <column> tag supports different attributes depending on
|
||||
* the type of query (select, update, insert, delete) this is only
|
||||
* the base class for the classes that will model each type <column> tag.
|
||||
*
|
||||
* @author Corina Udrescu (corina.udrescu@arnia.ro)
|
||||
* @package classes\xml\xmlquery\tags\column
|
||||
* @version 0.1
|
||||
*/
|
||||
class ColumnTag
|
||||
{
|
||||
|
||||
/**
|
||||
* Column name
|
||||
* @var string
|
||||
*/
|
||||
var $name;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file ColumnTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/column/ColumnTag.class.php */
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* Models the <column> tag inside an XML Query file whose action is 'insert'
|
||||
*
|
||||
* @author Corina Udrescu (corina.udrescu@arnia.ro)
|
||||
* @package classes\xml\xmlquery\tags\column
|
||||
* @version 0.1
|
||||
*/
|
||||
class InsertColumnTag extends ColumnTag
|
||||
{
|
||||
|
||||
/**
|
||||
* Argument
|
||||
*
|
||||
* @var QueryArgument object
|
||||
*/
|
||||
var $argument;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param object $column
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function __construct($column)
|
||||
{
|
||||
parent::__construct($column->attrs->name);
|
||||
$dbParser = DB::getParser();
|
||||
$this->name = $dbParser->parseColumnName($this->name);
|
||||
$this->argument = new QueryArgument($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string to be output in the cache file
|
||||
* used for instantiating an InsertExpression when a
|
||||
* query is executed
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getExpressionString()
|
||||
{
|
||||
return sprintf('new InsertExpression(\'%s\', ${\'%s_argument\'})'
|
||||
, $this->name
|
||||
, $this->argument->argument_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the QueryArgument object associated with this INSERT statement
|
||||
*
|
||||
* @return QueryArgument
|
||||
*/
|
||||
function getArgument()
|
||||
{
|
||||
return $this->argument;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file InsertColumnTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/column/InsertColumnTag.class.php */
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* Models the <column> tag inside an XML Query file whose action is 'insert-select'
|
||||
*
|
||||
* @author Corina Udrescu (corina.udrescu@arnia.ro)
|
||||
* @package classes\xml\xmlquery\tags\column
|
||||
* @version 0.1
|
||||
*/
|
||||
class InsertColumnTagWithoutArgument extends ColumnTag
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param object $column
|
||||
* @return void
|
||||
*/
|
||||
function __construct($column)
|
||||
{
|
||||
parent::__construct($column->attrs->name);
|
||||
$dbParser = DB::getParser();
|
||||
$this->name = $dbParser->parseColumnName($this->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string to be output in the cache file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getExpressionString()
|
||||
{
|
||||
return sprintf('new Expression(\'%s\')', $this->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the QueryArgument object associated with this INSERT statement
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
function getArgument()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file InsertColumnTagWithoutArgument.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/column/InsertColumnTagWithoutArgument.class.php */
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* Models the <columns> tag inside an XML Query file whose action is 'insert'
|
||||
*
|
||||
* @author Corina Udrescu (corina.udrescu@arnia.ro)
|
||||
* @package classes\xml\xmlquery\tags\column
|
||||
* @version 0.1
|
||||
*/
|
||||
class InsertColumnsTag
|
||||
{
|
||||
|
||||
/**
|
||||
* Column list
|
||||
*
|
||||
* @var array value is InsertColumnTag object
|
||||
*/
|
||||
var $columns;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array|string $xml_columns
|
||||
* @return void
|
||||
*/
|
||||
function __construct($xml_columns)
|
||||
{
|
||||
$this->columns = array();
|
||||
|
||||
if(!$xml_columns)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(!is_array($xml_columns))
|
||||
{
|
||||
$xml_columns = array($xml_columns);
|
||||
}
|
||||
|
||||
foreach($xml_columns as $column)
|
||||
{
|
||||
if($column->name === 'query')
|
||||
{
|
||||
$this->columns[] = new QueryTag($column, TRUE);
|
||||
}
|
||||
else if(!isset($column->attrs->var) && !isset($column->attrs->default))
|
||||
{
|
||||
$this->columns[] = new InsertColumnTagWithoutArgument($column);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->columns[] = new InsertColumnTag($column);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* InsertColumnTag object to string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function toString()
|
||||
{
|
||||
$output_columns = 'array(' . PHP_EOL;
|
||||
foreach($this->columns as $column)
|
||||
{
|
||||
$output_columns .= $column->getExpressionString() . PHP_EOL . ',';
|
||||
}
|
||||
$output_columns = substr($output_columns, 0, -1);
|
||||
$output_columns .= ')';
|
||||
return $output_columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return argument list
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getArguments()
|
||||
{
|
||||
$arguments = array();
|
||||
foreach($this->columns as $column)
|
||||
{
|
||||
$arguments[] = $column->getArgument();
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file InsertColumnsTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/column/InsertColumnsTag.class.php */
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* Models the <column> tag inside an XML Query file whose action is 'select'
|
||||
*
|
||||
* @author Corina Udrescu (corina.udrescu@arnia.ro)
|
||||
* @package classes\xml\xmlquery\tags\column
|
||||
* @version 0.1
|
||||
*/
|
||||
class SelectColumnTag extends ColumnTag
|
||||
{
|
||||
|
||||
/**
|
||||
* Column alias
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $alias;
|
||||
|
||||
/**
|
||||
* Click count status
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $click_count;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string|object $column
|
||||
* @return void
|
||||
*/
|
||||
function __construct($column)
|
||||
{
|
||||
if($column == "*" || $column->attrs->name == '*')
|
||||
{
|
||||
parent::__construct(NULL);
|
||||
$this->name = "*";
|
||||
}
|
||||
else
|
||||
{
|
||||
parent::__construct($column->attrs->name);
|
||||
$dbParser = DB::getParser();
|
||||
$this->name = $dbParser->parseExpression($this->name);
|
||||
|
||||
$this->alias = $column->attrs->alias;
|
||||
$this->click_count = $column->attrs->click_count;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string to be output in the cache file
|
||||
*
|
||||
* A select column tag in an XML query can be used for:
|
||||
* <ul>
|
||||
* <li> a star expression: SELECT *
|
||||
* <li> a click count expression: SELECT + UPDATE
|
||||
* <li> any other select expression (column name, function call etc). </li>
|
||||
* </ul>
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getExpressionString()
|
||||
{
|
||||
if($this->name == '*')
|
||||
{
|
||||
return "new StarExpression()";
|
||||
}
|
||||
if($this->click_count)
|
||||
{
|
||||
return sprintf('new ClickCountExpression(\'%s\', %s, $args->%s)', $this->name, $this->alias ? '\'' . $this->alias . '\'' : "''", $this->click_count);
|
||||
}
|
||||
if(strpos($this->name, '$') === 0)
|
||||
{
|
||||
return sprintf('new SelectExpression($args->%s)', substr($this->name, 1));
|
||||
}
|
||||
$dbParser = DB::getParser();
|
||||
return sprintf('new SelectExpression(\'%s\'%s)', $this->name, $this->alias ? ', \'' . $dbParser->escape($this->alias) . '\'' : '');
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file SelectColumnTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/column/SelectColumnTag.class.php */
|
||||
|
|
@ -1,117 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* Models the <columns> tag inside an XML Query file whose action is 'select'
|
||||
*
|
||||
* @author Corina Udrescu (corina.udrescu@arnia.ro)
|
||||
* @package classes\xml\xmlquery\tags\column
|
||||
* @version 0.1
|
||||
*/
|
||||
class SelectColumnsTag
|
||||
{
|
||||
|
||||
/**
|
||||
* Column list
|
||||
*
|
||||
* @var array value is SelectColumnTag object
|
||||
*/
|
||||
var $columns;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param $xml_columns_tag
|
||||
* @internal param \Xml_Node_ $xml_columns
|
||||
* @return void
|
||||
*/
|
||||
function __construct($xml_columns_tag)
|
||||
{
|
||||
if(!$xml_columns_tag)
|
||||
{
|
||||
$xml_columns_tag = new Xml_Node_();
|
||||
}
|
||||
|
||||
$xml_columns = $xml_columns_tag->column;
|
||||
$xml_queries = $xml_columns_tag->query;
|
||||
|
||||
$this->columns = array();
|
||||
|
||||
if(!$xml_columns)
|
||||
{
|
||||
$this->columns[] = new SelectColumnTag("*");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!is_array($xml_columns))
|
||||
{
|
||||
$xml_columns = array($xml_columns);
|
||||
}
|
||||
|
||||
foreach($xml_columns as $column)
|
||||
{
|
||||
$this->columns[] = new SelectColumnTag($column);
|
||||
}
|
||||
|
||||
|
||||
if(!$xml_queries)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(!is_array($xml_queries))
|
||||
{
|
||||
$xml_queries = array($xml_queries);
|
||||
}
|
||||
|
||||
foreach($xml_queries as $column)
|
||||
{
|
||||
$this->columns[] = new QueryTag($column, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string to be output in the cache file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function toString()
|
||||
{
|
||||
$output_columns = 'array(' . PHP_EOL;
|
||||
foreach($this->columns as $column)
|
||||
{
|
||||
if(is_a($column, 'QueryTag'))
|
||||
{
|
||||
$output_columns .= $column->toString() . PHP_EOL . ',';
|
||||
}
|
||||
else
|
||||
{
|
||||
$output_columns .= $column->getExpressionString() . PHP_EOL . ',';
|
||||
}
|
||||
}
|
||||
$output_columns = substr($output_columns, 0, -1);
|
||||
$output_columns .= ')';
|
||||
return $output_columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return argument list
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getArguments()
|
||||
{
|
||||
$arguments = array();
|
||||
foreach($this->columns as $column)
|
||||
{
|
||||
if(is_a($column, 'QueryTag'))
|
||||
{
|
||||
$arguments = array_merge($arguments, $column->getArguments());
|
||||
}
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file SelectColumnsTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/column/SelectColumnsTag.class.php */
|
||||
|
|
@ -1,108 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* Models the <column> tag inside an XML Query file whose action is 'update'
|
||||
*
|
||||
* @author Corina Udrescu (corina.udrescu@arnia.ro)
|
||||
* @package classes\xml\xmlquery\tags\column
|
||||
* @version 0.1
|
||||
*/
|
||||
class UpdateColumnTag extends ColumnTag
|
||||
{
|
||||
|
||||
/**
|
||||
* Argument
|
||||
*
|
||||
* @var QueryArgument object
|
||||
*/
|
||||
var $argument;
|
||||
|
||||
/**
|
||||
* Default value
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $default_value;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param object $column
|
||||
* @return void
|
||||
*/
|
||||
function __construct($column)
|
||||
{
|
||||
parent::__construct($column->attrs->name);
|
||||
|
||||
$dbParser = DB::getParser();
|
||||
$this->name = $dbParser->parseColumnName($this->name);
|
||||
|
||||
if($column->attrs->var)
|
||||
{
|
||||
$this->argument = new QueryArgument($column);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(strpos($column->attrs->default, '.') !== FALSE)
|
||||
{
|
||||
$this->default_value = "'" . $dbParser->parseColumnName($column->attrs->default) . "'";
|
||||
}
|
||||
else
|
||||
{
|
||||
$default_value = new DefaultValue($this->name, $column->attrs->default);
|
||||
if($default_value->isOperation())
|
||||
{
|
||||
$this->argument = new QueryArgument($column, TRUE);
|
||||
}
|
||||
//else $this->default_value = $dbParser->parseColumnName($column->attrs->default);
|
||||
else
|
||||
{
|
||||
$this->default_value = $default_value->toString();
|
||||
if($default_value->isStringFromFunction())
|
||||
{
|
||||
$this->default_value = '"\'".' . $this->default_value . '."\'"';
|
||||
}
|
||||
if($default_value->isString())
|
||||
{
|
||||
$this->default_value = '"' . $this->default_value . '"';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string to be output in the cache file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getExpressionString()
|
||||
{
|
||||
if($this->argument)
|
||||
{
|
||||
return sprintf('new UpdateExpression(\'%s\', ${\'%s_argument\'})'
|
||||
, $this->name
|
||||
, $this->argument->argument_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
return sprintf('new UpdateExpressionWithoutArgument(\'%s\', %s)'
|
||||
, $this->name
|
||||
, $this->default_value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Argument associated with this update statement
|
||||
*
|
||||
* @return QueryArgument
|
||||
*/
|
||||
function getArgument()
|
||||
{
|
||||
return $this->argument;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file UpdateColumnTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/column/UpdateColumnTag.class.php */
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* Models the <columns> tag inside an XML Query file whose action is 'update'
|
||||
*
|
||||
* @author Corina Udrescu (corina.udrescu@arnia.ro)
|
||||
* @package classes\xml\xmlquery\tags\column
|
||||
* @version 0.1
|
||||
*/
|
||||
class UpdateColumnsTag
|
||||
{
|
||||
|
||||
/**
|
||||
* Column list
|
||||
*
|
||||
* @var array value is UpdateColumnTag object
|
||||
*/
|
||||
var $columns;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array|object $xml_columns
|
||||
* @return void
|
||||
*/
|
||||
function __construct($xml_columns)
|
||||
{
|
||||
$this->columns = array();
|
||||
|
||||
if(!is_array($xml_columns))
|
||||
{
|
||||
$xml_columns = array($xml_columns);
|
||||
}
|
||||
|
||||
foreach($xml_columns as $column)
|
||||
{
|
||||
if($column->name === 'query')
|
||||
{
|
||||
$this->columns[] = new QueryTag($column, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->columns[] = new UpdateColumnTag($column);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string to be output in the cache file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function toString()
|
||||
{
|
||||
$output_columns = 'array(' . PHP_EOL;
|
||||
foreach($this->columns as $column)
|
||||
{
|
||||
$output_columns .= $column->getExpressionString() . PHP_EOL . ',';
|
||||
}
|
||||
$output_columns = substr($output_columns, 0, -1);
|
||||
$output_columns .= ')';
|
||||
return $output_columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return argument list
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getArguments()
|
||||
{
|
||||
$arguments = array();
|
||||
foreach($this->columns as $column)
|
||||
{
|
||||
$arguments[] = $column->getArgument();
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file UpdateColumnsTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/column/UpdateColumnsTag.class.php */
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* ConditionGroupTag class
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/condition
|
||||
* @version 0.1
|
||||
*/
|
||||
class ConditionGroupTag
|
||||
{
|
||||
|
||||
/**
|
||||
* condition list
|
||||
* @var string|array value is ConditionTag object
|
||||
*/
|
||||
var $conditions;
|
||||
|
||||
/**
|
||||
* pipe
|
||||
* @var string
|
||||
*/
|
||||
var $pipe;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param string|array $conditions
|
||||
* @param string $pipe
|
||||
* @return void
|
||||
*/
|
||||
function __construct($conditions, $pipe = 'and')
|
||||
{
|
||||
$this->pipe = $pipe;
|
||||
|
||||
if(!is_array($conditions))
|
||||
{
|
||||
$conditions = array($conditions);
|
||||
}
|
||||
|
||||
foreach($conditions as $condition)
|
||||
{
|
||||
if($condition->node_name === 'group')
|
||||
{
|
||||
$subconditions = $condition->condition;
|
||||
$subgroups = $condition->group;
|
||||
$subconditions = $subconditions ? (is_array($subconditions) ? $subconditions : [$subconditions]) : [];
|
||||
$subgroups = $subgroups ? (is_array($subgroups) ? $subgroups : [$subgroups]) : [];
|
||||
$this->conditions[] = new ConditionGroupTag(array_merge($subconditions, $subgroups), $condition->attrs->pipe);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->conditions[] = new ConditionTag($condition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getConditions()
|
||||
{
|
||||
return $this->conditions;
|
||||
}
|
||||
|
||||
/**
|
||||
* ConditionTag object to string
|
||||
* @return string
|
||||
*/
|
||||
function getConditionGroupString()
|
||||
{
|
||||
$conditions_string = 'array(' . PHP_EOL;
|
||||
foreach($this->conditions as $condition)
|
||||
{
|
||||
if($condition instanceof ConditionGroupTag)
|
||||
{
|
||||
$conditions_string .= $condition->getConditionGroupString() . PHP_EOL . ',';
|
||||
}
|
||||
else
|
||||
{
|
||||
$conditions_string .= $condition->getConditionString() . PHP_EOL . ',';
|
||||
}
|
||||
}
|
||||
$conditions_string = substr($conditions_string, 0, -2); //remove ','
|
||||
$conditions_string .= ')';
|
||||
|
||||
return sprintf("new ConditionGroup(%s%s)", $conditions_string, $this->pipe ? ',\'' . $this->pipe . '\'' : '');
|
||||
}
|
||||
|
||||
function getArguments()
|
||||
{
|
||||
$arguments = array();
|
||||
foreach($this->conditions as $condition)
|
||||
{
|
||||
$arguments = array_merge($arguments, $condition->getArguments());
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file ConditionGroupTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php */
|
||||
|
|
@ -1,187 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* ConditionTag
|
||||
* Models the <condition> tag inside an XML Query file. Base class.
|
||||
*
|
||||
* @author Corina
|
||||
* @package /classes/xml/xmlquery/tags/condition
|
||||
* @version 0.1
|
||||
*/
|
||||
class ConditionTag
|
||||
{
|
||||
|
||||
/**
|
||||
* operation for example 'in', 'between', 'not in'...
|
||||
* @var string
|
||||
*/
|
||||
var $operation;
|
||||
|
||||
/**
|
||||
* Column name
|
||||
* @var string
|
||||
*/
|
||||
var $column_name;
|
||||
|
||||
/**
|
||||
* Pipe
|
||||
* @var string
|
||||
*/
|
||||
var $pipe;
|
||||
|
||||
/**
|
||||
* Argument name
|
||||
* @var string
|
||||
*/
|
||||
var $argument_name;
|
||||
|
||||
/**
|
||||
* QueryArgument object
|
||||
* @var QueryArgument
|
||||
*/
|
||||
var $argument;
|
||||
|
||||
/**
|
||||
* Default column
|
||||
* @var string
|
||||
*/
|
||||
var $default_column;
|
||||
|
||||
/**
|
||||
* QueryTag object
|
||||
* @var QueryTag
|
||||
*/
|
||||
var $query;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param object $condition
|
||||
* @return void
|
||||
*/
|
||||
function __construct($condition)
|
||||
{
|
||||
$this->operation = $condition->attrs->operation;
|
||||
$this->pipe = $condition->attrs->pipe ?: 'and';
|
||||
$dbParser = DB::getParser();
|
||||
$this->column_name = $dbParser->parseExpression($condition->attrs->column);
|
||||
|
||||
// If default value is column name, it should be escaped
|
||||
if($isColumnName = (strpos($condition->attrs->default, '.') !== FALSE
|
||||
&& strpos($condition->attrs->default, '.') !== 0
|
||||
&& strpos($condition->attrs->default, '%') === FALSE ))
|
||||
{
|
||||
$condition->attrs->default = $dbParser->parseExpression($condition->attrs->default);
|
||||
}
|
||||
|
||||
if($condition->node_name == 'query')
|
||||
{
|
||||
$this->query = new QueryTag($condition, TRUE);
|
||||
$this->default_column = $this->query->toString();
|
||||
}
|
||||
else if($condition->attrs->var && !strpos($condition->attrs->var, '.'))
|
||||
{
|
||||
$this->argument = new QueryArgument($condition);
|
||||
$this->argument_name = $this->argument->getArgumentName();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(isset($condition->attrs->default))
|
||||
{
|
||||
$operationList = array('in' => 1, 'between' => 1, 'notin' => 1, 'not_in' => 1);
|
||||
if(isset($operationList[$this->operation]))
|
||||
{
|
||||
$default_value = $condition->attrs->default;
|
||||
if(strpos($default_value, "'") !== FALSE)
|
||||
{
|
||||
$default_value = "\"" . $default_value . "\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
$default_value = "'" . $default_value . "'";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$default_value_object = new DefaultValue($this->column_name, $condition->attrs->default);
|
||||
$default_value = $default_value_object->toString();
|
||||
|
||||
if($default_value_object->isStringFromFunction())
|
||||
{
|
||||
$default_value = '"\'".' . $default_value . '."\'"';
|
||||
}
|
||||
|
||||
if($default_value_object->isString() && !$isColumnName && !is_numeric($condition->attrs->default))
|
||||
{
|
||||
if(strpos($default_value, "'") !== FALSE)
|
||||
{
|
||||
$default_value = "\"" . $default_value . "\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
$default_value = "'" . $default_value . "'";
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->default_column = $default_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->default_column = "'" . $dbParser->parseColumnName($condition->attrs->var) . "'";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setPipe($pipe)
|
||||
{
|
||||
$this->pipe = $pipe;
|
||||
}
|
||||
|
||||
function getArguments()
|
||||
{
|
||||
$arguments = array();
|
||||
if($this->query)
|
||||
{
|
||||
$arguments = array_merge($arguments, $this->query->getArguments());
|
||||
}
|
||||
if($this->argument)
|
||||
{
|
||||
$arguments[] = $this->argument;
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
function getConditionString()
|
||||
{
|
||||
if($this->query)
|
||||
{
|
||||
return sprintf("new ConditionSubquery('%s',%s,%s%s)"
|
||||
, $this->column_name
|
||||
, $this->default_column
|
||||
, '"' . $this->operation . '"'
|
||||
, $this->pipe ? ", '" . $this->pipe . "'" : ''
|
||||
);
|
||||
}
|
||||
else if(isset($this->default_column))
|
||||
{
|
||||
return sprintf("new ConditionWithoutArgument('%s',%s,%s%s)"
|
||||
, $this->column_name
|
||||
, $this->default_column
|
||||
, '"' . $this->operation . '"'
|
||||
, $this->pipe ? ", '" . $this->pipe . "'" : ''
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
return sprintf("new ConditionWithArgument('%s',%s,%s%s)"
|
||||
, $this->column_name
|
||||
, '$' . $this->argument_name . '_argument'
|
||||
, '"' . $this->operation . '"'
|
||||
, $this->pipe ? ", '" . $this->pipe . "'" : ''
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file ConditionTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/condition/ConditionTag.class.php */
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* ConditionsTag class
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/condition
|
||||
* @version 0.1
|
||||
*/
|
||||
class ConditionsTag
|
||||
{
|
||||
|
||||
/**
|
||||
* ConditionGroupTag list
|
||||
* @var array value is ConditionGroupTag object
|
||||
*/
|
||||
var $condition_groups;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param object $xml_conditions
|
||||
* @return void
|
||||
*/
|
||||
function __construct($xml_conditions)
|
||||
{
|
||||
$this->condition_groups = array();
|
||||
if(!$xml_conditions)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$xml_condition_list = array();
|
||||
if($xml_conditions->condition)
|
||||
{
|
||||
$xml_condition_list = $xml_conditions->condition;
|
||||
}
|
||||
|
||||
if($xml_conditions->query)
|
||||
{
|
||||
if(!is_array($xml_condition_list))
|
||||
{
|
||||
$xml_condition_list = array($xml_condition_list);
|
||||
}
|
||||
if(!is_array($xml_conditions->query))
|
||||
{
|
||||
$xml_conditions->query = array($xml_conditions->query);
|
||||
}
|
||||
$xml_condition_list = array_merge($xml_condition_list, $xml_conditions->query);
|
||||
}
|
||||
if($xml_condition_list)
|
||||
{
|
||||
$this->condition_groups[] = new ConditionGroupTag($xml_condition_list);
|
||||
}
|
||||
|
||||
$xml_groups = $xml_conditions->group;
|
||||
if($xml_groups)
|
||||
{
|
||||
if(!is_array($xml_groups))
|
||||
{
|
||||
$xml_groups = array($xml_groups);
|
||||
}
|
||||
foreach($xml_groups as $group)
|
||||
{
|
||||
$subconditions = $group->condition;
|
||||
$subgroups = $group->group;
|
||||
$subconditions = $subconditions ? (is_array($subconditions) ? $subconditions : [$subconditions]) : [];
|
||||
$subgroups = $subgroups ? (is_array($subgroups) ? $subgroups : [$subgroups]) : [];
|
||||
$this->condition_groups[] = new ConditionGroupTag(array_merge($subconditions, $subgroups), $group->attrs->pipe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ConditionGroupTag object to string
|
||||
* @return string
|
||||
*/
|
||||
function toString()
|
||||
{
|
||||
$output_conditions = 'array(' . PHP_EOL;
|
||||
foreach($this->condition_groups as $condition)
|
||||
{
|
||||
$output_conditions .= $condition->getConditionGroupString() . PHP_EOL . ',';
|
||||
}
|
||||
$output_conditions = substr($output_conditions, 0, -1);
|
||||
$output_conditions .= ')';
|
||||
return $output_conditions;
|
||||
}
|
||||
|
||||
function getArguments()
|
||||
{
|
||||
$arguments = array();
|
||||
foreach($this->condition_groups as $condition)
|
||||
{
|
||||
$arguments = array_merge($arguments, $condition->getArguments());
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file ConditionsTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/condition/ConditionsTag.class.php */
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* JoinConditionsTag class
|
||||
*
|
||||
* @author Corina
|
||||
* @package /classes/xml/xmlquery/tags/condition
|
||||
* @version 0.1
|
||||
*/
|
||||
class JoinConditionsTag extends ConditionsTag
|
||||
{
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param object $xml_conditions
|
||||
* @return void
|
||||
*/
|
||||
function __construct($xml_conditions)
|
||||
{
|
||||
parent::__construct($xml_conditions);
|
||||
$this->condition_groups[0]->conditions[0]->setPipe("");
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file JoinConditionsTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/condition/JoinConditionsTag.class.php */
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* GroupsTag class
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/group
|
||||
* @version 0.1
|
||||
*/
|
||||
class GroupsTag
|
||||
{
|
||||
|
||||
/**
|
||||
* column list
|
||||
* @var array
|
||||
*/
|
||||
var $groups;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param array|string $xml_groups
|
||||
* @return void
|
||||
*/
|
||||
function __construct($xml_groups)
|
||||
{
|
||||
$this->groups = array();
|
||||
|
||||
if($xml_groups)
|
||||
{
|
||||
if(!is_array($xml_groups))
|
||||
{
|
||||
$xml_groups = array($xml_groups);
|
||||
}
|
||||
|
||||
$dbParser = &DB::getParser();
|
||||
for($i = 0; $i < count($xml_groups); $i++)
|
||||
{
|
||||
$group = $xml_groups[$i];
|
||||
$column = trim($group->attrs->column);
|
||||
if(!$column)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$column = $dbParser->parseExpression($column);
|
||||
$this->groups[] = $column;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function toString()
|
||||
{
|
||||
$output = 'array(' . PHP_EOL;
|
||||
foreach($this->groups as $group)
|
||||
{
|
||||
$output .= "'" . $group . "' ,";
|
||||
}
|
||||
$output = substr($output, 0, -1);
|
||||
$output .= ')';
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file GroupsTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/group/GroupsTag.class.php */
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* IndexTag class
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/navigation
|
||||
* @version 0.1
|
||||
*/
|
||||
class IndexTag
|
||||
{
|
||||
|
||||
/**
|
||||
* argument name
|
||||
* @var string
|
||||
*/
|
||||
var $argument_name;
|
||||
|
||||
/**
|
||||
* QueryArgument object
|
||||
* @var QueryArgument
|
||||
*/
|
||||
var $argument;
|
||||
|
||||
/**
|
||||
* Default value
|
||||
* @var string
|
||||
*/
|
||||
var $default;
|
||||
|
||||
/**
|
||||
* Sort order
|
||||
* @var string
|
||||
*/
|
||||
var $sort_order;
|
||||
|
||||
/**
|
||||
* Sort order argument
|
||||
* @var SortQueryArgument object
|
||||
*/
|
||||
var $sort_order_argument;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param object $index
|
||||
* @return void
|
||||
*/
|
||||
function __construct($index)
|
||||
{
|
||||
$this->argument_name = $index->attrs->var;
|
||||
|
||||
// Sort index - column by which to sort
|
||||
//$dbParser = new DB(); $dbParser = &$dbParser->getParser();
|
||||
//$index->attrs->default = $dbParser->parseExpression($index->attrs->default);
|
||||
$this->default = $index->attrs->default;
|
||||
$this->argument = new QueryArgument($index);
|
||||
|
||||
// Sort order - asc / desc
|
||||
$this->sort_order = $index->attrs->order;
|
||||
$sortList = array('asc' => 1, 'desc' => 1);
|
||||
if(!isset($sortList[$this->sort_order]))
|
||||
{
|
||||
$arg = new Xml_Node_();
|
||||
$arg->attrs = new Xml_Node_();
|
||||
$arg->attrs->var = $this->sort_order;
|
||||
$arg->attrs->default = 'asc';
|
||||
$this->sort_order_argument = new SortQueryArgument($arg);
|
||||
$this->sort_order = '$' . $this->sort_order_argument->getArgumentName() . '_argument';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->sort_order = '"' . $this->sort_order . '"';
|
||||
}
|
||||
}
|
||||
|
||||
function toString()
|
||||
{
|
||||
return sprintf('new OrderByColumn(${\'%s_argument\'}, %s)', $this->argument->getArgumentName(), $this->sort_order);
|
||||
}
|
||||
|
||||
function getArguments()
|
||||
{
|
||||
$arguments = array();
|
||||
$arguments[] = $this->argument;
|
||||
if($this->sort_order_argument)
|
||||
{
|
||||
$arguments[] = $this->sort_order_argument;
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file IndexTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/navigation/IndexTag.class.php */
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* LimitTag class
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/navigation
|
||||
* @version 0.1
|
||||
*/
|
||||
class LimitTag
|
||||
{
|
||||
|
||||
/**
|
||||
* Value is relate to limit query
|
||||
* @var array
|
||||
*/
|
||||
var $arguments;
|
||||
|
||||
/**
|
||||
* QueryArgument object
|
||||
* @var QueryArgument
|
||||
*/
|
||||
var $page;
|
||||
|
||||
/**
|
||||
* QueryArgument object
|
||||
* @var QueryArgument
|
||||
*/
|
||||
var $page_count;
|
||||
|
||||
/**
|
||||
* QueryArgument object
|
||||
* @var QueryArgument
|
||||
*/
|
||||
var $list_count;
|
||||
|
||||
/**
|
||||
* QueryArgument object
|
||||
* @var QueryArgument
|
||||
*/
|
||||
var $offset;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param object $index
|
||||
* @return void
|
||||
*/
|
||||
function __construct($index)
|
||||
{
|
||||
if($index->page && $index->page->attrs && $index->page_count && $index->page_count->attrs)
|
||||
{
|
||||
if(!isset($index->page->attrs->default))
|
||||
$index->page->attrs->default = 1;
|
||||
if(!isset($index->page_count->attrs->default))
|
||||
$index->page_count->attrs->default = 10;
|
||||
$this->page = new QueryArgument($index->page);
|
||||
$this->page_count = new QueryArgument($index->page_count);
|
||||
$this->arguments[] = $this->page;
|
||||
$this->arguments[] = $this->page_count;
|
||||
}
|
||||
|
||||
if(!isset($index->list_count->attrs->default))
|
||||
$index->list_count->attrs->default = 0;
|
||||
$this->list_count = new QueryArgument($index->list_count);
|
||||
$this->arguments[] = $this->list_count;
|
||||
|
||||
if(isset($index->offset) && isset($index->offset->attrs))
|
||||
{
|
||||
$this->offset = new QueryArgument($index->offset);
|
||||
$this->arguments[] = $this->offset;
|
||||
}
|
||||
}
|
||||
|
||||
function toString()
|
||||
{
|
||||
if($this->page)
|
||||
{
|
||||
return sprintf('new Limit(${\'%s_argument\'}, ${\'%s_argument\'}, ${\'%s_argument\'})', $this->list_count->getArgumentName(), $this->page->getArgumentName(), $this->page_count->getArgumentName());
|
||||
}
|
||||
elseif($this->offset)
|
||||
{
|
||||
return sprintf('new Limit(${\'%s_argument\'}, NULL, NULL, ${\'%s_argument\'})', $this->list_count->getArgumentName(), $this->offset->getArgumentName());
|
||||
}
|
||||
else
|
||||
{
|
||||
return sprintf('new Limit(${\'%s_argument\'})', $this->list_count->getArgumentName());
|
||||
}
|
||||
}
|
||||
|
||||
function getArguments()
|
||||
{
|
||||
return $this->arguments;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file LimitTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/navigation/LimitTag.class.php */
|
||||
|
|
@ -1,137 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* NavigationTag class
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/navigation
|
||||
* @version 0.1
|
||||
*/
|
||||
class NavigationTag
|
||||
{
|
||||
|
||||
/**
|
||||
* Order
|
||||
* @var array
|
||||
*/
|
||||
var $order;
|
||||
|
||||
/**
|
||||
* List count
|
||||
* @var int
|
||||
*/
|
||||
var $list_count;
|
||||
|
||||
/**
|
||||
* Page count
|
||||
* @var int
|
||||
*/
|
||||
var $page_count;
|
||||
|
||||
/**
|
||||
* Page
|
||||
* @var int
|
||||
*/
|
||||
var $page;
|
||||
|
||||
/**
|
||||
* Limit
|
||||
* @var LimitTag object
|
||||
*/
|
||||
var $limit;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param object $xml_navigation
|
||||
* @return void
|
||||
*/
|
||||
function __construct($xml_navigation)
|
||||
{
|
||||
$this->order = array();
|
||||
if($xml_navigation)
|
||||
{
|
||||
$order = $xml_navigation->index;
|
||||
if($order)
|
||||
{
|
||||
if(!is_array($order))
|
||||
{
|
||||
$order = array($order);
|
||||
}
|
||||
foreach($order as $order_info)
|
||||
{
|
||||
$this->order[] = new IndexTag($order_info);
|
||||
}
|
||||
|
||||
if($xml_navigation->page && $xml_navigation->page->attrs || $xml_navigation->list_count && $xml_navigation->list_count->attrs)
|
||||
{
|
||||
$this->limit = new LimitTag($xml_navigation);
|
||||
}
|
||||
|
||||
if($xml_navigation->list_count)
|
||||
{
|
||||
$this->list_count = $xml_navigation->list_count->attrs;
|
||||
}
|
||||
|
||||
if($xml_navigation->page_count)
|
||||
{
|
||||
$this->page_count = $xml_navigation->page_count->attrs;
|
||||
}
|
||||
|
||||
if($xml_navigation->page)
|
||||
{
|
||||
$this->page = $xml_navigation->page->attrs;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* NavigationTag object to string
|
||||
* @return string
|
||||
*/
|
||||
function getOrderByString()
|
||||
{
|
||||
$output = 'array(' . PHP_EOL;
|
||||
foreach($this->order as $order)
|
||||
{
|
||||
$output .= $order->toString() . PHP_EOL . ',';
|
||||
}
|
||||
$output = substr($output, 0, -1);
|
||||
$output .= ')';
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* LimitTag object to string
|
||||
* @return string
|
||||
*/
|
||||
function getLimitString()
|
||||
{
|
||||
if($this->limit)
|
||||
{
|
||||
return $this->limit->toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
function getArguments()
|
||||
{
|
||||
$arguments = array();
|
||||
foreach($this->order as $order)
|
||||
{
|
||||
$arguments = array_merge($order->getArguments(), $arguments);
|
||||
}
|
||||
if($this->limit)
|
||||
{
|
||||
$arguments = array_merge($this->limit->getArguments(), $arguments);
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file NavigationTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/navigation/NavigationTag.class.php */
|
||||
|
|
@ -1,407 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* QueryTag class
|
||||
*
|
||||
* @author Arnia Software
|
||||
* @package /classes/xml/xmlquery/tags/query
|
||||
* @version 0.1
|
||||
*/
|
||||
class QueryTag
|
||||
{
|
||||
|
||||
/**
|
||||
* Action for example, 'select', 'insert', 'delete'...
|
||||
* @var string
|
||||
*/
|
||||
var $action;
|
||||
|
||||
/**
|
||||
* Query id
|
||||
* @var string
|
||||
*/
|
||||
var $query_id;
|
||||
|
||||
/**
|
||||
* Priority
|
||||
* @var string
|
||||
*/
|
||||
var $priority;
|
||||
|
||||
/**
|
||||
* column type list
|
||||
* @var array
|
||||
*/
|
||||
var $column_type;
|
||||
|
||||
/**
|
||||
* Query stdClass object
|
||||
* @var object
|
||||
*/
|
||||
var $query;
|
||||
|
||||
/**
|
||||
* Columns in xml tags
|
||||
* @var object
|
||||
*/
|
||||
var $columns;
|
||||
|
||||
/**
|
||||
* Tables in xml tags
|
||||
* @var object
|
||||
*/
|
||||
var $tables;
|
||||
|
||||
/**
|
||||
* Subquery in xml tags
|
||||
* @var object
|
||||
*/
|
||||
var $subquery;
|
||||
|
||||
/**
|
||||
* Conditions in xml tags
|
||||
* @var object
|
||||
*/
|
||||
var $conditions;
|
||||
|
||||
/**
|
||||
* Groups in xml tags
|
||||
* @var object
|
||||
*/
|
||||
var $groups;
|
||||
|
||||
/**
|
||||
* Having in xml tags
|
||||
* @var object
|
||||
*/
|
||||
var $having;
|
||||
|
||||
/**
|
||||
* Navigation in xml tags
|
||||
* @var object
|
||||
*/
|
||||
var $navigation;
|
||||
|
||||
/**
|
||||
* Arguments in xml tags
|
||||
* @var object
|
||||
*/
|
||||
var $arguments;
|
||||
|
||||
/**
|
||||
* PreBuff
|
||||
* @var string
|
||||
*/
|
||||
var $preBuff;
|
||||
|
||||
/**
|
||||
* Buff
|
||||
* @var string
|
||||
*/
|
||||
var $buff;
|
||||
|
||||
/**
|
||||
* Subquery status
|
||||
* @var bool
|
||||
*/
|
||||
var $isSubQuery;
|
||||
|
||||
/**
|
||||
* Join type
|
||||
* @var string
|
||||
*/
|
||||
var $join_type;
|
||||
|
||||
/**
|
||||
* alias
|
||||
* @var string
|
||||
*/
|
||||
var $alias;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param object $query
|
||||
* @param bool $isSubQuery
|
||||
* @return void
|
||||
*/
|
||||
function __construct($query, $isSubQuery = FALSE)
|
||||
{
|
||||
$this->action = $query->attrs->action;
|
||||
$this->query_id = $query->attrs->id;
|
||||
$this->priority = $query->attrs->priority;
|
||||
$this->query = $query;
|
||||
$this->isSubQuery = $isSubQuery;
|
||||
if($this->isSubQuery)
|
||||
{
|
||||
$this->action = 'select';
|
||||
}
|
||||
if($query->attrs->alias)
|
||||
{
|
||||
$dbParser = DB::getParser();
|
||||
$this->alias = $dbParser->escape($query->attrs->alias);
|
||||
}
|
||||
$this->join_type = $query->attrs->join_type;
|
||||
|
||||
$this->getColumns();
|
||||
$tables = $this->getTables();
|
||||
$this->setTableColumnTypes($tables);
|
||||
$this->getSubquery(); // Used for insert-select
|
||||
$this->getConditions();
|
||||
$this->getGroups();
|
||||
$this->getNavigation();
|
||||
|
||||
$this->getPrebuff();
|
||||
$this->getBuff();
|
||||
}
|
||||
|
||||
function show()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
function getQueryId()
|
||||
{
|
||||
return $this->query->attrs->query_id ? $this->query->attrs->query_id : $this->query->attrs->id;
|
||||
}
|
||||
|
||||
function getPriority()
|
||||
{
|
||||
return $this->query->attrs->priority;
|
||||
}
|
||||
|
||||
function getAction()
|
||||
{
|
||||
return $this->query->attrs->action;
|
||||
}
|
||||
|
||||
function setTableColumnTypes($tables)
|
||||
{
|
||||
$query_id = $this->getQueryId();
|
||||
if(!isset($this->column_type[$query_id]))
|
||||
{
|
||||
$table_tags = $tables->getTables();
|
||||
$column_type = array();
|
||||
foreach($table_tags as $table_tag)
|
||||
{
|
||||
if(is_a($table_tag, 'TableTag'))
|
||||
{
|
||||
$table_name = $table_tag->getTableName();
|
||||
$table_alias = $table_tag->getTableAlias();
|
||||
$tag_column_type = QueryParser::getTableInfo($query_id, $table_name);
|
||||
$column_type[$table_alias] = $tag_column_type;
|
||||
}
|
||||
}
|
||||
$this->column_type[$query_id] = $column_type;
|
||||
}
|
||||
}
|
||||
|
||||
function getColumns()
|
||||
{
|
||||
if($this->action == 'select')
|
||||
{
|
||||
return $this->columns = new SelectColumnsTag($this->query->columns);
|
||||
}
|
||||
else if($this->action == 'insert' || $this->action == 'insert-select')
|
||||
{
|
||||
return $this->columns = new InsertColumnsTag($this->query->columns->column);
|
||||
}
|
||||
else if($this->action == 'update')
|
||||
{
|
||||
return $this->columns = new UpdateColumnsTag($this->query->columns->column);
|
||||
}
|
||||
else if($this->action == 'delete')
|
||||
{
|
||||
return $this->columns = null;
|
||||
}
|
||||
}
|
||||
|
||||
function getPrebuff()
|
||||
{
|
||||
if($this->isSubQuery)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// TODO Check if this work with arguments in join clause
|
||||
$arguments = $this->getArguments();
|
||||
|
||||
$prebuff = '';
|
||||
foreach($arguments as $argument)
|
||||
{
|
||||
if(isset($argument))
|
||||
{
|
||||
$arg_name = $argument->getArgumentName();
|
||||
if($arg_name)
|
||||
{
|
||||
unset($column_type);
|
||||
$prebuff .= $argument->toString();
|
||||
|
||||
$table_alias = $argument->getTableName();
|
||||
if(isset($table_alias))
|
||||
{
|
||||
if(isset($this->column_type[$this->getQueryId()][$table_alias][$argument->getColumnName()]))
|
||||
{
|
||||
$column_type = $this->column_type[$this->getQueryId()][$table_alias][$argument->getColumnName()];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$current_tables = $this->column_type[$this->getQueryId()];
|
||||
$column_name = $argument->getColumnName();
|
||||
foreach($current_tables as $current_table)
|
||||
{
|
||||
if(isset($current_table[$column_name]))
|
||||
{
|
||||
$column_type = $current_table[$column_name];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($column_type))
|
||||
{
|
||||
$prebuff .= sprintf('if(${\'%s_argument\'} !== null) ${\'%s_argument\'}->setColumnType(\'%s\');' . "\n"
|
||||
, $arg_name
|
||||
, $arg_name
|
||||
, $column_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$prebuff .= "\n";
|
||||
|
||||
return $this->preBuff = $prebuff;
|
||||
}
|
||||
|
||||
function getBuff()
|
||||
{
|
||||
$buff = '';
|
||||
if($this->isSubQuery)
|
||||
{
|
||||
$buff = 'new Subquery(';
|
||||
$buff .= "'" . $this->alias . '\', ';
|
||||
$buff .= ($this->columns ? $this->columns->toString() : 'null' ) . ', ' . PHP_EOL;
|
||||
$buff .= $this->tables->toString() . ',' . PHP_EOL;
|
||||
$buff .= $this->conditions->toString() . ',' . PHP_EOL;
|
||||
$buff .= $this->groups->toString() . ',' . PHP_EOL;
|
||||
$buff .= $this->navigation->getOrderByString() . ',' . PHP_EOL;
|
||||
$limit = $this->navigation->getLimitString();
|
||||
$buff .= $limit ? $limit : 'null' . PHP_EOL;
|
||||
$buff .= $this->join_type ? "'" . $this->join_type . "'" : '';
|
||||
$buff .= ')';
|
||||
|
||||
$this->buff = $buff;
|
||||
return $this->buff;
|
||||
}
|
||||
|
||||
$buff .= '$query = new Query();' . PHP_EOL;
|
||||
$buff .= sprintf('$query->setQueryId("%s");%s', $this->query_id, "\n");
|
||||
$buff .= sprintf('$query->setAction("%s");%s', $this->action, "\n");
|
||||
$buff .= sprintf('$query->setPriority("%s");%s', $this->priority, "\n");
|
||||
$buff .= $this->preBuff;
|
||||
if($this->columns)
|
||||
{
|
||||
$buff .= '$query->setColumns(' . $this->columns->toString() . ');' . PHP_EOL;
|
||||
}
|
||||
|
||||
$buff .= '$query->setTables(' . $this->tables->toString() . ');' . PHP_EOL;
|
||||
if($this->action == 'insert-select')
|
||||
{
|
||||
$buff .= '$query->setSubquery(' . $this->subquery->toString() . ');' . PHP_EOL;
|
||||
}
|
||||
$buff .= '$query->setConditions(' . $this->conditions->toString() . ');' . PHP_EOL;
|
||||
$buff .= '$query->setGroups(' . $this->groups->toString() . ');' . PHP_EOL;
|
||||
$buff .= '$query->setHaving(' . $this->having->toString() . ');' . PHP_EOL;
|
||||
$buff .= '$query->setOrder(' . $this->navigation->getOrderByString() . ');' . PHP_EOL;
|
||||
$buff .= '$query->setLimit(' . $this->navigation->getLimitString() . ');' . PHP_EOL;
|
||||
|
||||
$this->buff = $buff;
|
||||
return $this->buff;
|
||||
}
|
||||
|
||||
function getTables()
|
||||
{
|
||||
if($this->query->index_hint && ($this->query->index_hint->attrs->for == 'ALL' || Context::getDBType() == strtolower($this->query->index_hint->attrs->for)))
|
||||
{
|
||||
return $this->tables = new TablesTag($this->query->tables, $this->query->index_hint);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->tables = new TablesTag($this->query->tables);
|
||||
}
|
||||
}
|
||||
|
||||
function getSubquery()
|
||||
{
|
||||
if($this->query->query)
|
||||
{
|
||||
$this->subquery = new QueryTag($this->query->query, true);
|
||||
}
|
||||
}
|
||||
|
||||
function getConditions()
|
||||
{
|
||||
return $this->conditions = new ConditionsTag($this->query->conditions);
|
||||
}
|
||||
|
||||
function getGroups()
|
||||
{
|
||||
if($this->query->groups)
|
||||
{
|
||||
$this->groups = new GroupsTag($this->query->groups->group);
|
||||
$this->having = new ConditionsTag($this->query->groups->having);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->groups = new GroupsTag(NULL);
|
||||
$this->having = new ConditionsTag(array());
|
||||
}
|
||||
|
||||
return $this->groups;
|
||||
}
|
||||
|
||||
function getNavigation()
|
||||
{
|
||||
return $this->navigation = new NavigationTag($this->query->navigation);
|
||||
}
|
||||
|
||||
function toString()
|
||||
{
|
||||
return $this->buff;
|
||||
}
|
||||
|
||||
function getTableString()
|
||||
{
|
||||
return $this->buff;
|
||||
}
|
||||
|
||||
function getConditionString()
|
||||
{
|
||||
return $this->buff;
|
||||
}
|
||||
|
||||
function getExpressionString()
|
||||
{
|
||||
return $this->buff;
|
||||
}
|
||||
|
||||
function getArguments()
|
||||
{
|
||||
$arguments = array();
|
||||
if($this->columns)
|
||||
{
|
||||
$arguments = array_merge($arguments, $this->columns->getArguments());
|
||||
}
|
||||
if($this->action == 'insert-select')
|
||||
{
|
||||
$arguments = array_merge($arguments, $this->subquery->getArguments());
|
||||
}
|
||||
$arguments = array_merge($arguments, $this->tables->getArguments());
|
||||
$arguments = array_merge($arguments, $this->conditions->getArguments());
|
||||
$arguments = array_merge($arguments, $this->having->getArguments());
|
||||
$arguments = array_merge($arguments, $this->navigation->getArguments());
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file QueryTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/navigation/QueryTag.class.php */
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* HintTableTag
|
||||
* Models the <table> tag inside an XML Query file and the corresponding <index_hint> tag
|
||||
*
|
||||
* @author Arnia Sowftare
|
||||
* @package /classes/xml/xmlquery/tags/table
|
||||
* @version 0.1
|
||||
*/
|
||||
class HintTableTag extends TableTag
|
||||
{
|
||||
|
||||
/**
|
||||
* Action for example, 'select', 'insert', 'delete'...
|
||||
* @var array
|
||||
*/
|
||||
var $index;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* Initialises Table Tag properties
|
||||
* @param object $table XML <table> tag
|
||||
* @param array $index
|
||||
* @return void
|
||||
*/
|
||||
function __construct($table, $index)
|
||||
{
|
||||
parent::__construct($table);
|
||||
$this->index = $index;
|
||||
}
|
||||
|
||||
function getTableString()
|
||||
{
|
||||
$dbParser = DB::getParser();
|
||||
$dbType = ucfirst(Context::getDBType());
|
||||
|
||||
$result = sprintf('new %sTableWithHint(\'%s\'%s, array('
|
||||
, starts_with('mysql', $dbType, false) ? 'Mysql' : $dbType
|
||||
, $dbParser->escape($this->name)
|
||||
, $this->alias ? ', \'' . $dbParser->escape($this->alias) . '\'' : ', null'
|
||||
//, ', \'' . $dbParser->escape($this->index->name) .'\', \'' . $this->index->type .'\''
|
||||
);
|
||||
foreach($this->index as $indx)
|
||||
{
|
||||
$result .= "new IndexHint(";
|
||||
$result .= '\'' . $dbParser->escape($indx->name) . '\', \'' . $indx->type . '\'' . ') , ';
|
||||
}
|
||||
$result = substr($result, 0, -2);
|
||||
$result .= '))';
|
||||
return $result;
|
||||
}
|
||||
|
||||
function getArguments()
|
||||
{
|
||||
if(!isset($this->conditionsTag))
|
||||
{
|
||||
return array();
|
||||
}
|
||||
return $this->conditionsTag->getArguments();
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file HintTableTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/table/HintTableTag.class.php */
|
||||
|
|
@ -1,145 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* TableTag
|
||||
* Models the <table> tag inside an XML Query file
|
||||
* @abstract
|
||||
* Example
|
||||
* <table name="modules" />
|
||||
* <table name="documents" alias="doc" />
|
||||
* Attributes
|
||||
* name - name of the table - table prefix will be automatically added
|
||||
* alias - table alias. If no value is specified, the table name will be set as default alias
|
||||
* join_type - in case the table is part of a join clause, this specifies the type of join: left, right etc.
|
||||
* - permitted values: 'left join','left outer join','right join','right outer join'
|
||||
* Children
|
||||
* Can have children of type <conditions>
|
||||
*
|
||||
* @author Arnia Sowftare
|
||||
* @package /classes/xml/xmlquery/tags/table
|
||||
* @version 0.1
|
||||
*/
|
||||
class TableTag
|
||||
{
|
||||
|
||||
/**
|
||||
* Unescaped name
|
||||
* @var string
|
||||
*/
|
||||
var $unescaped_name;
|
||||
|
||||
/**
|
||||
* name
|
||||
* @var string
|
||||
*/
|
||||
var $name;
|
||||
|
||||
/**
|
||||
* alias
|
||||
* @var string
|
||||
*/
|
||||
var $alias;
|
||||
|
||||
/**
|
||||
* Join type
|
||||
* @example 'left join', 'left outer join', 'right join', 'right outer join'
|
||||
* @var string
|
||||
*/
|
||||
var $join_type;
|
||||
|
||||
/**
|
||||
* Condition object
|
||||
* @var object
|
||||
*/
|
||||
var $conditions;
|
||||
|
||||
/**
|
||||
* JoinConditionsTag
|
||||
* @var JoinConditionsTag object
|
||||
*/
|
||||
var $conditionsTag;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* Initialises Table Tag properties
|
||||
* @param object $table XML <table> tag
|
||||
* @return void
|
||||
*/
|
||||
function __construct($table)
|
||||
{
|
||||
$dbParser = DB::getParser();
|
||||
|
||||
$this->unescaped_name = $table->attrs->name;
|
||||
$this->name = $dbParser->parseTableName($table->attrs->name);
|
||||
|
||||
$this->alias = $table->attrs->alias;
|
||||
if(!$this->alias)
|
||||
{
|
||||
$this->alias = $table->attrs->name;
|
||||
}
|
||||
|
||||
$this->join_type = $table->attrs->type;
|
||||
|
||||
$this->conditions = $table->conditions;
|
||||
|
||||
if($this->isJoinTable())
|
||||
{
|
||||
$this->conditionsTag = new JoinConditionsTag($this->conditions);
|
||||
}
|
||||
}
|
||||
|
||||
function isJoinTable()
|
||||
{
|
||||
$joinList = array('left join' => 1, 'left outer join' => 1, 'right join' => 1, 'right outer join' => 1);
|
||||
if(isset($joinList[$this->join_type]) && countobj($this->conditions))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function getTableAlias()
|
||||
{
|
||||
return $this->alias;
|
||||
}
|
||||
|
||||
function getTableName()
|
||||
{
|
||||
return $this->unescaped_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns string for printing in PHP query cache file
|
||||
* The string contains code for instantiation of either
|
||||
* a Table or a JoinTable object
|
||||
* @return string
|
||||
*/
|
||||
function getTableString()
|
||||
{
|
||||
$dbParser = DB::getParser();
|
||||
|
||||
if($this->isJoinTable())
|
||||
{
|
||||
return sprintf('new JoinTable(\'%s\', \'%s\', "%s", %s)'
|
||||
, $dbParser->escape($this->name)
|
||||
, $dbParser->escape($this->alias)
|
||||
, $this->join_type, $this->conditionsTag->toString());
|
||||
}
|
||||
return sprintf('new Table(\'%s\'%s)'
|
||||
, $dbParser->escape($this->name)
|
||||
, $this->alias ? ', \'' . $dbParser->escape($this->alias) . '\'' : '');
|
||||
}
|
||||
|
||||
function getArguments()
|
||||
{
|
||||
if(!isset($this->conditionsTag))
|
||||
{
|
||||
return array();
|
||||
}
|
||||
return $this->conditionsTag->getArguments();
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file TableTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/table/TableTag.class.php */
|
||||
|
|
@ -1,122 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* TablesTag class
|
||||
* Models the <tables> tag inside an XML Query file
|
||||
* @abstract
|
||||
* Example
|
||||
* <tables>
|
||||
* <table name="documents" alias="doc" />
|
||||
* </tables>
|
||||
* Attributes
|
||||
* None.
|
||||
* Children
|
||||
* Can have children of type <table> or <query>
|
||||
*
|
||||
* @author Arnia Sowftare
|
||||
* @package /classes/xml/xmlquery/tags/table
|
||||
* @version 0.1
|
||||
*/
|
||||
class TablesTag
|
||||
{
|
||||
|
||||
/**
|
||||
* Table list
|
||||
* @var array
|
||||
*/
|
||||
var $tables;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param object $xml_tables_tag
|
||||
* @param object $xml_index_hints_tag
|
||||
* @return void
|
||||
*/
|
||||
function __construct($xml_tables_tag, $xml_index_hints_tag = NULL)
|
||||
{
|
||||
$this->tables = array();
|
||||
|
||||
$xml_tables = $xml_tables_tag->table;
|
||||
if(!is_array($xml_tables))
|
||||
{
|
||||
$xml_tables = array($xml_tables);
|
||||
}
|
||||
|
||||
if($xml_index_hints_tag)
|
||||
{
|
||||
$index_nodes = $xml_index_hints_tag->index;
|
||||
if(!is_array($index_nodes))
|
||||
{
|
||||
$index_nodes = array($index_nodes);
|
||||
}
|
||||
foreach($index_nodes as $index_node)
|
||||
{
|
||||
if(!isset($indexes[$index_node->attrs->table]))
|
||||
{
|
||||
$indexes[$index_node->attrs->table] = array();
|
||||
}
|
||||
$count = count($indexes[$index_node->attrs->table]);
|
||||
$indexes[$index_node->attrs->table][$count] = (object) NULL;
|
||||
$indexes[$index_node->attrs->table][$count]->name = $index_node->attrs->name;
|
||||
$indexes[$index_node->attrs->table][$count]->type = $index_node->attrs->type;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($xml_tables as $tag)
|
||||
{
|
||||
if($tag->attrs->query == 'true')
|
||||
{
|
||||
$this->tables[] = new QueryTag($tag, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(isset($indexes[$tag->attrs->name]) && $indexes[$tag->attrs->name])
|
||||
{
|
||||
$this->tables[] = new HintTableTag($tag, $indexes[$tag->attrs->name]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->tables[] = new TableTag($tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getTables()
|
||||
{
|
||||
return $this->tables;
|
||||
}
|
||||
|
||||
function toString()
|
||||
{
|
||||
$output_tables = 'array(' . PHP_EOL;
|
||||
foreach($this->tables as $table)
|
||||
{
|
||||
if(is_a($table, 'QueryTag'))
|
||||
{
|
||||
$output_tables .= $table->toString() . PHP_EOL . ',';
|
||||
}
|
||||
else
|
||||
{
|
||||
$output_tables .= $table->getTableString() . PHP_EOL . ',';
|
||||
}
|
||||
}
|
||||
$output_tables = substr($output_tables, 0, -1);
|
||||
$output_tables .= ')';
|
||||
return $output_tables;
|
||||
}
|
||||
|
||||
function getArguments()
|
||||
{
|
||||
$arguments = array();
|
||||
foreach($this->tables as $table)
|
||||
{
|
||||
$arguments = array_merge($arguments, $table->getArguments());
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file TablesTag.class.php */
|
||||
/* Location: ./classes/xml/xmlquery/tags/table/TablesTag.class.php */
|
||||
Loading…
Add table
Add a link
Reference in a new issue