XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
BaseObject.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
3 
9 class BaseObject
10 {
15  var $error = 0;
16 
21  var $message = 'success';
22 
27  var $variables = array();
28 
33  var $httpStatusCode = NULL;
34 
42  function __construct($error = 0, $message = 'success')
43  {
44  $this->setError($error);
45  $this->setMessage($message);
46  }
47 
54  function setError($error = 0)
55  {
56  $this->error = $error;
57  }
58 
64  function getError()
65  {
66  return $this->error;
67  }
68 
75  function setHttpStatusCode($code = '200')
76  {
77  $this->httpStatusCode = $code;
78  }
79 
85  function getHttpStatusCode()
86  {
87  return $this->httpStatusCode;
88  }
89 
96  function setMessage($message = 'success', $type = NULL)
97  {
98  if($str = Context::getLang($message))
99  {
100  $this->message = $str;
101  }
102  else
103  {
104  $this->message = $message;
105  }
106 
107  // TODO This method always returns True. We'd better remove it
108  return TRUE;
109  }
110 
116  function getMessage()
117  {
118  return $this->message;
119  }
120 
128  function add($key, $val)
129  {
130  $this->variables[$key] = $val;
131  }
132 
139  function adds($object)
140  {
141  if(is_object($object))
142  {
143  $object = get_object_vars($object);
144  }
145 
146  if(is_array($object))
147  {
148  foreach($object as $key => $val)
149  {
150  $this->variables[$key] = $val;
151  }
152  }
153  }
154 
161  function get($key)
162  {
163  return $this->variables[$key];
164  }
165 
171  function gets()
172  {
173  $args = func_get_args();
174  $output = new stdClass();
175  foreach($args as $arg)
176  {
177  $output->{$arg} = $this->get($arg);
178  }
179  return $output;
180  }
181 
187  function getVariables()
188  {
189  return $this->variables;
190  }
191 
197  function getObjectVars()
198  {
199  $output = new stdClass();
200  foreach($this->variables as $key => $val)
201  {
202  $output->{$key} = $val;
203  }
204  return $output;
205  }
206 
212  function toBool()
213  {
214  // TODO This method is misleading in that it returns true if error is 0, which should be true in boolean representation.
215  return ($this->error == 0);
216  }
217 
223  function toBoolean()
224  {
225  return $this->toBool();
226  }
227 }
228 
229 if(version_compare(PHP_VERSION, '7.2', '<') && !class_exists('Object', false))
230 {
231  class_alias('BaseObject', 'Object');
232 }
233 /* End of file BaseObject.class.php */
234 /* Location: ./classes/object/BaseObject.class.php */
$output
Definition: ko.install.php:193
add($key, $val)
high class of message module
setHttpStatusCode($code= '200')
setError($error=0)
$args
Definition: ko.install.php:185
getLang($code)
__construct($error=0, $message= 'success')
setMessage($message= 'success', $type=NULL)