Ver código fonte

changed error_handler for organizr class to setAPIErrorResponse
added function printWarningsAndErrors for dev purposes
changed the api response of warning and errors to admin and co-admin only

CauseFX 4 anos atrás
pai
commit
3a141f7482
1 arquivos alterados com 43 adições e 7 exclusões
  1. 43 7
      api/classes/organizr.class.php

+ 43 - 7
api/classes/organizr.class.php

@@ -98,7 +98,7 @@ class Organizr
 	public function __construct($updating = false)
 	{
 		// Set custom Error handler
-		set_error_handler([$this, 'setErrorResponse']);
+		set_error_handler([$this, 'setAPIErrorResponse']);
 		// Next Check PHP Version
 		$this->checkPHP();
 		// Check Disk Space
@@ -750,14 +750,50 @@ class Organizr
 		}
 	}
 
+	public function printWarningsAndErrors()
+	{
+		if (isset($GLOBALS['api']['response']['exceptions'])) {
+			$this->prettyPrint($GLOBALS['api']['response']['exceptions'], true);
+		} else {
+			$this->prettyPrint('No Errors');
+		}
+	}
+
 	public function setAPIErrorResponse($number, $message, $file, $line)
 	{
-		$GLOBALS['api']['response']['errors'][] = [
-			'error' => $number,
-			'message' => $message,
-			'file' => $file,
-			'line' => $line
-		];
+		switch ($number) {
+			case E_USER_ERROR:
+			case E_ERROR:
+			case E_CORE_ERROR:
+			case E_COMPILE_ERROR:
+			case E_RECOVERABLE_ERROR:
+				$type = 'errors';
+				break;
+			case E_USER_WARNING:
+			case E_WARNING:
+			case E_CORE_WARNING:
+			case E_COMPILE_WARNING:
+				$type = 'warnings';
+				break;
+			case E_USER_NOTICE:
+			case E_NOTICE:
+			case E_PARSE:
+			case E_DEPRECATED:
+			case E_USER_DEPRECATED:
+				$type = 'notice';
+				break;
+			default:
+				$type = 'other';
+				break;
+		}
+		if ($this->qualifyRequest(1)) {
+			$GLOBALS['api']['response']['exceptions'][$type][] = [
+				'error' => $number,
+				'message' => $message,
+				'file' => $file,
+				'line' => $line
+			];
+		}
 		$this->handleError($number, $message, $file, $line);
 	}