add phpDoc style comment

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@10774 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ovclas 2012-06-14 02:33:44 +00:00
parent 744cc459ac
commit 3f0dd9cb06
11 changed files with 534 additions and 229 deletions

View file

@ -1,21 +1,32 @@
<?php
/**
* @class HttpRequest
* - HttpRequest class
* - a class that is designed to be used for sending out HTTP request to an external server and retrieving response
* - Connection: keep-alive is not supported
* @author NHN (developers@xpressengine.com)
* @package /classes/httprequest
* @version 0.1
* @brief a class that is designed to be used for sending out HTTP request to an external server and retrieving response
* @remarks Connection: keep-alive is not supported
*/
class XEHttpRequest {
/// target host
/**
* target host
* @var string
*/
var $m_host;
/// target Port
/**
* target Port
* @var int
*/
var $m_port;
/// header array
/**
* target header
* @var array
*/
var $m_headers;
/**
* @brief Constructor
* constructor
* @return void
*/
function XEHttpRequest($host, $port)
{
@ -25,9 +36,10 @@ class XEHttpRequest {
}
/**
* @brief mether to add key/value pair to the HTTP request header
* @param[in] key HTTP header element
* @param[in] value value string for HTTP header element
* Mether to add key/value pair to the HTTP request header
* @param int|string $key HTTP header element
* @param string $value value string for HTTP header element
* @return void
*/
function addToHeader($key, $value)
{
@ -35,12 +47,12 @@ class XEHttpRequest {
}
/**
* @brief send HTTP message to the host
* @param[in] target ip or url of the external server
* @param[in] method HTTP method such as GET and POST
* @param[in] timeout time out value for HTTP request expiration
* @param[in] post variables to send
* @return Returns an object containing HTTP Response body and HTTP response code
* Send HTTP message to the host
* @param string $target ip or url of the external server
* @param string $method HTTP method such as GET and POST
* @param int $timeout time out value for HTTP request expiration
* @param array $post_vars variables to send
* @return object Returns an object containing HTTP Response body and HTTP response code
*/
function send($target='/', $method='GET', $timeout=3, $post_vars=null)
{
@ -67,8 +79,12 @@ class XEHttpRequest {
}
/**
* @brief Send a request with the file socket
* @private
* Send a request with the file socket
* @param string $target ip or url of the external server
* @param string $method HTTP method such as GET and POST
* @param int $timeout time out value for HTTP request expiration
* @param array $post_vars variables to send
* @return object Returns an object containing HTTP Response body and HTTP response code
*/
function sendWithSock($target, $method, $timeout, $post_vars)
{
@ -131,8 +147,12 @@ class XEHttpRequest {
}
/**
* @brief Send a request with the curl library
* @private
* Send a request with the curl library
* @param string $target ip or url of the external server
* @param string $method HTTP method such as GET and POST
* @param int $timeout time out value for HTTP request expiration
* @param array $post_vars variables to send
* @return object Returns an object containing HTTP Response body and HTTP response code
*/
function sendWithCurl($target, $method, $timeout, $post_vars)
{

View file

@ -1,20 +1,23 @@
<?php
/**
* @class Security
* @brief This class helps to solve security problems.
* - Security class
* - This class helps to solve security problems.
* @author NHN (developers@xpressengine.com)
**/
* @package /classes/security
* @version 0.1
*/
class Security
{
/**
* @brief Action target variable. If this value is null, the method will use Context variables
* @protected
* Action target variable. If this value is null, the method will use Context variables
* @var mixed
**/
var $_targetVar = null;
/**
* @constructor
* @param $var Target context
* @param mixed $var Target context
* @return void
*/
function Security($var = null)
{
@ -22,13 +25,11 @@ class Security
}
/**
* @brief Convert special characters to HTML entities for the target variables.
* The results of conversion are equivalent to the results of htmlspecialchars() which is a native function of PHP.
* @params string $varName
* A variable's name to convert
* To process properties of an object or elements of an array,
* separate the owner(object or array) and the item(property or element) using a dot(.)
* @public
* - Convert special characters to HTML entities for the target variables.
* - The results of conversion are equivalent to the results of htmlspecialchars() which is a native function of PHP.
* @params string $varName. A variable's name to convert to process properties of an object or elements of an array,
* separate the owner(object or array) and the item(property or element) using a dot(.)
* @return mixed
*/
function encodeHTML(/*, $varName1, $varName2, ... */)
{
@ -70,7 +71,10 @@ class Security
}
/**
* @protected
* Convert special characters to HTML entities for the target variables.
* @param mixed $var
* @param array $name
* @return mixed
*/
function _encodeHTML($var, $name=array())
{

View file

@ -2,25 +2,66 @@
/**
* Validator class
* @author NHN (developers@xpressengine.com)
* @package /classes/validator
* @version 0.1
*/
class Validator
{
/**
* cache directory
* @var string
*/
var $_cache_dir = '';
/**
* last error
* @var array
*/
var $_last_error;
/**
* xml ruleset object
* @var Xml_Node_ object
*/
var $_xml_ruleset = null;
/**
* rule list
* @var array
*/
var $_rules;
/**
* filter list
* @var array
*/
var $_filters;
/**
* Can usable status for multibyte string function
* @var boolean
*/
var $_has_mb_func;
/**
* validator version
* @var string
*/
var $_version = '1.0';
/**
* ruleset xml file path
* @var string
*/
var $_xml_path = '';
/**
* @constructor
* @param string $xml_path
* @return void
*/
function Validator($xml_path='') {
$this->__construct($xml_path);
}
/**
* @constructor
* @param string $xml_path
* @return void
*/
function __construct($xml_path='') {
$this->_rules = array();
$this->_filters = array();
@ -42,6 +83,10 @@ class Validator
$this->setCacheDir('./files/cache');
}
/**
* @destructor
* @return void
*/
function __destruct() {
$this->_rules = null;
$this->_filters = null;
@ -49,7 +94,8 @@ class Validator
/**
* Load a xml file
* @param[in] string $xml_path A file name to be loaded
* @param string $xml_path A file name to be loaded
* @return boolean
*/
function load($xml_path) {
$this->_xml_ruleset = null;
@ -116,7 +162,8 @@ class Validator
/**
* Set root cache directory
* @param[in] string $cache_dir Root cache directory
* @param string $cache_dir Root cache directory
* @return void
*/
function setCacheDir($cache_dir){
if(is_dir($cache_dir)) {
@ -126,8 +173,8 @@ class Validator
/**
* Validate the fields. If the fields aren't passed, validation will be execute on the Context variables.
* @param[in] (optional) array $fields Target fields. The keys of the array represents field's name, its values represents field's value.
* @return bool True if it is valid, FALSE otherwise.
* @param array $fields Target fields. The keys of the array represents field's name, its values represents field's value.
* @return boolean TRUE if it is valid, FALSE otherwise.
*/
function validate($fields_=null) {
if(is_array($fields_)) {
@ -245,6 +292,8 @@ class Validator
/**
* apply trim recursive
* @param string|array $array
* @return string|array
*/
function arrayTrim($array)
{
@ -260,8 +309,8 @@ class Validator
/**
* Log an error
* @param[in] $msg error message
* @return always false
* @param $msg error message
* @return boolean always false
*/
function error($field, $msg){
$lang_filter = Context::getLang('filter');
@ -283,8 +332,9 @@ class Validator
/**
* Add a new rule
* @param[in] string $name rule name
* @param[in] mixed $rule
* @param string $name rule name
* @param mixed $rule
* @return void
*/
function addRule($name, $rule=''){
if(is_array($name)) $args = $name;
@ -305,12 +355,19 @@ class Validator
/**
* Remove a rule
* @param[in] string $name rule name
* @param string $name rule name
* @return void
*/
function removeRule($name){
unset($this->_rules[$name]);
}
/**
* add filter to filter list
* @param string $name rule name
* @param string $filter filter
* @return void
*/
function addFilter($name, $filter='') {
if(is_array($name)) $args = $name;
else $args = array($name=>$filter);
@ -331,15 +388,20 @@ class Validator
}
}
/**
* remove filter from filter list
* @param string $name rule name
* @return void
*/
function removeFilter($name) {
unset($this->_filters[$name]);
}
/**
* Find whether the field is valid with the rule
* @param[in] string $name rule name
* @param[in] string $value a value to be validated
* @return bool TRUE if the field is valid, FALSE otherwise.
* @param string $name rule name
* @param string $value a value to be validated
* @return boolean TRUE if the field is valid, FALSE otherwise.
*/
function applyRule($name, $value){
$rule = $this->_rules[$name];
@ -365,7 +427,9 @@ class Validator
}
/**
* Return
* if not supported 'mb_strlen' function, this method can use.
* @param string $str
* @return int
*/
function mbStrLen($str){
$arr = count_chars($str);
@ -411,7 +475,7 @@ class Validator
/**
* Compile a ruleset to a javascript file
* @private
* @return string
*/
function _compile2js() {
global $lang;

View file

@ -1,18 +1,23 @@
<?php
/**
* @class GeneralXmlParser
* @author NHN (developers@xpressengine.com)
* @brief Generic XML parser for XE
* @version 0.1
*/
class GeneralXmlParser {
/**
* GeneralXmlParser class
* Generic XML parser for XE
* @author NHN (developers@xpressengine.com)
* @package /classes/xml
* @version 0.1
*/
class GeneralXmlParser {
/**
* result of parse
* @var array
*/
var $output = array();
/**
* @brief parse a given input to product a object containing parse values.
* @param[in] $input data to be parsed
* @return Returns an object containing parsed values or NULL in case of failure
*/
/**
* Parse a given input to product a object containing parse values.
* @param string $input data to be parsed
* @return array|NULL Returns an object containing parsed values or NULL in case of failure
*/
function parse($input = '') {
$oParser = xml_parser_create('UTF-8');
xml_set_object($oParser, $this);
@ -28,12 +33,13 @@
return $this->output;
}
/**
* @brief start element handler
* @param[in] $parse an instance of parser
* @param[in] $node_name a name of node
* @param[in] $attrs attributes to be set
*/
/**
* Start element handler
* @param resource $parser an instance of parser
* @param string $node_name a name of node
* @param array $attrs attributes to be set
* @return void
*/
function _tagOpen($parser, $node_name, $attrs) {
$obj->node_name = strtolower($node_name);
$obj->attrs = $attrs;
@ -42,23 +48,25 @@
array_push($this->output, $obj);
}
/**
* @brief character data handler
* variable in the last element of this->output
* @param[in] $parse an instance of parser
* @param[in] $body a data to be added
*/
/**
* Character data handler
* Variable in the last element of this->output
* @param resource $parse an instance of parser
* @param string $body a data to be added
* @return void
*/
function _tagBody($parser, $body) {
//if(!trim($body)) return;
$this->output[count($this->output)-1]->body .= $body;
}
/**
* @brief end element handler
* @param[in] $parse an instance of parser
* @param[in] $node_name name of xml node
*/
/**
* End element handler
* @param resource $parse an instance of parser
* @param string $node_name name of xml node
* @return void
*/
function _tagClosed($parser, $node_name) {
$node_name = strtolower($node_name);
$cur_obj = array_pop($this->output);
@ -79,5 +87,5 @@
}
}
}
}
?>

View file

@ -1,7 +1,16 @@
<?php
/**
* XmlGenerator class
* @author NHN (developers@xpressengine.com)
* @package /classes/xml
* @version 0.1
*/
class XmlGenerator{
/**
* object change to xml
* @param object $xml
* @return string
*/
function obj2xml($xml){
$buff = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
@ -11,6 +20,11 @@ class XmlGenerator{
return $buff;
}
/**
* object change to xml
* @param object $node node in xml object
* @return string
*/
function _makexml($node){
$body = '';
foreach($node as $key => $value){

View file

@ -1,13 +1,10 @@
<?php
/**
* @class XmlJsFilter
* @author NHN (developers@xpressengine.com)
* @brief filter class traslate xml content into javascript code
* @version 0.2
* filter class traslate xml content into javascript code
*
* it convert xml code into js file and save the result as a cache file
* @code
* {
* <pre>{
* <filter name="name of javascript funcion" act="action name" confirm_msg_code="message string to be prompted when submitting the form" >
* <form> <-- code to validate data in the form
* <node target="name" required="true" minlength="1" maxlength="5" filter="email,userid,alpha,number" equalto="target" />
@ -19,9 +16,10 @@
* <tag name="error" /> <- get the result of error name
* </response>
* </filter>
* }
* }</pre>
*
* @detail {
* @detail
* <pre>{
* - syntax description of <form> node
* target = name of for element
* required = flag indicating whether a field is mandatory or not
@ -40,18 +38,40 @@
*
* - response
* tag = key : name of variable that will contain the result of the execution
* }
**/
* }</pre>
* @class XmlJsFilter
* @author NHN (developers@xpressengine.com)
* @package /classes/xml
* @version 0.2
*/
class XmlJsFilter extends XmlParser {
/**
* version
* @var string
*/
var $version = '0.2.5';
/**
* compiled javascript cache path
* @var string
*/
var $compiled_path = './files/cache/js_filter_compiled/'; // / directory path for compiled cache file
var $xml_file = NULL; // / Target xml file
var $js_file = NULL; // / Compiled js file
/**
* Target xml file
* @var string
*/
var $xml_file = NULL;
/**
* Compiled js file
* @var string
*/
var $js_file = NULL; // /
/**
* @brief constructor
**/
* constructor
* @param string $path
* @param string $xml_file
* @return void
*/
function XmlJsFilter($path, $xml_file) {
if(substr($path,-1)!=='/') $path .= '/';
$this->xml_file = sprintf("%s%s",$path, $xml_file);
@ -59,9 +79,9 @@
}
/**
* @brief compile a xml_file only when a corresponding js file does not exists or is outdated
* @return Returns NULL regardless of the success of failure of the operation
**/
* Compile a xml_file only when a corresponding js file does not exists or is outdated
* @return void Returns NULL regardless of the success of failure of the operation
*/
function compile() {
if(!file_exists($this->xml_file)) return;
if(!file_exists($this->js_file)) $this->_compile();
@ -70,8 +90,9 @@
}
/**
* @brief compile a xml_file into js_file
**/
* compile a xml_file into js_file
* @return void
*/
function _compile() {
global $lang;
@ -283,7 +304,9 @@
}
/**
* @brief return a file name of js file corresponding to the xml file
* return a file name of js file corresponding to the xml file
* @param string $xml_file
* @return string
**/
function _getCompiledFileName($xml_file) {
return sprintf('%s%s.%s.compiled.js',$this->compiled_path, md5($this->version.$xml_file),Context::getLangType());

View file

@ -1,22 +1,50 @@
<?php
/**
* @class XmlLangParser
* XmlLangParser class
* Change to lang php file from xml.
* @author NHN (developers@xpressengine.com)
* @brief change to lang php file from xml.
* @version 0.1
* @package /classes/xml
* @version 0.1
**/
class XmlLangParser extends XmlParser {
/**
* compiled language cache path
* @var string
*/
var $compiled_path = './files/cache/lang/'; // / directory path for compiled cache file
var $xml_file = NULL; // / Target xml file
var $php_file = NULL; // / Target php file
/**
* Target xml file
* @var string
*/
var $xml_file = NULL;
/**
* Target php file
* @var string
*/
var $php_file = NULL;
/**
* result source code
* @var string
*/
var $code;
/**
* language list, for example ko, en...
* @var array
*/
var $lang_types;
/**
* language type
* @see _XE_PATH_.'/common/lang/lang.info'
* @var string
*/
var $lang_type;
/**
* @brief constructor
**/
* constructor
* @param string $xml_file
* @param string $lang_type
* @return void
*/
function XmlLangParser($xml_file, $lang_type) {
$this->lang_type = $lang_type;
$this->xml_file = $xml_file;
@ -24,9 +52,9 @@
}
/**
* @brief compile a xml_file only when a corresponding php lang file does not exists or is outdated
* @return Returns compiled php file.
**/
* compile a xml_file only when a corresponding php lang file does not exists or is outdated
* @return string|bool Returns compiled php file.
*/
function compile() {
if(!file_exists($this->xml_file)) return false;
if(!file_exists($this->php_file)){
@ -36,9 +64,13 @@
else return $this->php_file;
}
return $this->_writefile() ? $this->php_file : false;
return $this->_writeFile() ? $this->php_file : false;
}
/**
* Return compiled content
* @return string Returns compiled lang source code
*/
function getCompileContent() {
if(!file_exists($this->xml_file)) return false;
$this->_compile();
@ -47,8 +79,9 @@
}
/**
* @brief compile a xml_file
**/
* Compile a xml_file
* @return void
*/
function _compile() {
$lang_selected = Context::loadLangSelected();
$this->lang_types = array_keys($lang_selected);
@ -68,8 +101,9 @@
}
/**
* @brief writing cache file
**/
* Writing cache file
* @return void|bool
*/
function _writeFile(){
if(!$this->code) return;
FileHandler::writeFile($this->php_file, "<?php\n".$this->code);
@ -77,8 +111,11 @@
}
/**
* @brief Parsing item node
**/
* Parsing item node, set content to '$this->code'
* @param object $item
* @param string $var
* @return void
*/
function _parseItem($item, $var){
$name = $item->attrs->name;
$value = $item->value;
@ -108,8 +145,11 @@
}
/**
* @brief Parsing value nodes
**/
* Parsing value nodes
* @param array $nodes
* @param string $var
* @return array|string
*/
function _parseValues($nodes, $var) {
if(!is_array($nodes)) $nodes = array($nodes);
@ -132,8 +172,11 @@
}
/**
* @brief Parsing value node
**/
* Parsing value node
* @param object $node
* @param string $var
* @return array|bool
*/
function _parseValue($node, $var) {
$lang_type = $node->attrs->xml_lang;
$value = $node->body;
@ -144,8 +187,11 @@
}
/**
* @brief get cache file name
**/
* Get cache file name
* @param string $lang_type
* @param string $type
* @return string
*/
function _getCompiledFileName($lang_type, $type='php') {
return sprintf('%s%s.%s.php',$this->compiled_path, md5($this->xml_file), $lang_type);
}

View file

@ -1,6 +1,11 @@
<?php
/* Element node or attribute node. */
/**
* Xml_Node_ class
* Element node or attribute node.
* @author NHN (developers@xpressengine.com)
* @package /classes/xml
* @version 0.1
*/
class Xml_Node_
{
/** In PHP5 this will silence E_STRICT warnings
@ -13,33 +18,46 @@
}
}
/**
* @class XmlParser
* @author NHN (developers@xpressengine.com)
* @brief class parsing a given xmlrpc request and creating a data object
* @version 0.1
*
* @remarks {
* This class may drops unsupported xml lanuage attributes when multiple language attributes are given.
* For example, if 'xml:lang='ko, en, ch, jp..' is given in a xml file, only ko will be left ignoring all other language
* attributes when kor is only supported language. It seems to work fine now but we did not scrutinze any potential side effects,
* }
**/
/**
* XmlParser class
* Class parsing a given xmlrpc request and creating a data object
* @remarks <pre>{
* This class may drops unsupported xml lanuage attributes when multiple language attributes are given.
* For example, if 'xml:lang='ko, en, ch, jp..' is given in a xml file, only ko will be left ignoring all other language
* attributes when kor is only supported language. It seems to work fine now but we did not scrutinze any potential side effects,
* }</pre>
*
* @author NHN (developers@xpressengine.com)
* @package /classes/xml
* @version 0.1
*/
class XmlParser {
/**
* Xml parser
* @var resource
*/
var $oParser = NULL;
/**
* Input xml
* @var string
*/
var $input = NULL;
/**
* Output object in array
* @var array
*/
var $output = array();
/**
* The default language type
* @var string
*/
var $lang = "en";
var $oParser = NULL; ///< xml parser
var $input = NULL; ///< input xml
var $output = array(); ///< output object
var $lang = "en"; // /< The default language type
/**
* @brief load a xml file specified by a filename and parse it to Return the resultant data object
* @param[in] $filename a file path of file
* @return Returns a data object containing data extracted from a xml file or NULL if a specified file does not exist
**/
/**
* Load a xml file specified by a filename and parse it to Return the resultant data object
* @param string $filename a file path of file
* @return array Returns a data object containing data extracted from a xml file or NULL if a specified file does not exist
*/
function loadXmlFile($filename) {
if(!file_exists($filename)) return;
$buff = FileHandler::readFile($filename);
@ -48,11 +66,13 @@
return $oXmlParser->parse($buff);
}
/**
* @brief parse xml data to extract values from it and construct data object
* @param[in] a data buffer containing xml data
* @return Returns a resultant data object or NULL in case of error
**/
/**
* Parse xml data to extract values from it and construct data object
* @param string $input a data buffer containing xml data
* @param mixed $arg1 ???
* @param mixed $arg2 ???
* @return array Returns a resultant data object or NULL in case of error
*/
function parse($input = '', $arg1 = NULL, $arg2 = NULL) {
// Save the compile starting time for debugging
if(__DEBUG__==3) $start = getMicroTime();
@ -99,12 +119,13 @@
}
/**
* @brief start element handler.
* @param[in] $parse an instance of parser
* @param[in] $node_name a name of node
* @param[in] $attrs attributes to be set
*/
/**
* Start element handler.
* @param resource $parse an instance of parser
* @param string $node_name a name of node
* @param array $attrs attributes to be set
* @return array
*/
function _tagOpen($parser, $node_name, $attrs) {
$obj = new Xml_Node_();
$obj->node_name = strtolower($node_name);
@ -114,23 +135,24 @@
}
/**
* @brief character data handler
* variable in the last element of this->output
* @param[in] $parse an instance of parser
* @param[in] $body a data to be added
* @remark the first parameter, $parser ought to be remove since it is not used.
*/
/**
* Character data handler
* Variable in the last element of this->output
* @param resource $parse an instance of parser
* @param string $body a data to be added
* @return void
*/
function _tagBody($parser, $body) {
//if(!trim($body)) return;
$this->output[count($this->output)-1]->body .= $body;
}
/**
* @brief end element handler
* @param[in] $parse an instance of parser
* @param[in] $node_name name of xml node
*/
/**
* End element handler
* @param resource $parse an instance of parser
* @param string $node_name name of xml node
* @return void
*/
function _tagClosed($parser, $node_name) {
$node_name = strtolower($node_name);
$cur_obj = array_pop($this->output);
@ -155,10 +177,11 @@
}
}
/**
* @brief method to transfer values in an array to a data object
* @param[in] $arr data array
**/
/**
* Method to transfer values in an array to a data object
* @param array $arr data array
* @return Xml_Node_ object
**/
function _arrToAttrsObj($arr) {
$output = new Xml_Node_();
foreach($arr as $key => $val) {

View file

@ -1,14 +1,4 @@
<?php
/**
* @class NewXmlQueryParser
* @author NHN (developers@xpressengine.com)
* @brief case to parse XE xml query
* @version 0.1
*
* @todo need to support extend query such as subquery, union
* @todo include info about column types for parsing user input
**/
if(!defined('__XE_LOADED_XML_CLASS__')){
define('__XE_LOADED_XML_CLASS__', 1);
@ -44,12 +34,27 @@
require(_XE_PATH_.'classes/xml/xmlquery/queryargument/DefaultValue.class.php');
}
/**
* New XmlQueryParser class
* @author NHN (developers@xpressengine.com)
* @brief case to parse XE xml query
* @version 0.1
*
* @todo need to support extend query such as subquery, union
* @todo include info about column types for parsing user input
*/
class XmlQueryParser extends XmlParser {
/**
* constructor
* @return void
*/
function XmlQueryParser(){
}
/**
* Create XmlQueryParser instance for Singleton
* @return XmlQueryParser object
*/
function &getInstance(){
static $theInstance = null;
if(!isset($theInstance)){
@ -58,6 +63,12 @@
return $theInstance;
}
/**
* 1. Read xml file<br />
* 2. Check the action<br />
* 3. Parsing and write a cache file<br />
* @return QueryParser object
*/
function &parse_xml_query($query_id, $xml_file, $cache_file)
{
// Read xml file
@ -74,11 +85,19 @@
return $parser;
}
/**
* Query XML file parsing
* @return QueryParser object
*/
function parse($query_id = NULL, $xml_file = NULL, $cache_file = NULL)
{
$this->parse_xml_query($query_id, $xml_file, $cache_file);
}
/**
* Return XML file content
* @return array|NULL Returns a resultant data object or NULL in case of error
*/
function getXmlFileContent($xml_file){
$buff = FileHandler::readFile($xml_file);
$xml_obj = parent::parse($buff);

View file

@ -1,13 +1,12 @@
<?php
/**
* @class XmlQueryParser
* @author NHN (developers@xpressengine.com)
* @brief case to parse XE xml query
* @version 0.1
* XmlQueryParser
* Case to parse XE xml query
*
* @author NHN (developers@xpressengine.com)
* @version 0.1
* @todo need to support extend query such as subquery, union
**/
*/
class XmlQueryParser extends XmlParser {
var $default_list = array();
@ -15,13 +14,13 @@
var $filter_list = array();
/**
* @brief parse a xml query file and save the result as a new file specified by cache_file
* @param[in] $query_id name of query
* @param[in] $xml_file file path of a xml query file to be loaded
* @param[in] $cache_file file path of a cache file to store resultant php code after parsing xml query
* @return Nothing is requred.
* @remarks {there should be a way to report an error}
**/
* Parse a xml query file and save the result as a new file specified by cache_file
* {there should be a way to report an error}
* @param string $query_id name of query
* @param string $xml_file file path of a xml query file to be loaded
* @param string $cache_file file path of a cache file to store resultant php code after parsing xml query
* @return void Nothing is requred.
*/
function parse($query_id, $xml_file, $cache_file) {
// query xml 파일을 찾아서 파싱, 결과가 없으면 return
$buff = FileHandler::readFile($xml_file);
@ -260,11 +259,10 @@
}
/**
* @brief transfer given column information to object->columns
* @param[in] column information
* @result Returns $object
* Transfer given column information to object->columns
* @param array $columns column information
* @return object
*/
function _setColumn($columns){
if(!$columns) {
$output->column[] = array("*" => "*");
@ -296,9 +294,9 @@
}
/**
* @brief transfer condition information to $object->conditions
* @param[in] SQL condition information
* @result Returns $output
* Transfer condition information to $object->conditions
* @param object @condition SQL condition information
* @retrun object
*/
function _setConditions($conditions){
// 조건절 정리
@ -339,9 +337,9 @@
}
/**
* @brief transfer condition information to $object->groups
* @param[in] SQL group information
* @result Returns $output
* Transfer condition information to $object->groups
* @param array $group_list SQL group information
* @return object
*/
function _setGroup($group_list){
// group 정리
@ -361,9 +359,9 @@
/**
* @brief transfer pagnation information to $output
* @param[in] $xml_obj xml object containing Navigation information
* @result Returns $output
* Transfer pagnation information to $output
* @param object $xml_obj xml object containing Navigation information
* @return object
*/
function _setNavigation($xml_obj){
$navigation = $xml_obj->query->navigation;
@ -389,10 +387,10 @@
}
/**
* @brief retrieve column information from $output->colums to generate corresponding php code
* @param[in] $column
* @remarks the name of this method is misleading.
* @result Returns string buffer containing php code
* Retrieve column information from $output->colums to generate corresponding php code <br />
* The name of this method is misleading.
* @param array $columns
* @return string buffer containing php code
*/
function _getColumn($columns){
$buff = '';
@ -439,10 +437,10 @@
}
/**
* @brief retrieve condition information from $output->condition to generate corresponding php code
* @param[in] $conditions array containing Query conditions
* @remarks the name of this method is misleading.
* @return Returns string buffer containing php code
* Retrieve condition information from $output->condition to generate corresponding php code
* The name of this method is misleading.
* @param array $conditions array containing Query conditions
* @return string buffer containing php code
*/
function _getConditions($conditions){
$buff = '';
@ -472,21 +470,30 @@
return $buff;
}
/**
* Add argument to $this->args
* @param mixed $args_name argument value
* @return void
*/
function addArguments($args_name)
{
$this->args[] = $args_name;
}
/**
* Get argument from $this->args
* @return mixed
*/
function getArguments()
{
return $this->args;
}
/**
* @brief returns predefined default values correspoding to given parameters
* @param[in] $name
* @param[in] $value
* @return Returns a default value for specified field
* Returns predefined default values correspoding to given parameters
* @param string $name
* @param mixed $value
* @return mixed Returns a default value for specified field
*/
function getDefault($name, $value) {
$db_info = Context::getDBInfo ();

View file

@ -1,9 +1,34 @@
<?php
/**
* DBParser class
* @author NHN (developers@xpressengine.com)
* @package /classes/xml/xmlquery
* @version 0.1
**/
class DBParser {
/**
* Character for escape target value on the left
* @var string
*/
var $escape_char_left;
/**
* Character for escape target value on the right
* @var string
*/
var $escape_char_right;
/**
* Table prefix string
* @var string
*/
var $table_prefix;
/**
* constructor
* @param string $escape_char_left
* @param string $escape_char_right
* @param string $table_prefix
* @return void
*/
function DBParser($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;
@ -11,33 +36,68 @@
$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 colmun 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
* @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);
@ -49,11 +109,21 @@
}
}
/**
* Column name is suitable for use in checking
* @param string $column_name
* @return bool
*/
function isUnqualifiedColumnName($column_name){
if(strpos($column_name,'.')===false && strpos($column_name,'(')===false) return true;
return false;
}
/**
* Column name is suitable for use in checking
* @param string $column_name
* @return bool
*/
function isQualifiedColumnName($column_name){
if(strpos($column_name,'.')!==false && strpos($column_name,'(')===false) return true;
return false;
@ -92,12 +162,19 @@
/*
* 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)){
@ -108,4 +185,4 @@
}
}