Improved implementation of objectID handling
authorAlexander Ebert <ebert@woltlab.com>
Wed, 29 Jun 2016 14:43:23 +0000 (16:43 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 29 Jun 2016 14:43:23 +0000 (16:43 +0200)
wcfsetup/install/files/lib/system/html/IHtmlProcessor.class.php
wcfsetup/install/files/lib/system/html/input/HtmlInputProcessor.class.php
wcfsetup/install/files/lib/system/html/output/HtmlOutputProcessor.class.php

index 7233cc082fc01b93b8610c53872568b8b01ad482..577ef3080461f658b838d86ecffe54d72558aeaa 100644 (file)
@@ -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.
         * 
index be243403e27da2238e92c81d4d7ae7c62ef2d10a..0ab678ae1bca99c4bfc6aea833a7fd1b4eb79f27 100644 (file)
@@ -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);
index b0daa4b875784a52c5f4d45aa42c3296298aaef0..4e0584929872586cc384286c9f1609742f376e4c 100644 (file)
@@ -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.
         *