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