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