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