Throw ErrorException in WCF::handleError()
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 29 Sep 2015 20:16:50 +0000 (22:16 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 1 Dec 2015 21:15:48 +0000 (22:15 +0100)
wcfsetup/install/files/lib/system/WCF.class.php
wcfsetup/install/files/lib/system/exception/ErrorException.class.php [new file with mode: 0644]

index 863a0e91b03db7c8bef2a2d6d6cbd5a2e7089fe9..93f521cd2c4ed7bc113dc3256c8967bd7775320c 100644 (file)
@@ -11,6 +11,7 @@ use wcf\system\cache\builder\PackageUpdateCacheBuilder;
 use wcf\system\cronjob\CronjobScheduler;
 use wcf\system\event\EventHandler;
 use wcf\system\exception\AJAXException;
+use wcf\system\exception\ErrorException;
 use wcf\system\exception\IPrintableException;
 use wcf\system\exception\NamedUserException;
 use wcf\system\exception\PermissionDeniedException;
@@ -262,25 +263,18 @@ class WCF {
        }
        
        /**
-        * Catches php errors and throws instead a system exception.
+        * Turns PHP errors into an ErrorException.
         * 
         * @param       integer         $errorNo
         * @param       string          $message
         * @param       string          $filename
         * @param       integer         $lineNo
         */
-       public static final function handleError($errorNo, $message, $filename, $lineNo) {
-               if (error_reporting() != 0) {
-                       $type = 'error';
-                       switch ($errorNo) {
-                               case 2: $type = 'warning';
-                                       break;
-                               case 8: $type = 'notice';
-                                       break;
-                       }
-                       
-                       throw new SystemException('PHP '.$type.' in file '.$filename.' ('.$lineNo.'): '.$message, 0);
-               }
+       public static final function handleError($severity, $message, $file, $line) {
+               // this is neccessary for the shut-up operator
+               if (error_reporting() == 0) return;
+               
+               throw new ErrorException($message, 0, $severity, $file, $line);
        }
        
        /**
diff --git a/wcfsetup/install/files/lib/system/exception/ErrorException.class.php b/wcfsetup/install/files/lib/system/exception/ErrorException.class.php
new file mode 100644 (file)
index 0000000..f6f5fdc
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+namespace wcf\system\exception;
+
+/**
+ * This is a custom implementation of the default \ErrorException.
+ * It is used for backwards compatibility reasons. Do not rely on it
+ * inheriting \wcf\system\exception\SystemException.
+ * 
+ * @author     Tim Duesterhus
+ * @copyright  2001-2015 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.exception
+ * @category   Community Framework
+ */
+class ErrorException extends SystemException {
+       /**
+        * @see \ErrorException::$severity
+        */
+       protected $severity;
+       
+       /**
+        * @see \ErrorException::__construct()
+        */
+       public function __construct($message = "", $code = 0, $severity = 1, $filename = __FILE__, $lineno = __LINE__, $previous = null) {
+               parent::__construct($message, $code, "", $previous);
+               
+               $this->severity = $severity;
+       }
+       
+       /**
+        * @see \ErrorException::getSeverity()
+        */
+       public function getSeverity() {
+               return $this->severity;
+       }
+}