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