]> git.mxchange.org Git - hub.git/blob
0a879d50d85d3f32ceb786259ff5ac73ff62ae7e
[hub.git] /
1 <?php
2 // Own namespace
3 namespace Hub\Node\Helper\Answer\Announcement;
4
5 // Import application-specific stuff
6 use Hub\Factory\Network\NetworkPackageFactory;
7 use Hub\Helper\Node\NodeHelper;
8
9 // Import framework stuff
10 use CoreFramework\Factory\Template\XmlTemplateEngineFactory;
11
12 /**
13  * A AnnouncementMessageAnswer node helper class
14  *
15  * @author              Roland Haeder <webmaster@shipsimu.org>
16  * @version             0.0.0
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
21  *
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.
26  *
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.
31  *
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/>.
34  */
35 class NodeAnnouncementMessageAnswerHelper extends BaseHubAnswerHelper implements HelpableNode {
36         /**
37          * Protected constructor
38          *
39          * @return      void
40          */
41         protected function __construct () {
42                 // Call parent constructor
43                 parent::__construct(__CLASS__);
44
45                 // Init package tags
46                 $this->setPackageTags(array('announcement_answer'));
47         }
48
49         /**
50          * Creates the helper class
51          *
52          * @param       $messageData            An array with all message data
53          * @return      $helperInstance         A prepared instance of this helper
54          */
55         public final static function createNodeAnnouncementMessageAnswerHelper (array $messageData) {
56                 // Get new instance
57                 $helperInstance = new NodeAnnouncementMessageAnswerHelper();
58
59                 // Set session id of other peer as recipient
60                 $helperInstance->setRecipientType($messageData[XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID]);
61
62                 // Set message data
63                 $helperInstance->setMessageData($messageData);
64
65                 // Return the prepared instance
66                 return $helperInstance;
67         }
68
69         /**
70          * Loads the descriptor XML file
71          *
72          * @param       $nodeInstance   An instance of a NodeHelper class
73          * @return      void
74          */
75         public function loadDescriptorXml (NodeHelper $nodeInstance) {
76                 // Debug message
77                 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HELPER: Attempting to answer an announcement...');
78
79                 // Get a XML template instance
80                 $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_announcement_answer_template_class');
81
82                 // Set it for later use
83                 $this->setTemplateInstance($templateInstance);
84
85                 // Read the XML descriptor
86                 $templateInstance->loadXmlTemplate();
87
88                 // Render the XML content
89                 $templateInstance->renderXmlContent();
90         }
91
92         /**
93          * Send out announcement answer package
94          *
95          * @param       $nodeInstance   An instance of a NodeHelper class
96          * @return      void
97          */
98         public function sendPackage (NodeHelper $nodeInstance) {
99                 // Sanity check: Is the node in the approx. state? (active/reachable)
100                 $nodeInstance->getStateInstance()->validateNodeStateIsActiveOrReachable();
101
102                 // Compile the template, this inserts the loaded node data into the gaps.
103                 $this->getTemplateInstance()->compileTemplate();
104
105                 // Get a singleton network package instance
106                 $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
107
108                 // Next, feed the content in. The network package class is a pipe-through class.
109                 $packageInstance->enqueueRawDataFromTemplate($this);
110         }
111
112 }