00001 <?php
00012 class SObject {
00013 private $error = array();
00014 private $warning = array();
00015
00016 private static $staticError = array();
00017 private static $staticWarning = array();
00018
00019 private $ignoreExtra = false;
00020 private static $staticIgnoreExtra = false;
00021
00022 const XML_ERROR_MODE_DEFAULT = 0;
00023 const XML_ERROR_MODE_REDIRECT = 1;
00024
00025 private static $xmlErrors = array();
00026 private static $xmlErrorMode = self::XML_ERROR_MODE_DEFAULT;
00027
00028
00029
00030
00031
00032
00036 public function doc() {
00037 if (get_class($this) != "SObject") {
00038 return "Another class has extended SObject but not provided "
00039 . "its own doc string.";
00040 }
00041 return "SObject is the standard object for all objects in "
00042 . "Shodor web apps to extend. It includes error handling "
00043 . "and provides a default doc string.";
00044 }
00045
00053 public function __construct() {
00054 }
00055
00056
00057
00058
00059
00064 public function getWarning() {
00065 return $this->warning;
00066 }
00067
00072 public function getError() {
00073 return $this->error;
00074 }
00075
00082 public function setError($error) {
00083 array_push($this->error, $error);
00084 SErrorManager::sobj_setError($error, false, $this->ignoreExtra ? 3 : 2);
00085 $this->ignoreExtra = false;
00086 }
00087
00094 public function setUserError($error) {
00095 array_push($this->error, $error);
00096 SErrorManager::sobj_setError($error, true, 2);
00097 }
00098
00105 public function setWarning($warning) {
00106 array_push($this->warning, $warning);
00107 SErrorManager::sobj_setWarning($warning, $this->ignoreExtra ? 3 : 2);
00108 $this->ignoreExtra = false;
00109 }
00110
00116 public function getLastError() {
00117 if(count($this->error) > 0)
00118 return $this->error[count($this->error) - 1];
00119 else
00120 return false;
00121 }
00122
00128 public function getLastWarning() {
00129 if(count($this->warning) > 0)
00130 return $this->warning[count($this->warning) - 1];
00131 else
00132 return false;
00133 }
00134
00140 public function getErrorFrom($obj) {
00141 if ($obj == null){
00142 $this->setPrettyError('getErrorFrom',
00143 'Attempting to get errors from an object that does not exist.');
00144 return false;
00145 }
00146 if ($obj->hasError()) {
00147 $this->setSilentError("from " . get_class($obj) .
00148 "<br /><small>(" . $obj->doc() . ")</small>", $obj->getError());
00149 $this->setSilentError($obj->getError());
00150 }
00151 return true;
00152 }
00153
00159 public function getWarningFrom($obj) {
00160 if ($obj == null){
00161 $this->setPrettyError('getWarningFrom',
00162 'Attempting to get warnings from an object that does not exist.');
00163 return false;
00164 }
00165 if ($obj->hasWarning()) {
00166 $this->setSilentWarning("from " . get_class($obj) . "<br /><small>(" . $obj->doc() . ")</small>");
00167 $this->setSilentWarning($obj->getWarning());
00168 }
00169 return true;
00170 }
00171
00178 private function setSilentError($msg) {
00179
00180 array_push($this->error, $msg);
00181 }
00182
00189 private function setSilentWarning($msg) {
00190 array_push($this->warning, $msg);
00191 }
00192
00198 public function hasError() {
00199 return (count($this->getError()) > 0);
00200 }
00201
00207 public function hasWarning() {
00208 return (count($this->getWarning()) > 0);
00209 }
00210
00215 public function resetError() {
00216 $this->error = array();
00217 }
00218
00223 public function resetWarning() {
00224 $this->warning = array();
00225 }
00226
00234 public function setPrettyError($function, $error) {
00235 $this->ignoreExtra = true;
00236 $this->setError("Attempt to call '" . $function . "' action on "
00237 . get_class($this) . ' object failed: ' . $error);
00238 }
00239
00246 public function setPrettyWarning($function, $warning) {
00247 $this->ignoreExtra = true;
00248 $this->setWarning("While calling '" . $function . "' action on "
00249 . get_class($this) . ': ' . $warning);
00250 }
00251
00252
00253
00254
00255
00261 public static function getStaticError() {
00262 return SObject::$staticError;
00263 }
00264
00271 public static function setStaticError($error) {
00272 array_push(SObject::$staticError, $error);
00273 SErrorManager::sobj_setError($error, false, SObject::$staticIgnoreExtra ? 3 : 2);
00274 SObject::$staticIgnoreExtra = false;
00275 }
00276
00282 public static function getStaticWarning() {
00283 return SObject::$staticWarning;
00284 }
00285
00292 public static function setStaticWarning($warning) {
00293 array_push(SObject::$staticWarning, $warning);
00294 SErrorManager::sobj_setWarning($warning, SObject::$staticIgnoreExtra ? 3 : 2);
00295 SObject::$staticIgnoreExtra = false;
00296 }
00297
00303 public static function hasStaticError() {
00304 return (count(SObject::getStaticError()) > 0);
00305 }
00306
00312 public static function hasStaticWarning() {
00313 return (count(SObject::getStaticWarning()) > 0);
00314 }
00315
00320 public static function resetStaticError(){
00321 SObject::$staticError = array();
00322 }
00323
00328 public static function resetStaticWarning(){
00329 SObject::$staticWarning = array();
00330 }
00331
00339 public static function setStaticPrettyError($function, $error) {
00340 SObject::$staticIgnoreExtra = true;
00341 SObject::setStaticError("Attempt to call '" . $function . "' action failed: '" . $error);
00342 }
00343
00351 public static function setStaticPrettyWarning($function, $warning) {
00352 SObject::$staticIgnoreExtra = true;
00353 SObject::setStaticWarning("While calling '" . $function . "' action failed: '" . $warning);
00354 }
00355
00361 public static function getLastStaticError() {
00362 if(count(SObject::$staticError) > 0)
00363 return SObject::$staticError[count(SObject::$staticError) - 1];
00364 else
00365 return false;
00366 }
00367
00372 public static function getLastStaticWarning() {
00373 if(count(SObject::$staticWarning) > 0)
00374 return SObject::$staticWarning[count(SObject::$staticWarning) - 1];
00375 else
00376 return false;
00377 }
00378
00379
00380
00381
00382
00390
00391
00392
00393
00401
00402
00403
00404
00405
00406
00407
00408
00415 public function setXMLErrorMode($mode) {
00416 $oldMode = self::$xmlErrorMode;
00417 self::$xmlErrorMode = $mode;
00418 return $oldMode;
00419 }
00420
00427 public function getXMLErrors() {
00428 return self::$xmlErrors;
00429 }
00430
00439 public function parseXML($xml) {
00440 self::setStaticWarning('DEPRECATED: usage of SObject->parseXML(); use SXMLHelper::parse() instead');
00441 return SXMLHelper::parse($xml);
00442 }
00443 }
00444
00445 ?>