mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-09 12:02:24 +09:00
Reformat class files based on PHP coding convention
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@9828 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
339b2de797
commit
be6d9a096d
6 changed files with 1085 additions and 1081 deletions
134
classes/cache/CacheApc.class.php
vendored
134
classes/cache/CacheApc.class.php
vendored
|
|
@ -1,72 +1,72 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @class CacheApc
|
* @class CacheApc
|
||||||
* @author NHN (developer@xpressengine.com)
|
* @author NHN (developer@xpressengine.com)
|
||||||
* @brief APC Handler
|
* @brief APC Handler
|
||||||
* @version 0.1
|
* @version 0.1
|
||||||
*
|
**/
|
||||||
**/
|
|
||||||
|
|
||||||
|
class CacheApc extends CacheBase {
|
||||||
|
var $valid_time = 36000;
|
||||||
|
|
||||||
class CacheApc extends CacheBase {
|
function getInstance($opt=null){
|
||||||
var $valid_time = 36000;
|
if(!$GLOBALS['__CacheApc__']) {
|
||||||
|
$GLOBALS['__CacheApc__'] = new CacheApc();
|
||||||
function getInstance($opt=null){
|
|
||||||
if(!$GLOBALS['__CacheApc__']) {
|
|
||||||
$GLOBALS['__CacheApc__'] = new CacheApc();
|
|
||||||
}
|
|
||||||
return $GLOBALS['__CacheApc__'];
|
|
||||||
}
|
|
||||||
|
|
||||||
function CacheApc(){
|
|
||||||
}
|
|
||||||
|
|
||||||
function isSupport(){
|
|
||||||
return function_exists('apc_add');
|
|
||||||
}
|
|
||||||
|
|
||||||
function put($key, $buff, $valid_time = 0){
|
|
||||||
if($valid_time == 0) $valid_time = $this->valid_time;
|
|
||||||
return apc_store(md5(_XE_PATH_.$key), array(time(), $buff), $valid_time);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isValid($key, $modified_time = 0) {
|
|
||||||
$_key = md5(_XE_PATH_.$key);
|
|
||||||
$obj = apc_fetch($_key, $success);
|
|
||||||
if(!$success || !is_array($obj)) return false;
|
|
||||||
unset($obj[1]);
|
|
||||||
|
|
||||||
if($modified_time > 0 && $modified_time > $obj[0]) {
|
|
||||||
$this->_delete($_key);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function get($key, $modified_time = 0) {
|
|
||||||
$_key = md5(_XE_PATH_.$key);
|
|
||||||
$obj = apc_fetch($_key, $success);
|
|
||||||
if(!$success || !is_array($obj)) return false;
|
|
||||||
|
|
||||||
if($modified_time > 0 && $modified_time > $obj[0]) {
|
|
||||||
$this->_delete($_key);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $obj[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
function _delete($_key) {
|
|
||||||
$this->put($_key,null,1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function delete($key) {
|
|
||||||
$this->_delete($key);
|
|
||||||
}
|
|
||||||
|
|
||||||
function truncate() {
|
|
||||||
return apc_clear_cache('user');
|
|
||||||
}
|
}
|
||||||
|
return $GLOBALS['__CacheApc__'];
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
function CacheApc(){
|
||||||
|
}
|
||||||
|
|
||||||
|
function isSupport(){
|
||||||
|
return function_exists('apc_add');
|
||||||
|
}
|
||||||
|
|
||||||
|
function put($key, $buff, $valid_time = 0){
|
||||||
|
if($valid_time == 0) $valid_time = $this->valid_time;
|
||||||
|
return apc_store(md5(_XE_PATH_.$key), array(time(), $buff), $valid_time);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isValid($key, $modified_time = 0) {
|
||||||
|
$_key = md5(_XE_PATH_.$key);
|
||||||
|
$obj = apc_fetch($_key, $success);
|
||||||
|
if(!$success || !is_array($obj)) return false;
|
||||||
|
unset($obj[1]);
|
||||||
|
|
||||||
|
if($modified_time > 0 && $modified_time > $obj[0]) {
|
||||||
|
$this->_delete($_key);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get($key, $modified_time = 0) {
|
||||||
|
$_key = md5(_XE_PATH_.$key);
|
||||||
|
$obj = apc_fetch($_key, $success);
|
||||||
|
if(!$success || !is_array($obj)) return false;
|
||||||
|
|
||||||
|
if($modified_time > 0 && $modified_time > $obj[0]) {
|
||||||
|
$this->_delete($_key);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $obj[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
function _delete($_key) {
|
||||||
|
$this->put($_key,null,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function delete($key) {
|
||||||
|
$this->_delete($key);
|
||||||
|
}
|
||||||
|
|
||||||
|
function truncate() {
|
||||||
|
return apc_clear_cache('user');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* End of file CacheApc.class.php */
|
||||||
|
/* Location: ./classes/cache/CacheApc.class.php */
|
||||||
|
|
|
||||||
18
classes/cache/CacheHandler.class.php
vendored
18
classes/cache/CacheHandler.class.php
vendored
|
|
@ -4,21 +4,20 @@
|
||||||
* @author NHN (developer@xpressengine.com)
|
* @author NHN (developer@xpressengine.com)
|
||||||
* @brief Cache Handler
|
* @brief Cache Handler
|
||||||
* @version 0.1
|
* @version 0.1
|
||||||
*
|
|
||||||
**/
|
**/
|
||||||
|
|
||||||
class CacheHandler extends Handler {
|
class CacheHandler extends Handler {
|
||||||
var $handler = null;
|
var $handler = null;
|
||||||
var $keyGroupVersions = null;
|
var $keyGroupVersions = null;
|
||||||
|
|
||||||
function &getInstance($target='object') {
|
function &getInstance($target = 'object') {
|
||||||
if(!$GLOBALS['__XE_CACHE_HANDLER__'][$target]) {
|
if(!$GLOBALS['__XE_CACHE_HANDLER__'][$target]) {
|
||||||
$GLOBALS['__XE_CACHE_HANDLER__'][$target] = new CacheHandler($target);
|
$GLOBALS['__XE_CACHE_HANDLER__'][$target] = new CacheHandler($target);
|
||||||
}
|
}
|
||||||
return $GLOBALS['__XE_CACHE_HANDLER__'][$target];
|
return $GLOBALS['__XE_CACHE_HANDLER__'][$target];
|
||||||
}
|
}
|
||||||
|
|
||||||
function CacheHandler($target, $info=null) {
|
function CacheHandler($target, $info = null) {
|
||||||
if(!$info) $info = Context::getDBInfo();
|
if(!$info) $info = Context::getDBInfo();
|
||||||
if($info){
|
if($info){
|
||||||
if($target == 'object'){
|
if($target == 'object'){
|
||||||
|
|
@ -39,11 +38,11 @@ class CacheHandler extends Handler {
|
||||||
$class = 'Cache' . ucfirst($type);
|
$class = 'Cache' . ucfirst($type);
|
||||||
include_once sprintf('%sclasses/cache/%s.class.php', _XE_PATH_, $class);
|
include_once sprintf('%sclasses/cache/%s.class.php', _XE_PATH_, $class);
|
||||||
$this->handler = call_user_func(array($class,'getInstance'), $url);
|
$this->handler = call_user_func(array($class,'getInstance'), $url);
|
||||||
$this->keyGroupVersions = $this->handler->get('key_group_versions', 0);
|
$this->keyGroupVersions = $this->handler->get('key_group_versions', 0);
|
||||||
if(!$this->keyGroupVersions) {
|
if(!$this->keyGroupVersions) {
|
||||||
$this->keyGroupVersions = array();
|
$this->keyGroupVersions = array();
|
||||||
$this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
|
$this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -127,4 +126,5 @@ class CacheBase{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* End of file : CacheHandler.class.php */
|
/* End of file CacheHandler.class.php */
|
||||||
|
/* Location: ./classes/cache/CacheHandler.class.php */
|
||||||
|
|
|
||||||
178
classes/cache/CacheMemcache.class.php
vendored
178
classes/cache/CacheMemcache.class.php
vendored
|
|
@ -1,97 +1,97 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @class CacheMemcache
|
* @class CacheMemcache
|
||||||
* @author NHN (developer@xpressengine.com)
|
* @author NHN (developer@xpressengine.com)
|
||||||
* @brief Memcache Handler
|
* @brief Memcache Handler
|
||||||
* @version 0.1
|
* @version 0.1
|
||||||
*
|
**/
|
||||||
**/
|
|
||||||
|
|
||||||
class CacheMemcache extends CacheBase {
|
class CacheMemcache extends CacheBase {
|
||||||
|
var $valid_time = 36000;
|
||||||
|
var $Memcache;
|
||||||
|
|
||||||
var $valid_time = 36000;
|
function getInstance($url){
|
||||||
var $Memcache;
|
if(!$GLOBALS['__CacheMemcache__']) {
|
||||||
|
$GLOBALS['__CacheMemcache__'] = new CacheMemcache($url);
|
||||||
function getInstance($url){
|
|
||||||
if(!$GLOBALS['__CacheMemcache__']) {
|
|
||||||
$GLOBALS['__CacheMemcache__'] = new CacheMemcache($url);
|
|
||||||
}
|
|
||||||
return $GLOBALS['__CacheMemcache__'];
|
|
||||||
}
|
}
|
||||||
|
return $GLOBALS['__CacheMemcache__'];
|
||||||
|
}
|
||||||
|
|
||||||
function CacheMemcache($url){
|
function CacheMemcache($url){
|
||||||
//$config['url'] = array('memcache://localhost:11211');
|
//$config['url'] = array('memcache://localhost:11211');
|
||||||
$config['url'] = is_array($url)?$url:array($url);
|
$config['url'] = is_array($url)?$url:array($url);
|
||||||
$this->Memcache = new Memcache;
|
$this->Memcache = new Memcache;
|
||||||
|
|
||||||
foreach($config['url'] as $url) {
|
foreach($config['url'] as $url) {
|
||||||
$info = parse_url($url);
|
$info = parse_url($url);
|
||||||
$this->Memcache->addServer($info['host'], $info['port']);
|
$this->Memcache->addServer($info['host'], $info['port']);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function isSupport(){
|
|
||||||
if($GLOBALS['XE_MEMCACHE_SUPPORT']) return true;
|
|
||||||
if($this->Memcache->set('xe', 'xe', MEMCACHE_COMPRESSED, 1)) {
|
|
||||||
$GLOBALS['XE_MEMCACHE_SUPPORT'] = true;
|
|
||||||
} else {
|
|
||||||
$GLOBALS['XE_MEMCACHE_SUPPORT'] = false;
|
|
||||||
}
|
|
||||||
return $GLOBALS['XE_MEMCACHE_SUPPORT'];
|
|
||||||
}
|
|
||||||
|
|
||||||
function getKey($key){
|
|
||||||
return md5(_XE_PATH_.$key);
|
|
||||||
}
|
|
||||||
|
|
||||||
function put($key, $buff, $valid_time = 0){
|
|
||||||
if($valid_time == 0) $valid_time = $this->valid_time;
|
|
||||||
|
|
||||||
return $this->Memcache->set($this->getKey($key), array(time(), $buff), MEMCACHE_COMPRESSED, $valid_time);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isValid($key, $modified_time = 0) {
|
|
||||||
$_key = $this->getKey($key);
|
|
||||||
|
|
||||||
$obj = $this->Memcache->get($_key);
|
|
||||||
if(!$obj || !is_array($obj)) return false;
|
|
||||||
unset($obj[1]);
|
|
||||||
|
|
||||||
if($modified_time > 0 && $modified_time > $obj[0]) {
|
|
||||||
$this->_delete($_key);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function get($key, $modified_time = 0) {
|
|
||||||
$_key = $this->getKey($key);
|
|
||||||
$obj = $this->Memcache->get($_key);
|
|
||||||
if(!$obj || !is_array($obj)) return false;
|
|
||||||
|
|
||||||
if($modified_time > 0 && $modified_time > $obj[0]) {
|
|
||||||
$this->_delete($_key);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($obj[0]);
|
|
||||||
|
|
||||||
return $obj[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
function delete($key) {
|
|
||||||
$_key = $this->getKey($key);
|
|
||||||
$this->_delete($_key);
|
|
||||||
}
|
|
||||||
|
|
||||||
function _delete($_key) {
|
|
||||||
$this->Memcache->delete($_key);
|
|
||||||
}
|
|
||||||
|
|
||||||
function truncate() {
|
|
||||||
// not support memcached
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
function isSupport(){
|
||||||
|
if($GLOBALS['XE_MEMCACHE_SUPPORT']) return true;
|
||||||
|
if($this->Memcache->set('xe', 'xe', MEMCACHE_COMPRESSED, 1)) {
|
||||||
|
$GLOBALS['XE_MEMCACHE_SUPPORT'] = true;
|
||||||
|
} else {
|
||||||
|
$GLOBALS['XE_MEMCACHE_SUPPORT'] = false;
|
||||||
|
}
|
||||||
|
return $GLOBALS['XE_MEMCACHE_SUPPORT'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getKey($key){
|
||||||
|
return md5(_XE_PATH_.$key);
|
||||||
|
}
|
||||||
|
|
||||||
|
function put($key, $buff, $valid_time = 0){
|
||||||
|
if($valid_time == 0) $valid_time = $this->valid_time;
|
||||||
|
|
||||||
|
return $this->Memcache->set($this->getKey($key), array(time(), $buff), MEMCACHE_COMPRESSED, $valid_time);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isValid($key, $modified_time = 0) {
|
||||||
|
$_key = $this->getKey($key);
|
||||||
|
|
||||||
|
$obj = $this->Memcache->get($_key);
|
||||||
|
if(!$obj || !is_array($obj)) return false;
|
||||||
|
unset($obj[1]);
|
||||||
|
|
||||||
|
if($modified_time > 0 && $modified_time > $obj[0]) {
|
||||||
|
$this->_delete($_key);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get($key, $modified_time = 0) {
|
||||||
|
$_key = $this->getKey($key);
|
||||||
|
$obj = $this->Memcache->get($_key);
|
||||||
|
if(!$obj || !is_array($obj)) return false;
|
||||||
|
|
||||||
|
if($modified_time > 0 && $modified_time > $obj[0]) {
|
||||||
|
$this->_delete($_key);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($obj[0]);
|
||||||
|
|
||||||
|
return $obj[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
function delete($key) {
|
||||||
|
$_key = $this->getKey($key);
|
||||||
|
$this->_delete($_key);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _delete($_key) {
|
||||||
|
$this->Memcache->delete($_key);
|
||||||
|
}
|
||||||
|
|
||||||
|
function truncate() {
|
||||||
|
// not supported on memcached
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* End of file CacheMemcache.class.php */
|
||||||
|
/* Location: ./classes/cache/CacheMemcache.class.php */
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,128 +1,129 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @class FileObject
|
* @class FileObject
|
||||||
* @author NHN (developers@xpressengine.com)
|
* @author NHN (developers@xpressengine.com)
|
||||||
* @brief file abstraction class
|
* @brief file abstraction class
|
||||||
**/
|
**/
|
||||||
|
|
||||||
class FileObject extends Object
|
class FileObject extends Object
|
||||||
{
|
{
|
||||||
var $fp = null; ///< file descriptor
|
var $fp = null; ///< file descriptor
|
||||||
var $path = null; ///< file path
|
var $path = null; ///< file path
|
||||||
var $mode = "r"; ///< file open mode
|
var $mode = "r"; ///< file open mode
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief constructor
|
* @brief constructor
|
||||||
* @param[in] $path path of target file
|
* @param[in] $path path of target file
|
||||||
* @param[in] $mode file open mode
|
* @param[in] $mode file open mode
|
||||||
* @return file object
|
* @return file object
|
||||||
**/
|
**/
|
||||||
function FileObject($path, $mode)
|
function FileObject($path, $mode)
|
||||||
{
|
{
|
||||||
if($path != null) $this->Open($path, $mode);
|
if($path != null) $this->Open($path, $mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief append target file's content to current file
|
* @brief append target file's content to current file
|
||||||
* @param[in] $file_name path of target file
|
* @param[in] $file_name path of target file
|
||||||
* @return none
|
* @return none
|
||||||
**/
|
**/
|
||||||
function append($file_name)
|
function append($file_name)
|
||||||
{
|
{
|
||||||
$target = new FileObject($file_name, "r");
|
$target = new FileObject($file_name, "r");
|
||||||
while(!$target->feof())
|
while(!$target->feof())
|
||||||
{
|
{
|
||||||
$readstr = $target->read();
|
$readstr = $target->read();
|
||||||
$this->write($readstr);
|
$this->write($readstr);
|
||||||
}
|
}
|
||||||
$target->close();
|
$target->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief check current file meets eof
|
* @brief check current file meets eof
|
||||||
* @return true: if eof. false: otherwise
|
* @return true: if eof. false: otherwise
|
||||||
**/
|
**/
|
||||||
function feof()
|
function feof()
|
||||||
{
|
{
|
||||||
return feof($this->fp);
|
return feof($this->fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief read from current file
|
* @brief read from current file
|
||||||
* @param[in] $size size to read
|
* @param[in] $size size to read
|
||||||
* @return read bytes
|
* @return read bytes
|
||||||
**/
|
**/
|
||||||
function read($size = 1024)
|
function read($size = 1024)
|
||||||
{
|
{
|
||||||
return fread($this->fp, $size);
|
return fread($this->fp, $size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief write string to current file
|
* @brief write string to current file
|
||||||
* @param[in] $str string to write
|
* @param[in] $str string to write
|
||||||
* @return written bytes. if failed, it returns false
|
* @return written bytes. if failed, it returns false
|
||||||
**/
|
**/
|
||||||
function write($str)
|
function write($str)
|
||||||
{
|
{
|
||||||
$len = strlen($str);
|
$len = strlen($str);
|
||||||
if(!$str || $len <= 0) return false;
|
if(!$str || $len <= 0) return false;
|
||||||
if(!$this->fp) return false;
|
if(!$this->fp) return false;
|
||||||
$written = fwrite($this->fp, $str);
|
$written = fwrite($this->fp, $str);
|
||||||
return $written;
|
return $written;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief open a file
|
* @brief open a file
|
||||||
* @param[in] $path path of target file
|
* @param[in] $path path of target file
|
||||||
* @param[in] $mode file open mode
|
* @param[in] $mode file open mode
|
||||||
* @remarks if file is opened, close it and open the new path
|
* @remarks if file is opened, close it and open the new path
|
||||||
* @return true if succeed, false otherwise.
|
* @return true if succeed, false otherwise.
|
||||||
*/
|
*/
|
||||||
function open($path, $mode)
|
function open($path, $mode)
|
||||||
{
|
{
|
||||||
if($this->fp != null)
|
if($this->fp != null)
|
||||||
{
|
{
|
||||||
$this->close();
|
$this->close();
|
||||||
}
|
}
|
||||||
$this->fp = fopen($path, $mode);
|
$this->fp = fopen($path, $mode);
|
||||||
if(! is_resource($this->fp) )
|
if(! is_resource($this->fp) )
|
||||||
{
|
{
|
||||||
$this->fp = null;
|
$this->fp = null;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->path = $path;
|
$this->path = $path;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief return current file's path
|
* @brief return current file's path
|
||||||
* @return file path
|
* @return file path
|
||||||
**/
|
**/
|
||||||
function getPath()
|
function getPath()
|
||||||
{
|
{
|
||||||
if($this->fp != null)
|
if($this->fp != null)
|
||||||
{
|
{
|
||||||
return $this->path;
|
return $this->path;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief close file
|
* @brief close file
|
||||||
* @return none
|
* @return none
|
||||||
**/
|
**/
|
||||||
function close()
|
function close()
|
||||||
{
|
{
|
||||||
if($this->fp != null)
|
if($this->fp != null)
|
||||||
{
|
{
|
||||||
fclose($this->fp);
|
fclose($this->fp);
|
||||||
$this->fp = null;
|
$this->fp = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
/* End of file FileObject.class.php */
|
||||||
?>
|
/* Location: ./classes/file/FileObject.class.php */
|
||||||
|
|
|
||||||
|
|
@ -1,148 +1,149 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @class Object
|
* @class Object
|
||||||
* @author NHN (developers@xpressengine.com)
|
* @author NHN (developers@xpressengine.com)
|
||||||
* @brief Base class design to pass the Object instance between XE Modules
|
* @brief Base class design to pass the Object instance between XE Modules
|
||||||
*
|
*
|
||||||
* @remark 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
|
||||||
**/
|
**/
|
||||||
|
|
||||||
class Object {
|
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 $error = 0; // / "Error code (if 0, it is not an error)
|
var $variables = array(); // /< an additional variable
|
||||||
var $message = 'success'; // / "Error message (if success, it is not an error)
|
var $httpStatusCode = NULL; ///< http status code.
|
||||||
|
|
||||||
var $variables = array(); // /< an additional variable
|
/**
|
||||||
var $httpStatusCode = NULL; ///< http status code.
|
* @brief constructor
|
||||||
|
**/
|
||||||
|
function Object($error = 0, $message = 'success') {
|
||||||
|
$this->setError($error);
|
||||||
|
$this->setMessage($message);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief constructor
|
* @brief Setter to set error code
|
||||||
**/
|
* @param[in] $error error code
|
||||||
function Object($error = 0, $message = 'success') {
|
**/
|
||||||
$this->setError($error);
|
function setError($error = 0) {
|
||||||
$this->setMessage($message);
|
$this->error = $error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Setter to set error code
|
* @brief Getter to retrieve error code
|
||||||
* @param[in] $error error code
|
**/
|
||||||
**/
|
function getError() {
|
||||||
function setError($error = 0) {
|
return $this->error;
|
||||||
$this->error = $error;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
function setHttpStatusCode($code = '200')
|
||||||
* @brief Getter to retrieve error code
|
{
|
||||||
**/
|
$this->httpStatusCode = $code;
|
||||||
function getError() {
|
}
|
||||||
return $this->error;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setHttpStatusCode($code = '200')
|
function getHttpStatusCode()
|
||||||
{
|
{
|
||||||
$this->httpStatusCode = $code;
|
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
|
||||||
|
**/
|
||||||
|
function setMessage($message = 'success') {
|
||||||
|
if(Context::getLang($message)) $message = Context::getLang($message);
|
||||||
|
$this->message = $message;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief getter to retrieve an error 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
|
||||||
|
**/
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getHttpStatusCode()
|
/**
|
||||||
{
|
* @brief method to retrieve a corresponding value to a given key
|
||||||
return $this->httpStatusCode;
|
**/
|
||||||
|
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
|
||||||
|
**/
|
||||||
|
function gets() {
|
||||||
|
$num_args = func_num_args();
|
||||||
|
$args_list = func_get_args();
|
||||||
|
for($i=0;$i<$num_args;$i++) {
|
||||||
|
$key = $args_list[$i];
|
||||||
|
$output->{$key} = $this->get($key);
|
||||||
}
|
}
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Setter to set set the error message
|
* @brief method to retrieve an array of key/value pairs
|
||||||
* @param[in] $message a messge string
|
* @return Return a list of key/value pairs
|
||||||
* @return return True
|
**/
|
||||||
* @remark this method always returns True. We'd better remove it
|
function getVariables() {
|
||||||
**/
|
return $this->variables;
|
||||||
function setMessage($message = 'success') {
|
}
|
||||||
if(Context::getLang($message)) $message = Context::getLang($message);
|
|
||||||
$this->message = $message;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief getter to retrieve an error message
|
* @brief method to retrieve an object of key/value pairs
|
||||||
**/
|
* @return Return an object of key/value pairs
|
||||||
function getMessage() {
|
**/
|
||||||
return $this->message;
|
function getObjectVars() {
|
||||||
}
|
foreach($this->variables as $key => $val) $output->{$key} = $val;
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief setter to set a key/value pair as an additional variable
|
* @brief method to return either true or false depnding on the value in a 'error' variable
|
||||||
* @param[in] $key a variable name
|
* @remark this method is misleading in that it returns true if error is 0, which should be true in
|
||||||
* @param[in] $val a value for the variable
|
* boolean representation.
|
||||||
**/
|
**/
|
||||||
function add($key, $val) {
|
function toBool() {
|
||||||
$this->variables[$key] = $val;
|
return $this->error==0?true:false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief method to retrieve a corresponding value to a given key
|
|
||||||
**/
|
|
||||||
function get($key) {
|
|
||||||
return $this->variables[$key];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief method to retrieve an object containing a key/value paris
|
* @brief method to return either true or false depnding on the value in a 'error' variable
|
||||||
* @return Returns an object containing key/value pairs
|
**/
|
||||||
**/
|
function toBoolean() {
|
||||||
function gets() {
|
return $this->toBool();
|
||||||
$num_args = func_num_args();
|
}
|
||||||
$args_list = func_get_args();
|
}
|
||||||
for($i=0;$i<$num_args;$i++) {
|
|
||||||
$key = $args_list[$i];
|
|
||||||
$output->{$key} = $this->get($key);
|
|
||||||
}
|
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/* End of file Object.class.php */
|
||||||
* @brief method to retrieve an array of key/value pairs
|
/* Location: ./classes/object/Object.class.php */
|
||||||
* @return Return a list of key/value pairs
|
|
||||||
**/
|
|
||||||
function getVariables() {
|
|
||||||
return $this->variables;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief method to retrieve an object of key/value pairs
|
|
||||||
* @return Return an object of key/value pairs
|
|
||||||
**/
|
|
||||||
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.
|
|
||||||
**/
|
|
||||||
function toBool() {
|
|
||||||
return $this->error==0?true:false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief method to return either true or false depnding on the value in a 'error' variable
|
|
||||||
**/
|
|
||||||
function toBoolean() {
|
|
||||||
return $this->toBool();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue