* @param $typePrefix Type prefix
* @param $xmlTemplateType Type of XML template
* @return $templateInstance An instance of TemplateEngine
+ * @throws InvalidArgumentException If a parameter has an invalid value
* @throws BasePathIsEmptyException If the provided $templateBasePath is empty
* @throws InvalidBasePathStringException If $templateBasePath is no string
* @throws BasePathIsNoDirectoryException If $templateBasePath is no
* read-protected
*/
protected function initXmlTemplateEngine (string $typePrefix, string $xmlTemplateType) {
+ // Check on parameter
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-XML-TEMPLATE-ENGINE: typePrefix=%s,xmlTemplateType=%s - CALLED!', $typePrefix, $xmlTemplateType));
+ if (empty($typePrefix)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "typePrefix" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+ } elseif (empty($xmlTemplateType)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "xmlTemplateType" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+ }
+
// Set XML template type and prefix
$this->xmlTemplateType = $xmlTemplateType;
$this->typePrefix = $typePrefix;
}
// Set the base path
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-XML-TEMPLATE-ENGINE: templateBasePath=%s', $templateBasePath));
$this->setTemplateBasePath($templateBasePath);
// Set template extensions
$this->stackerName = $typePrefix . '_' . $xmlTemplateType;
// Init stacker
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-XML-TEMPLATE-ENGINE: this->stackerName=%s', $this->stackerName));
$stackInstance->initStack($this->stackerName);
// Set it
$this->setStackInstance($stackInstance);
// Set it in main nodes
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-XML-TEMPLATE-ENGINE: Adding xmlTemplateType=%s to this->mainNodes ...', $xmlTemplateType));
array_push($this->mainNodes, str_replace('_', '-', $xmlTemplateType));
+
+ // Trace message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-XML-TEMPLATE-ENGINE: CALLED!');
}
/**
*/
public function loadXmlTemplate (string $templateName = '') {
// Is the template name empty?
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-XML-TEMPLATE-ENGINE: templateName=%s - CALLED!', $templateName));
if (empty($templateName)) {
// Set generic template name
$templateName = $this->typePrefix . '_' . $this->xmlTemplateType . '_template_type';
$this->setTemplateType(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($templateName));
// Load the special template
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-XML-TEMPLATE-ENGINE: Invoking this->loadTemplate(%s) ...', $this->xmlTemplateType));
$this->loadTemplate($this->xmlTemplateType);
+
+ // Trace message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-XML-TEMPLATE-ENGINE: CALLED!');
}
/**
*/
public function readXmlData (string $key) {
// Is key parameter valid?
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-XML-TEMPLATE-ENGINE: key=%s - CALLED!', $key));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-XML-TEMPLATE-ENGINE: key=%s - CALLED!', $key));
if (empty($key)) {
// Throw exception
throw new InvalidArgumentException('Parameter key is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
$value = parent::readVariable($key, 'general');
// Is this null?
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-XML-TEMPLATE-ENGINE: value[]=%s', gettype($value)));
if (is_null($value)) {
// Bah, needs fixing.
$this->debugInstance(sprintf('[%s:%d]: key=%s returns NULL', __METHOD__, __LINE__, $key));
}
// Return value
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-XML-TEMPLATE-ENGINE: value=%s - EXIT!', $value));
return $value;
}
* @param $node The XML node we should load a dependency template
* @param $templateDependency A template to load to satisfy dependencies
* @return void
+ * @throws InvalidArgumentException If a parameter has an invalid value
*/
protected function handleTemplateDependency (string $node, string $templateDependency) {
- // Check that the XML node is not empty
- assert(!empty($node));
+ // Check parameter
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-XML-TEMPLATE-ENGINE: node=%s,templateDependency=%s - CALLED!', $node, $templateDependency));
+ if (empty($node)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "node" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+ } elseif (empty($templateDependency)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "templateDependency" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+ }
// Is the template dependency set?
if ((!empty($templateDependency)) && (!isset($this->dependencyContent[$node]))) {
// Save the parsed raw content in our dependency array
$this->dependencyContent[$node] = $templateInstance->getRawTemplateData();
}
+
+ // Trace message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-XML-TEMPLATE-ENGINE: CALLED!');
}
/**
* @param $element The element we shall handle
* @param $attributes All attributes
* @return void
+ * @throws InvalidArgumentException If a parameter has an invalid value
* @throws InvalidXmlNodeException If an unknown/invalid XML node name was found
*/
public final function startElement ($resource, string $element, array $attributes) {
+ // Check parameters
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-XML-TEMPLATE-ENGINE: resource[%s]=%s,element=%s,attributes()=%d - CALLED!', gettype($resource), $resource, $element, count($attributes)));
+ if (!is_resource($resource)) {
+ // Throw IAE
+ throw new InvalidArgumentException(sprintf('Parameter resource has unexpected type %s', gettype($resource)), FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+ } elseif (empty($element)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "element" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+ } elseif (count($attributes) == 0) {
+ // Throw IAE
+ throw new InvalidArgumentException(sprintf('Parameter attributes()=%d is an empty array', count($attributes)), FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+ }
+
// Initial method name which will never be called...
$methodName = $this->initMethodName;
$element = strtolower($element);
// Is the element a main node?
- //* DEBUG: */ echo "START: >".$element."<<br />\n";
if (in_array($element, $this->getMainNodes())) {
// Okay, main node found!
$methodName = 'start' . StringUtils::convertToClassName($element);
}
// Call method
- call_user_func_array(array($this, $methodName), $attributes);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-XML-TEMPLATE-ENGINE: Invoking this->%s(attributes()=%d) ...', $methodName, count($attributes)));
+ call_user_func_array([$this, $methodName], $attributes);
+
+ // Trace message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-XML-TEMPLATE-ENGINE: CALLED!');
}
/**
* @throws XmlNodeMismatchException If current main node mismatches the closing one
*/
public final function finishElement ($resource, string $nodeName) {
+ // Check parameters
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-XML-TEMPLATE-ENGINE: resource[%s]=%s,nodeName=%s - CALLED!', gettype($resource), $resource, $nodeName));
+ if (!is_resource($resource)) {
+ // Throw IAE
+ throw new InvalidArgumentException(sprintf('Parameter resource has unexpected type %s', gettype($resource)), FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+ } elseif (empty($nodeName)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "nodeName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+ }
+
// Make all lower-case
$nodeName = strtolower($nodeName);
// Does this match with current main node?
- //* DEBUG: */ echo "END: >".$nodeName."<<br />\n";
if (($nodeName != $this->getCurrMainNode()) && (in_array($nodeName, $this->getMainNodes()))) {
// Did not match!
- throw new XmlNodeMismatchException (array($this, $nodeName, $this->getCurrMainNode()), XmlParser::EXCEPTION_XML_NODE_MISMATCH);
+ throw new XmlNodeMismatchException ([$this, $nodeName, $this->getCurrMainNode()], XmlParser::EXCEPTION_XML_NODE_MISMATCH);
}
// Construct method name
$methodName = 'finish' . StringUtils::convertToClassName($nodeName);
// Call the corresponding method
- //* DEBUG: */ echo "call: ".$methodName."<br />\n";
- call_user_func_array(array($this, $methodName), array());
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-XML-TEMPLATE-ENGINE: Invoking this->%s() ...', $methodName));
+ call_user_func_array([$this, $methodName], []);
+
+ // Trace message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-XML-TEMPLATE-ENGINE: CALLED!');
}
/**
*/
public function renderXmlContent (string $content = NULL) {
// Is the content set?
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-XML-TEMPLATE-ENGINE: content[%s]()=%d - CALLED!', gettype($content), strlen($content)));
if (is_null($content)) {
// Get current content
$content = $this->getRawTemplateData();
// Check if XML compacting is enabled
if ($this->isXmlCompactingEnabled()) {
// Yes, so get a decorator class for transparent compacting
- $parserInstance = ObjectFactory::createObjectByConfiguredName('deco_compacting_xml_parser_class', array($parserInstance));
+ $parserInstance = ObjectFactory::createObjectByConfiguredName('deco_compacting_xml_parser_class', [$parserInstance]);
}
// Parse the XML document
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-XML-TEMPLATE-ENGINE: Invoking parserInstance->parseXmlContent(content()=%d) ...', strlen($content)));
$parserInstance->parseXmlContent($content);
+
+ // Trace message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-XML-TEMPLATE-ENGINE: CALLED!');
}
/**