From 8e274dd6b36989dd7b20a3e2b17a5d2cf1db7107 Mon Sep 17 00:00:00 2001
From: diosmosis <benaka@piwik.pro>
Date: Wed, 29 Oct 2014 04:03:36 -0700
Subject: [PATCH] Use interface to determine if an exception contains HTML
 message content.

---
 core/Exceptions/HtmlMessageException.php      | 12 ++---------
 .../HtmlMessageExceptionInterface.php         | 20 +++++++++++++++++++
 core/FrontController.php                      |  5 +++--
 3 files changed, 25 insertions(+), 12 deletions(-)
 create mode 100644 core/Exceptions/HtmlMessageExceptionInterface.php

diff --git a/core/Exceptions/HtmlMessageException.php b/core/Exceptions/HtmlMessageException.php
index 243a0f1726..69f809e1e0 100644
--- a/core/Exceptions/HtmlMessageException.php
+++ b/core/Exceptions/HtmlMessageException.php
@@ -16,15 +16,7 @@ use Exception;
  *
  * @api
  */
-class HtmlMessageException extends Exception
+class HtmlMessageException extends Exception implements HtmlMessageExceptionInterface
 {
-    /**
-     * Returns the exception message.
-     *
-     * @return string
-     */
-    public function getHtmlMessage()
-    {
-        return $this->getMessage();
-    }
+    // empty
 }
\ No newline at end of file
diff --git a/core/Exceptions/HtmlMessageExceptionInterface.php b/core/Exceptions/HtmlMessageExceptionInterface.php
new file mode 100644
index 0000000000..b96c2e0a84
--- /dev/null
+++ b/core/Exceptions/HtmlMessageExceptionInterface.php
@@ -0,0 +1,20 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ */
+namespace Piwik\Exceptions;
+
+/**
+ * Exceptions that implement this interface are assumed to have HTML content
+ * in their messages.
+ *
+ * @api
+ */
+interface HtmlMessageExceptionInterface
+{
+    // empty
+}
\ No newline at end of file
diff --git a/core/FrontController.php b/core/FrontController.php
index 6f101c10ac..e61e37d21d 100644
--- a/core/FrontController.php
+++ b/core/FrontController.php
@@ -13,6 +13,7 @@ use Exception;
 use Piwik\API\Request;
 use Piwik\API\ResponseBuilder;
 use Piwik\Exceptions\HtmlMessageException;
+use Piwik\Exceptions\HtmlMessageExceptionInterface;
 use Piwik\Http\Router;
 use Piwik\Plugin\Controller;
 use Piwik\Plugin\Report;
@@ -613,8 +614,8 @@ class FrontController extends Singleton
     {
         $debugTrace = $ex->getTraceAsString();
 
-        if (method_exists($ex, 'getHtmlMessage')) {
-            $message = $ex->getHtmlMessage();
+        if ($ex instanceof HtmlMessageExceptionInterface) {
+            $message = $ex->getMessage();
         } else {
             $message = Common::sanitizeInputValue($ex->getMessage());
         }
-- 
GitLab