merge from 1.5.3 (~r10943)

git-svn-id: http://xe-core.googlecode.com/svn/trunk@10951 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
flyskyko 2012-07-27 02:47:10 +00:00
parent 7aa4798373
commit 54e3a72065
334 changed files with 13011 additions and 5561 deletions

View file

@ -1,105 +1,159 @@
<?php
/**
* @class Object
* @author NHN (developers@xpressengine.com)
* @brief Base class design to pass the Object instance between XE Modules
* Every modules inherits from Object class. It includes error, message, and other variables for communicatin purpose.
*
* @remark Every modules inherits from Object class. It includes error, message, and other variables for communicatin purpose
**/
* @author NHN (developers@xpressengine.com)
*/
class Object {
var $error = 0; // / "Error code (if 0, it is not an error)
var $message = 'success'; // / "Error message (if success, it is not an error)
var $variables = array(); // /< an additional variable
var $httpStatusCode = NULL; ///< http status code.
/**
* @brief constructor
**/
* Error code. If `0`, it is not an error.
* @var int
*/
var $error = 0;
/**
* Error message. If `success`, it is not an error.
* @var string
*/
var $message = 'success';
/**
* An additional variable
* @var array
*/
var $variables = array();
/**
* http status code.
* @var int
*/
var $httpStatusCode = NULL;
/**
* Constructor
*
* @param int $error Error code
* @param string $message Error message
* @return void
*/
function Object($error = 0, $message = 'success') {
$this->setError($error);
$this->setMessage($message);
}
/**
* @brief Setter to set error code
* @param[in] $error error code
**/
* Setter to set error code
*
* @param int $error error code
* @return void
*/
function setError($error = 0) {
$this->error = $error;
}
/**
* @brief Getter to retrieve error code
**/
* Getter to retrieve error code
*
* @return int Returns an error code
*/
function getError() {
return $this->error;
}
/**
* Setter to set HTTP status code
*
* @param int $code HTTP status code. Default value is `200` that means successful
* @return void
*/
function setHttpStatusCode($code = '200')
{
$this->httpStatusCode = $code;
}
/**
* Getter to retrieve HTTP status code
*
* @return int Returns HTTP status code
*/
function getHttpStatusCode()
{
return $this->httpStatusCode;
}
/**
* @brief Setter to set set the error message
* @param[in] $message a messge string
* @return return True
* @remark this method always returns True. We'd better remove it
**/
* Setter to set set the error message
*
* @param string $message Error message
* @return bool Alaways returns true.
*/
function setMessage($message = 'success') {
if(Context::getLang($message)) $message = Context::getLang($message);
$this->message = $message;
// TODO This method always returns True. We'd better remove it
return true;
}
/**
* @brief getter to retrieve an error message
**/
* Getter to retrieve an error message
*
* @return string Returns message
*/
function getMessage() {
return $this->message;
}
/**
* @brief setter to set a key/value pair as an additional variable
* @param[in] $key a variable name
* @param[in] $val a value for the variable
**/
* Setter to set a key/value pair as an additional variable
*
* @param string $key A variable name
* @param mixed $val A value for the variable
* @return void
*/
function add($key, $val) {
$this->variables[$key] = $val;
}
/**
* @brief method to set multiple key/value pairs as an additional variables
* @param[in] $object either object or array containg key/value pairs to be added
**/
function adds($object) {
if(is_object($object)) {
$vars = get_object_vars($object);
foreach($vars as $key => $val) $this->add($key, $val);
} elseif(is_array($object)) {
foreach($object as $key => $val) $this->add($key, $val);
* Method to set multiple key/value pairs as an additional variables
*
* @param Object|array $object Either object or array containg key/value pairs to be added
* @return void
*/
function adds($object)
{
if(is_object($object))
{
$object = get_object_vars($object);
}
if(is_array($object))
{
foreach($object as $key => $val) $this->variables[$key] = $val;
}
}
/**
* @brief method to retrieve a corresponding value to a given key
**/
* Method to retrieve a corresponding value to a given key
*
* @param string $key
* @return string Returns value to a given key
*/
function get($key) {
return $this->variables[$key];
}
/**
* @brief method to retrieve an object containing a key/value paris
* @return Returns an object containing key/value pairs
**/
* Method to retrieve an object containing a key/value paris
*
* @return Object Returns an object containing key/value pairs
*/
function gets() {
$num_args = func_num_args();
$args_list = func_get_args();
@ -111,35 +165,40 @@ class Object {
}
/**
* @brief method to retrieve an array of key/value pairs
* @return Return a list of key/value pairs
**/
* Method to retrieve an array of key/value pairs
*
* @return array
*/
function getVariables() {
return $this->variables;
}
/**
* @brief method to retrieve an object of key/value pairs
* @return Return an object of key/value pairs
**/
* Method to retrieve an object of key/value pairs
*
* @return Object
*/
function getObjectVars() {
foreach($this->variables as $key => $val) $output->{$key} = $val;
return $output;
}
/**
* @brief method to return either true or false depnding on the value in a 'error' variable
* @remark this method is misleading in that it returns true if error is 0, which should be true in
* boolean representation.
**/
* Method to return either true or false depnding on the value in a 'error' variable
*
* @return bool Retruns true : error isn't 0 or false : otherwise.
*/
function toBool() {
// TODO This method is misleading in that it returns true if error is 0, which should be true in boolean representation.
return $this->error==0?true:false;
}
/**
* @brief method to return either true or false depnding on the value in a 'error' variable
**/
* Method to return either true or false depnding on the value in a 'error' variable
*
* @return bool
*/
function toBoolean() {
return $this->toBool();
}