]> git.mxchange.org Git - hub.git/blob
b8308a5cb87c23cd52728d96c3d6e4cbc701739c
[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 use Hub\Node\Helper\HelpableNode;
9
10 // Import framework stuff
11 use CoreFramework\Factory\Template\XmlTemplateEngineFactory;
12
13 /**
14  * A AnnouncementMessageAnswer node helper class
15  *
16  * @author              Roland Haeder <webmaster@shipsimu.org>
17  * @version             0.0.0
18  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
19  * @license             GNU GPL 3.0 or any newer version
20  * @link                http://www.shipsimu.org
21  * @todo                Find an interface for hub helper
22  *
23  * This program is free software: you can redistribute it and/or modify
24  * it under the terms of the GNU General Public License as published by
25  * the Free Software Foundation, either version 3 of the License, or
26  * (at your option) any later version.
27  *
28  * This program is distributed in the hope that it will be useful,
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31  * GNU General Public License for more details.
32  *
33  * You should have received a copy of the GNU General Public License
34  * along with this program. If not, see <http://www.gnu.org/licenses/>.
35  */
36 class NodeAnnouncementMessageAnswerHelper extends BaseHubAnswerHelper implements HelpableNode {
37         /**
38          * Protected constructor
39          *
40          * @return      void
41          */
42         protected function __construct () {
43                 // Call parent constructor
44                 parent::__construct(__CLASS__);
45
46                 // Init package tags
47                 $this->setPackageTags(array('announcement_answer'));
48         }
49
50         /**
51          * Creates the helper class
52          *
53          * @param       $messageData            An array with all message data
54          * @return      $helperInstance         A prepared instance of this helper
55          */
56         public final static function createNodeAnnouncementMessageAnswerHelper (array $messageData) {
57                 // Get new instance
58                 $helperInstance = new NodeAnnouncementMessageAnswerHelper();
59
60                 // Set session id of other peer as recipient
61                 $helperInstance->setRecipientType($messageData[XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID]);
62
63                 // Set message data
64                 $helperInstance->setMessageData($messageData);
65
66                 // Return the prepared instance
67                 return $helperInstance;
68         }
69
70         /**
71          * Loads the descriptor XML file
72          *
73          * @param       $nodeInstance   An instance of a NodeHelper class
74          * @return      void
75          */
76         public function loadDescriptorXml (NodeHelper $nodeInstance) {
77                 // Debug message
78                 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HELPER: Attempting to answer an announcement...');
79
80                 // Get a XML template instance
81                 $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_announcement_answer_template_class');
82
83                 // Set it for later use
84                 $this->setTemplateInstance($templateInstance);
85
86                 // Read the XML descriptor
87                 $templateInstance->loadXmlTemplate();
88
89                 // Render the XML content
90                 $templateInstance->renderXmlContent();
91         }
92
93         /**
94          * Send out announcement answer package
95          *
96          * @param       $nodeInstance   An instance of a NodeHelper class
97          * @return      void
98          */
99         public function sendPackage (NodeHelper $nodeInstance) {
100                 // Sanity check: Is the node in the approx. state? (active/reachable)
101                 $nodeInstance->getStateInstance()->validateNodeStateIsActiveOrReachable();
102
103                 // Compile the template, this inserts the loaded node data into the gaps.
104                 $this->getTemplateInstance()->compileTemplate();
105
106                 // Get a singleton network package instance
107                 $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
108
109                 // Next, feed the content in. The network package class is a pipe-through class.
110                 $packageInstance->enqueueRawDataFromTemplate($this);
111         }
112
113 }