]> git.mxchange.org Git - hub.git/blob - application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php
State pattern added, hub continued (sorry, I let it lay around uncommitted for long...
[hub.git] / application / hub / main / helper / hub / announcement / class_HubDescriptorHelper.php
1 <?php
2 /**
3  * A Descriptor hub helper class
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.ship-simu.org
10  * @todo                Find an interface for hub helper
11  *
12  * This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  */
25 class HubDescriptorHelper extends BaseHubHelper {
26         /**
27          * Protected constructor
28          *
29          * @return      void
30          */
31         protected function __construct () {
32                 // Call parent constructor
33                 parent::__construct(__CLASS__);
34         }
35
36         /**
37          * Creates the helper class
38          *
39          * @param       $nodeInstance           An instance of a NodeHelper class
40          * @return      $helperInstance         A prepared instance of this helper
41          */
42         public final static function createHubDescriptorHelper (NodeHelper $nodeInstance) {
43                 // Get new instance
44                 $helperInstance = new HubDescriptorHelper();
45
46                 // Set the node instance
47                 $helperInstance->setNodeInstance($nodeInstance);
48
49                 // Return the prepared instance
50                 return $helperInstance;
51         }
52
53         /**
54          * Loads the announcement descriptor for parsing
55          *
56          * @return      void
57          * @todo        Rewrite the ->renderXmlContent() call to no arguments
58          */
59         public function loadAnnouncementDescriptor () {
60                 // Debug message
61                 $this->debugOutput('HELPER: Starting with announcement to upper hubs...');
62
63                 // Get the application instance
64                 $appInstance = Registry::getRegistry()->getInstance('app');
65
66                 // Get a XML template instance
67                 $templateInstance = ObjectFactory::createObjectByConfiguredName('announcement_template_class', array($appInstance));
68
69                 // Disable language support
70                 $templateInstance->enableLanguageSupport(false);
71
72                 // Enable compacting/rewriting of the  XML to save bandwidth from XML
73                 // comments. This is expensive and should be avoided in general.
74                 $templateInstance->enableXmlCompacting();
75
76                 // Set it for later use
77                 $this->setTemplateInstance($templateInstance);
78
79                 // Get an XML parser instance
80                 $parserInstance = ObjectFactory::createObjectByConfiguredName('xml_parser_class', array($this->getTemplateInstance()));
81
82                 // Read the XML descriptor
83                 $this->getTemplateInstance()->loadAnnouncementTemplate('self_announcement');
84
85                 // Render the XML content
86                 $this->getTemplateInstance()->renderXmlContent();
87         }
88
89         /**
90          * Publishes the node's descriptor XML to all found upper nodes when the
91          * node has not yet published it's descriptor to a bootstrap node. This is
92          * done by getting the raw XML content and inserting all variables into
93          * the code. After this wents fine, the rendered content got "packaged"
94          * for network delivery.
95          *
96          * @return      void
97          */
98         public function publishAnnouncementDescriptor () {
99                 // Is the node in the approx state? (active)
100                 $this->getNodeInstance()->getStateInstance()->validateNodeStateIsActive();
101
102                 // Compile the template, this inserts the loaded node data into the gaps.
103                 $this->getTemplateInstance()->compileTemplate();
104
105                 // Prepare the compressor for our package, GZIP should be fine but we
106                 // keep it open here so you can experiment with the settings and don't
107                 // need to touch any code.
108                 $compressorInstance = ObjectFactory::createObjectByConfiguredName('raw_package_compressor_class');
109
110                 // Prepare the decorator compressor (for later flawless and easy updates)
111                 $compressorInstance = ObjectFactory::createObjectByConfiguredName('deco_package_compressor_class', array($compressorInstance));
112
113                 // Now prepare the network package for delivery so only need to do this
114                 // once just before the "big announcement loop".
115                 $packageInstance = ObjectFactory::createObjectByConfiguredName('network_package_class', array($compressorInstance));
116
117                 // Enable re-queue support which re-queues the below feeded content
118                 // into the delivery method all over again.
119                 $packageInstance->enableDataReQueueing();
120
121                 // Next, feed the content in. The network package class is a pipe-through class.
122                 $packageInstance->queueRawDataFromTemplate($this->getTemplateInstance());
123
124                 // Debug only:
125                 /* DEBUG: */ die(print_r($this->getTemplateInstance(), true));
126         }
127 }
128
129 // [EOF]
130 ?>