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