* @return $xmlCompacting Wether XML compacting is enabled or disabled
*/
function isXmlCompactingEnabled ();
+
+ /**
+ * Removes all comments, tabs and new-line charcters to compact the content
+ *
+ * @param $content The uncompacted content
+ * @return $content The compacted content
+ */
+ function compactContent ($content);
}
// [EOF]
// Call the inner class' method
return $this->getTemplateInstance()->isXmlCompactingEnabled();
}
+
+ /**
+ * Handles the start element of an XML resource
+ *
+ * @param $resource XML parser resource (currently ignored)
+ * @param $element The element we shall handle
+ * @param $attributes All attributes
+ * @return void
+ * @throws InvalidXmlNodeException If an unknown/invalid XML node name was found
+ */
+ public function startElement ($resource, $element, array $attributes) {
+ // Call the inner class' method
+ $this->getTemplateInstance()->startElement($resource, $element, $attributes);
+ }
+
+ /**
+ * Ends the main or sub node by sending out the gathered data
+ *
+ * @param $resource An XML resource pointer (currently ignored)
+ * @param $nodeName Name of the node we want to finish
+ * @return void
+ * @throws XmlNodeMismatchException If current main node mismatches the closing one
+ */
+ public function endElement ($resource, $nodeName) {
+ // Call the inner class' method
+ $this->getTemplateInstance()->endElement($resource, $nodeName);
+ }
+
+ /**
+ * Currently not used
+ *
+ * @param $resource XML parser resource (currently ignored)
+ * @param $characters Characters to handle
+ * @return void
+ * @todo Find something useful with this!
+ */
+ public function characterHandler ($resource, $characters) {
+ // Call the inner class' method but trim the characters before
+ $this->getTemplateInstance()->characterHandler($resource, trim($characters));
+ }
+
+ /**
+ * Removes all comments, tabs and new-line charcters to compact the content
+ *
+ * @param $content The uncompacted content
+ * @return $content The compacted content
+ */
+ public function compactContent ($content) {
+ $this->getTemplateInstance()->compactContent($content);
+ }
}
// [EOF]
* @throws XmlCompactorDecoratorException If an XML error was found
*/
public function parseXmlContent ($content) {
+ // Remove all comments for better compacting
+ $content = $this->getParserInstance()->getTemplateInstance()->compactContent($content);
+
// Parse the content
$this->getParserInstance()->parseXmlContent($content);
}
// Was it found?
if ($index !== false) {
// Remove this variable
- $this->varStack->offsetUnset($index);
+ $this->unsetVariableStackOffset($index);
} // END - if
}
+ /**
+ * Unsets the given offset in the variable stack
+ *
+ * @param $index Index to unset
+ * @return void
+ */
+ protected final function unsetVariableStackOffset ($index) {
+ // Is the entry there?
+ if (!isset($this->varStack[$this->currGroup][$index])) {
+ // Abort here, we need fixing!
+ $this->debugInstance();
+ } // END - if
+
+ // Remove it
+ unset($this->varStack[$this->currGroup][$index]);
+ }
+
/**
* Private setter for raw template data
*
} // for ($varMatches ...
}
+
/**
* Compiles all loaded raw templates
*
public final function isXmlCompactingEnabled () {
return $this->xmlCompacting;
}
+
+ /**
+ * Removes all commentd, tabs and new-line characters to compact the content
+ *
+ * @param $content The uncompacted content
+ * @return $content The compacted content
+ */
+ public function compactContent ($content) {
+ // First, remove all tab/new-line/revert characters
+ $content = str_replace("\t", '', str_replace("\n", '', str_replace("\r", '', $content)));
+
+ // Then regex all comments like <!-- //--> away
+ preg_match_all('/<!--[\w\W]*?(\/\/){0,1}-->/', $content, $matches);
+
+ // Do we have entries?
+ if (isset($matches[0][0])) {
+ // Remove all
+ foreach ($matches[0] as $match) {
+ // Remove the match
+ $content = str_replace($match, '', $content);
+ } // END - foreach
+ } // END - if
+
+ // Return compacted content
+ return $content;
+ }
}
// [EOF]