3 namespace Hub\Node\Helper\Answer\Request\NodeList;
5 // Import application-specific stuff
6 use Hub\Node\Helper\NodeHelper;
9 * A RequestNodeListMessageAnswer node helper class
11 * @author Roland Haeder <webmaster@shipsimu.org>
13 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
14 * @license GNU GPL 3.0 or any newer version
15 * @link http://www.shipsimu.org
16 * @todo Find an interface for hub helper
18 * This program is free software: you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation, either version 3 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 class NodeRequestNodeListMessageAnswerHelper extends BaseHubAnswerHelper implements HelpableNode {
33 * Protected constructor
37 protected function __construct () {
38 // Call parent constructor
39 parent::__construct(__CLASS__);
42 $this->setPackageTags(array('request_node_list_answer'));
46 * Creates the helper class
48 * @param $messageData An array with all message data
49 * @return $helperInstance A prepared instance of this helper
51 public final static function createNodeRequestNodeListMessageAnswerHelper (array $messageData) {
53 $helperInstance = new NodeRequestNodeListMessageAnswerHelper();
55 // Set session id of other peer as recipient
56 $helperInstance->setRecipientType($messageData[XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID]);
59 $helperInstance->setMessageData($messageData);
61 // Return the prepared instance
62 return $helperInstance;
66 * Loads the descriptor XML file
68 * @param $nodeInstance An instance of a NodeHelper class
71 public function loadDescriptorXml (NodeHelper $nodeInstance) {
73 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Attempting to answer a request: node-list...');
75 // Get a XML template instance
76 $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_request_node_list_answer_template_class');
78 // Set it for later use
79 $this->setTemplateInstance($templateInstance);
81 // Read the XML descriptor
82 $templateInstance->loadXmlTemplate();
84 // "Cache" entries instance for next foreach loop
85 $entriesInstance = $templateInstance->getTemplateInstance();
87 // Is must not be NULL (then it can only be a template instance)
88 assert(!is_null($entriesInstance));
90 // Render the XML content
91 $templateInstance->renderXmlContent();
95 * Send out request-node-list answer package
97 * @param $nodeInstance An instance of a NodeHelper class
100 public function sendPackage (NodeHelper $nodeInstance) {
101 // Sanity check: Is the node in the approx. state? (active/reachable)
102 $nodeInstance->getStateInstance()->validateNodeStateIsActiveOrReachable();
104 // Compile the template, this inserts the loaded node data into the gaps.
105 $this->getTemplateInstance()->compileTemplate();
107 // Get a singleton network package instance
108 $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
110 // Next, feed the content in. The network package class is a pipe-through class.
111 $packageInstance->enqueueRawDataFromTemplate($this);