<?php
/**
- * An ??? template engine class for XML templates
+ * An AnnouncementAnswer template engine class for XML templates
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class XmlAnnouncementAnswerTemplateEngine extends BaseTemplateEngine implements CompileableTemplate, Registerable {
+class XmlAnnouncementAnswerTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
/**
- * Main nodes in the XML tree
+ * Some XML nodes must be available for later data extraction
*/
- private $mainNodes = array(
- '|||'
- );
-
- /**
- * Sub nodes in the XML tree
- */
- private $subNodes = array(
- );
-
- /**
- * Current main node
- */
- private $curr = array();
+ const ANNOUNCEMENT_DATA_SESSION_ID = 'my-session-id';
+ const ANNOUNCEMENT_DATA_NODE_STATUS = 'my-status';
+ const ANNOUNCEMENT_DATA_EXTERNAL_IP = 'my-external-ip';
+ const ANNOUNCEMENT_DATA_INTERNAL_IP = 'my-internal-ip';
+ const ANNOUNCEMENT_DATA_TCP_PORT = 'my-tcp-port';
+ const ANNOUNCEMENT_DATA_UDP_PORT = 'my-udp-port';
/**
* Protected constructor
protected function __construct () {
// Call parent constructor
parent::__construct(__CLASS__);
+
+ // Init sub-nodes array
+ $this->subNodes = array(
+ // These nodes don't contain any data
+ 'my-data',
+ 'your-data',
+ // Data from *this* node
+ self::ANNOUNCEMENT_DATA_EXTERNAL_IP,
+ self::ANNOUNCEMENT_DATA_INTERNAL_IP,
+ self::ANNOUNCEMENT_DATA_TCP_PORT,
+ self::ANNOUNCEMENT_DATA_UDP_PORT,
+ self::ANNOUNCEMENT_DATA_NODE_STATUS,
+ self::ANNOUNCEMENT_DATA_SESSION_ID,
+ // Data from other node
+ 'your-external-ip',
+ 'your-internal-ip',
+ 'your-session-id',
+ );
}
/**
// Get a new instance
$templateInstance = new XmlAnnouncementAnswerTemplateEngine();
- // Get application instance from registry
- $applicationInstance = Registry::getRegistry()->getInstance('app');
+ // Init instance
+ $templateInstance->initXmlTemplateEngine('node', 'announcement_answer');
- // Determine base path
- $templateBasePath = $templateInstance->getConfigInstance()->getConfigEntry('application_base_path') . $applicationInstance->getRequestInstance()->getRequestElement('app') . '/';
+ // Return the prepared instance
+ return $templateInstance;
+ }
- // Is the base path valid?
- if (empty($templateBasePath)) {
- // Base path is empty
- throw new BasePathIsEmptyException($templateInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
- } elseif (!is_string($templateBasePath)) {
- // Is not a string
- throw new InvalidBasePathStringException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_STRING);
- } elseif (!is_dir($templateBasePath)) {
- // Is not a path
- throw new BasePathIsNoDirectoryException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME);
- } elseif (!is_readable($templateBasePath)) {
- // Is not readable
- throw new BasePathReadProtectedException(array($templateInstance, $templateBasePath), self::EXCEPTION_READ_PROTECED_PATH);
- }
+ /**
+ * 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) {
+ // Trim all spaces away
+ $characters = trim($characters);
- // Set the base path
- $templateInstance->setTemplateBasePath($templateBasePath);
+ // Is this string empty?
+ if (empty($characters)) {
+ // Then skip it silently
+ return false;
+ } // END - if
- // Set template extensions
- $templateInstance->setRawTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('raw_template_extension'));
- $templateInstance->setCodeTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('node_answer_template_extension'));
+ /*
+ * Assign the found characters to variable and use the last entry from
+ * stack as the name.
+ */
+ parent::assignVariable($this->getStackerInstance()->getNamed('node_announcement_answer'), $characters);
+ }
- // Absolute output path for compiled templates
- $templateInstance->setCompileOutputPath($templateInstance->getConfigInstance()->getConfigEntry('base_path') . $templateInstance->getConfigInstance()->getConfigEntry('compile_output_path'));
+ /**
+ * Getter for cache file (FQFN)
+ *
+ * @return $fqfn Full-qualified file name of the menu cache
+ */
+ public function getAnnouncementAnswerCacheFqfn () {
+ $this->partialStub('Please implement this method.');
+ }
- // Init a variable stacker
- $stackerInstance = ObjectFactory::createObjectByConfiguredName('node_announcement_answer_stacker_class');
+ /**
+ * Starts the announcement-answer
+ *
+ * @return void
+ */
+ protected function startAnnouncementAnswer () {
+ // Push the node name on the stacker
+ $this->getStackerInstance()->pushNamed('node_announcement_answer', 'announcement-answer');
+ }
- // Set it
- $templateInstance->setStackerInstance($stackerInstance);
+ /**
+ * Starts the my-data
+ *
+ * @return void
+ */
+ protected function startMyData () {
+ // Push the node name on the stacker
+ $this->getStackerInstance()->pushNamed('node_announcement_answer', 'my-data');
+ }
- // Return the prepared instance
- return $templateInstance;
+ /**
+ * Starts the my-external-ip
+ *
+ * @return void
+ */
+ protected function startMyExternalIp () {
+ // Push the node name on the stacker
+ $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_EXTERNAL_IP);
}
/**
- * Load a specified announcement-answer template into the engine
+ * Starts the my-internal-ip
*
- * @param $template The announcement-answer template we shall load which is
- * located in 'announcement-answer' by default
* @return void
*/
- public function loadAnnouncementAnswerTemplate ($template = 'announcement_answer') {
- // Set template type
- $this->setTemplateType($this->getConfigInstance()->getConfigEntry('node_announcement_answer_template_type'));
+ protected function startMyInternalIp () {
+ // Push the node name on the stacker
+ $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_INTERNAL_IP);
+ }
- // Load the special template
- $this->loadTemplate($template);
+ /**
+ * Starts the my-tcp-port
+ *
+ * @return void
+ */
+ protected function startMyTcpPort () {
+ // Push the node name on the stacker
+ $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_TCP_PORT);
}
/**
- * Getter for current main node
+ * Starts the my-udp-port
*
- * @return $currMainNode Current main node
+ * @return void
*/
- public final function getCurrMainNode () {
- return $this->curr['main_node'];
+ protected function startMyUdpPort () {
+ // Push the node name on the stacker
+ $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_UDP_PORT);
}
/**
- * Setter for current main node
+ * Starts the my-session-id
*
- * @param $element Element name to set as current main node
- * @return $currMainNode Current main node
+ * @return void
*/
- private final function setCurrMainNode ($element) {
- $this->curr['main_node'] = (string) $element;
+ protected function startMySessionId () {
+ // Push the node name on the stacker
+ $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_SESSION_ID);
}
/**
- * Getter for main node array
+ * Starts the my-status
*
- * @return $mainNodes Array with valid main node names
+ * @return void
*/
- public final function getMainNodes () {
- return $this->mainNodes;
+ protected function startMyStatus () {
+ // Push the node name on the stacker
+ $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_NODE_STATUS);
}
/**
- * Getter for sub node array
+ * Finishes the my-status
*
- * @return $subNodes Array with valid sub node names
+ * @return void
*/
- public final function getSubNodes () {
- return $this->subNodes;
+ protected function finishMyStatus () {
+ // Pop the last entry
+ $this->getStackerInstance()->popNamed('node_announcement_answer');
}
/**
- * Handles the start element of an XML resource
+ * Finishes the my-session-id
*
- * @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) {
- // Initial method name which will never be called...
- $methodName = 'initAnnouncementAnswer';
-
- // Make the element name lower-case
- $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' . $this->convertToClassName($element);
-
- // Set it
- $this->setCurrMainNode($element);
- } elseif (in_array($element, $this->getSubNodes())) {
- // Sub node found
- $methodName = 'start' . $this->convertToClassName($element);
- } else {
- // Invalid node name found
- throw new InvalidXmlNodeException(array($this, $element, $attributes), XmlParser::EXCEPTION_XML_NODE_UNKNOWN);
- }
-
- // Call method
- call_user_func_array(array($this, $methodName), $attributes);
+ protected function finishMySessionId () {
+ // Pop the last entry
+ $this->getStackerInstance()->popNamed('node_announcement_answer');
}
/**
- * Ends the main or sub node by sending out the gathered data
+ * Finishes the my-udp-port
*
- * @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) {
- // 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);
- } // END - if
+ protected function finishMyUdpPort () {
+ // Pop the last entry
+ $this->getStackerInstance()->popNamed('node_announcement_answer');
+ }
- // Construct method name
- $methodName = 'finish' . $this->convertToClassName($nodeName);
+ /**
+ * Finishes the my-tcp-port
+ *
+ * @return void
+ */
+ protected function finishMyTcpPort () {
+ // Pop the last entry
+ $this->getStackerInstance()->popNamed('node_announcement_answer');
+ }
- // Call the corresponding method
- //* DEBUG: */ echo "call: ".$methodName."<br />\n";
- call_user_func_array(array($this, $methodName), array());
+ /**
+ * Finishes the my-internal-ip
+ *
+ * @return void
+ */
+ protected function finishMyInternalIp () {
+ // Pop the last entry
+ $this->getStackerInstance()->popNamed('node_announcement_answer');
}
/**
- * Currently not used
+ * Finishes the my-external-ip
*
- * @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) {
- // Trim all spaces away
- $characters = trim($characters);
+ protected function finishMyExternalIp () {
+ // Pop the last entry
+ $this->getStackerInstance()->popNamed('node_announcement_answer');
+ }
- // Is this string empty?
- if (empty($characters)) {
- // Then skip it silently
- return false;
- } // END - if
+ /**
+ * Finishes the my-data
+ *
+ * @return void
+ */
+ protected function finishMyData () {
+ // Pop the last entry
+ $this->getStackerInstance()->popNamed('node_announcement_answer');
+ }
- // Get current XML node name as an array index
- $nodeName = $this->getStackerInstance()->getNamed('announcement-answer');
+ /**
+ * Starts the your-data
+ *
+ * @return void
+ */
+ protected function startYourData () {
+ // Push the node name on the stacker
+ $this->getStackerInstance()->pushNamed('node_announcement_answer', 'your-data');
+ }
- $this->partialStub('TODO: Do something with the gathered data.');
+ /**
+ * Starts the your-external-ip
+ *
+ * @return void
+ */
+ protected function startYourExternalIp () {
+ // Push the node name on the stacker
+ $this->getStackerInstance()->pushNamed('node_announcement_answer', 'your-external-ip');
}
/**
- * Getter for cache file (FQFN)
+ * Starts the your-internal-ip
*
- * @return $fqfn Full-qualified file name of the menu cache
+ * @return void
*/
- public function getAnnouncementAnswerCacheFqfn () {
- $this->partialStub('Please implement this method.');
+ protected function startYourInternalIp () {
+ // Push the node name on the stacker
+ $this->getStackerInstance()->pushNamed('node_announcement_answer', 'your-internal-ip');
}
/**
- * Starts the |||
+ * Starts the your-session-id
*
* @return void
*/
- private function startAnnouncementAnswer () {
+ protected function startYourSessionId () {
// Push the node name on the stacker
- $this->getStackerInstance()->pushNamed('announcement-answer', '|||');
+ $this->getStackerInstance()->pushNamed('node_announcement_answer', 'your-session-id');
+ }
+
+ /**
+ * Finishes the your-session-id
+ *
+ * @return void
+ */
+ protected function finishYourSessionId () {
+ // Pop the last entry
+ $this->getStackerInstance()->popNamed('node_announcement_answer');
+ }
+
+ /**
+ * Finishes the your-internal-ip
+ *
+ * @return void
+ */
+ protected function finishYourInternalIp () {
+ // Pop the last entry
+ $this->getStackerInstance()->popNamed('node_announcement_answer');
+ }
+
+ /**
+ * Finishes the your-external-ip
+ *
+ * @return void
+ */
+ protected function finishYourExternalIp () {
+ // Pop the last entry
+ $this->getStackerInstance()->popNamed('node_announcement_answer');
+ }
+
+ /**
+ * Finishes the your-data
+ *
+ * @return void
+ */
+ protected function finishYourData () {
+ // Pop the last entry
+ $this->getStackerInstance()->popNamed('node_announcement_answer');
}
/**
- * Finishes the |||
+ * Finishes the announcement-answer
*
* @return void
*/
- private function finishAnnouncementAnswer () {
+ protected function finishAnnouncementAnswer () {
// Pop the last entry
- $this->getStackerInstance()->popNamed('announcement-answer');
+ $this->getStackerInstance()->popNamed('node_announcement_answer');
}
}