]> git.mxchange.org Git - hub.git/blob
250b0527d246a9488f3294940151751cbcbb606d
[hub.git] /
1 <?php
2 // Own namespace
3 namespace Org\Shipsimu\Hub\Template\Engine\Xml\Answer\Request\NodeList;
4
5 // Import application-specific stuff
6 use Org\Shipsimu\Hub\Template\Engine\Xml\Network\Answer\BaseXmlAnswerTemplateEngine;
7
8 // Import framework stuff
9 use Org\Mxchange\CoreFramework\Factory\Template\XmlTemplateEngineFactory;
10 use Org\Mxchange\CoreFramework\Registry\Registerable;
11 use Org\Mxchange\CoreFramework\Template\Xml\CompileableXmlTemplate;
12 use Org\Mxchange\CoreFramework\Traits\Template\CompileableTemplateTrait;
13
14 /**
15  * A RequestNodeListAnswer template engine class for XML templates
16  *
17  * @author              Roland Haeder <webmaster@shipsimu.org>
18  * @version             0.0.0
19  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Hub Developer Team
20  * @license             GNU GPL 3.0 or any newer version
21  * @link                http://www.shipsimu.org
22  * @todo                This template engine does not make use of setTemplateType()
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 XmlRequestNodeListAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine implements CompileableXmlTemplate, Registerable {
38         // Load traits
39         use CompileableTemplateTrait;
40
41         // Constants for array elements
42         const REQUEST_DATA_SESSION_ID    = 'session-id';
43         const REQUEST_DATA_NODE_LIST     = 'node-list';
44
45         /**
46          * Protected constructor
47          *
48          * @return      void
49          */
50         private function __construct () {
51                 // Call parent constructor
52                 parent::__construct(__CLASS__);
53
54                 // Init sub-nodes array
55                 $this->setSubNodes(array(
56                         self::REQUEST_DATA_SESSION_ID,
57                         self::REQUEST_DATA_NODE_LIST,
58                         // Answer status (generic field)
59                         self::ANSWER_STATUS,
60                 ));
61         }
62
63         /**
64          * Creates an instance of the class TemplateEngine and prepares it for usage
65          *
66          * @return      $templateInstance               An instance of TemplateEngine
67          * @throws      BasePathIsEmptyException                If the provided $templateBasePath is empty
68          * @throws      InvalidBasePathStringException  If $templateBasePath is no string
69          * @throws      BasePathIsNoDirectoryException  If $templateBasePath is no
70          *                                                                                      directory or not found
71          * @throws      BasePathReadProtectedException  If $templateBasePath is
72          *                                                                                      read-protected
73          */
74         public static final function createXmlRequestNodeListAnswerTemplateEngine () {
75                 // Get a new instance
76                 $templateInstance = new XmlRequestNodeListAnswerTemplateEngine();
77
78                 // Init instance
79                 $templateInstance->initXmlTemplateEngine('node', 'request_node_list_answer');
80
81                 // Get a template instance for list entries (as they are dynamic)
82                 $entriesInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_request_node_list_entries_template_class');
83
84                 // Set it here
85                 $templateInstance->setTemplateInstance($entriesInstance);
86
87                 // Return the prepared instance
88                 return $templateInstance;
89         }
90
91         /**
92          * Currently not used
93          *
94          * @param       $resource               XML parser resource (currently ignored)
95          * @param       $characters             Characters to handle
96          * @return      void
97          * @todo        Find something useful with this!
98          */
99         public function characterHandler ($resource, string $characters) {
100                 // Trim all spaces away
101                 $characters = trim($characters);
102
103                 // Is this string empty?
104                 if (empty($characters)) {
105                         // Then skip it silently
106                         return;
107                 }
108
109                 /*
110                  * Assign the found characters to variable and use the last entry from
111                  * stack as the name.
112                  */
113                 parent::assignVariable($this->getStackInstance()->getNamed('node_request_node_list_answer'), $characters);
114         }
115
116         /**
117          * Getter for cache file (FQFN)
118          *
119          * @return      $fqfn   Full-qualified file name of the menu cache
120          */
121         public function getRequestNodeListAnswerCacheFqfn () {
122                 $this->partialStub('Please implement this method.');
123         }
124
125         /**
126          * Starts the 'request-node-list-answer'
127          *
128          * @return      void
129          */
130         protected function startRequestNodeListAnswer () {
131                 // Push the node name on the stacker
132                 $this->getStackInstance()->pushNamed('node_request_node_list_answer', 'request-node-list-answer');
133         }
134
135         /**
136          * Starts the session-id
137          *
138          * @return      void
139          */
140         protected function startSessionId () {
141                 // Push the node name on the stacker
142                 $this->getStackInstance()->pushNamed('node_request_node_list_answer', self::REQUEST_DATA_SESSION_ID);
143         }
144
145         /**
146          * Starts the node-list
147          *
148          * @return      void
149          */
150         protected function startNodeList () {
151                 // Push the node name on the stacker
152                 $this->getStackInstance()->pushNamed('node_request_node_list_answer', self::REQUEST_DATA_NODE_LIST);
153         }
154
155         /**
156          * Finishes the node-list
157          *
158          * @return      void
159          */
160         protected function finishNodeList () {
161                 // Pop the last entry
162                 $this->getStackInstance()->popNamed('node_request_node_list_answer');
163         }
164
165         /**
166          * Finishes the session-id
167          *
168          * @return      void
169          */
170         protected function finishSessionId () {
171                 // Pop the last entry
172                 $this->getStackInstance()->popNamed('node_request_node_list_answer');
173         }
174
175         /**
176          * Finishes the 'request-node-list-answer'
177          *
178          * @return      void
179          */
180         protected function finishRequestNodeListAnswer () {
181                 // Pop the last entry
182                 $this->getStackInstance()->popNamed('node_request_node_list_answer');
183         }
184
185 }