From fa6c14d530a4c00e64d232efd9902fe17322bd93 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 29 Jun 2016 16:43:23 +0200 Subject: [PATCH] Improved implementation of objectID handling --- .../lib/system/html/IHtmlProcessor.class.php | 9 ------- .../html/input/HtmlInputProcessor.class.php | 10 ++++---- .../html/output/HtmlOutputProcessor.class.php | 24 ++++++++++++++----- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/wcfsetup/install/files/lib/system/html/IHtmlProcessor.class.php b/wcfsetup/install/files/lib/system/html/IHtmlProcessor.class.php index 7233cc082f..577ef30804 100644 --- a/wcfsetup/install/files/lib/system/html/IHtmlProcessor.class.php +++ b/wcfsetup/install/files/lib/system/html/IHtmlProcessor.class.php @@ -11,15 +11,6 @@ namespace wcf\system\html; * @since 3.0 */ interface IHtmlProcessor { - /** - * Processes the input html string. - * - * @param string $html html string - * @param string $objectType object type identifier - * @param integer $objectID object id - */ - public function process($html, $objectType, $objectID = 0); - /** * Returns the parsed html. * diff --git a/wcfsetup/install/files/lib/system/html/input/HtmlInputProcessor.class.php b/wcfsetup/install/files/lib/system/html/input/HtmlInputProcessor.class.php index be243403e2..0ab678ae1b 100644 --- a/wcfsetup/install/files/lib/system/html/input/HtmlInputProcessor.class.php +++ b/wcfsetup/install/files/lib/system/html/input/HtmlInputProcessor.class.php @@ -34,12 +34,14 @@ class HtmlInputProcessor extends AbstractHtmlProcessor { protected $htmlInputNodeProcessor; /** - * @inheritDoc + * Processes the input html string. + * + * @param string $html html string + * @param string $objectType object type identifier + * @param integer $objectID object id */ public function process($html, $objectType, $objectID = 0) { - // object id is always `0` during input processing but is set - // before saving embedded objects - $this->setContext($objectType, 0); + $this->setContext($objectType, $objectID); // enforce consistent newlines $html = StringUtil::unifyNewlines($html); diff --git a/wcfsetup/install/files/lib/system/html/output/HtmlOutputProcessor.class.php b/wcfsetup/install/files/lib/system/html/output/HtmlOutputProcessor.class.php index b0daa4b875..4e05849298 100644 --- a/wcfsetup/install/files/lib/system/html/output/HtmlOutputProcessor.class.php +++ b/wcfsetup/install/files/lib/system/html/output/HtmlOutputProcessor.class.php @@ -26,13 +26,13 @@ class HtmlOutputProcessor extends AbstractHtmlProcessor { protected $outputType = 'text/html'; /** - * @inheritDoc + * Processes the input html string. + * + * @param string $html html string + * @param string $objectType object type identifier + * @param integer $objectID object id */ - public function process($html, $objectType, $objectID = 0) { - if ($objectID === 0) { - throw new \UnexpectedValueException('Object id cannot be 0 for output processing.'); - } - + public function process($html, $objectType, $objectID) { $this->setContext($objectType, $objectID); $this->getHtmlOutputNodeProcessor()->setOutputType($this->outputType); @@ -61,6 +61,18 @@ class HtmlOutputProcessor extends AbstractHtmlProcessor { return $this->getHtmlOutputNodeProcessor()->getHtml(); } + /** + * @inheritdoc + * @throws \InvalidArgumentException + */ + public function setContext($objectType, $objectID) { + if (!$objectID) { + throw new \InvalidArgumentException("Output processor requires a valid objectID."); + } + + parent::setContext($objectType, $objectID); + } + /** * Returns the output node processor instance. * -- 2.20.1