]> git.mxchange.org Git - core.git/blob - framework/main/classes/template/menu/class_MenuTemplateEngine.php
Continued:
[core.git] / framework / main / classes / template / menu / class_MenuTemplateEngine.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\CoreFramework\Template\Engine;
4
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
7 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
8 use Org\Mxchange\CoreFramework\Filesystem\InvalidDirectoryException;
9 use Org\Mxchange\CoreFramework\Menu\RenderableMenu;
10 use Org\Mxchange\CoreFramework\Parser\Xml\XmlParser;
11 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
12 use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
13 use Org\Mxchange\CoreFramework\Template\Engine\BaseTemplateEngine;
14 use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
15
16 // Import SPL stuff
17 use \SplFileInfo;
18 use \UnexpectedValueException;
19
20 /**
21  * A Menu template engine class
22  *
23  * @author              Roland Haeder <webmaster@shipsimu.org>
24  * @version             0.0.0
25  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
26  * @license             GNU GPL 3.0 or any newer version
27  * @link                http://www.shipsimu.org
28  *
29  * This program is free software: you can redistribute it and/or modify
30  * it under the terms of the GNU General Public License as published by
31  * the Free Software Foundation, either version 3 of the License, or
32  * (at your option) any later version.
33  *
34  * This program is distributed in the hope that it will be useful,
35  * but WITHOUT ANY WARRANTY; without even the implied warranty of
36  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37  * GNU General Public License for more details.
38  *
39  * You should have received a copy of the GNU General Public License
40  * along with this program. If not, see <http://www.gnu.org/licenses/>.
41  */
42 class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTemplate {
43         /**
44          * Main nodes in the XML tree ('menu' is ignored)
45          */
46         private $mainNodes = array(
47                 'block-list',
48         );
49
50         /**
51          * Sub nodes in the XML tree
52          */
53         private $subNodes = array(
54                 'entry-list',
55                 'entry',
56                 'entry-id',
57                 'entries-content',
58                 'block-header',
59                 'block-footer',
60                 'footer-id',
61                 'footer-class',
62                 'footer-text',
63                 'block',
64                 'title',
65                 'title-id',
66                 'title-class',
67                 'title-text',
68                 'design',
69                 'text',
70                 'advert',
71                 'anchor',
72                 'anchor-id',
73                 'anchor-text',
74                 'anchor-title',
75                 'anchor-href',
76         );
77
78         /**
79          * Variables for a menu entry
80          */
81         private $menuEntryVariables = array(
82                 // List entry
83                 'entry_id',
84                 // Anchor
85                 'anchor-id',
86                 'anchor-text',
87                 'anchor-title',
88                 'anchor-href',
89         );
90
91         /**
92          * Variables for a menu block
93          */
94         private $menuBlockVariables = array(
95                 // Title
96                 'title_id',
97                 'title_class',
98                 'title_text',
99                 // Content is taken from menuEntries
100                 // Footer
101                 'footer_id',
102                 'footer_class',
103                 'footer_text',
104         );
105
106         /**
107          * Rendered menu entries
108          */
109         private $menuEntries = array();
110
111         /**
112          * Rendered menu blocks
113          */
114         private $menuBlocks = array();
115
116         /**
117          * Current main node
118          */
119         private $curr = array();
120
121         /**
122          * Content from dependency
123          */
124         private $dependencyContent = array();
125
126         /**
127          * Instance of a menu
128          */
129         private $menuInstance = NULL;
130
131         /**
132          * Protected constructor
133          *
134          * @return      void
135          */
136         protected function __construct () {
137                 // Call parent constructor
138                 parent::__construct(__CLASS__);
139         }
140
141         /**
142          * Creates an instance of the class TemplateEngine and prepares it for usage
143          *
144          * @param       $menuInstance                   A RenderableMenu instance
145          * @return      $templateInstance               An instance of TemplateEngine
146          * @throws      UnexpectedValueException                If the found $templateBasePath is empty or not a string
147          * @throws      InvalidDirectoryException       If $templateBasePath is no directory or not found
148          * @throws      BasePathReadProtectedException  If $templateBasePath is
149          *                                                                                      read-protected
150          */
151         public static final function createMenuTemplateEngine (RenderableMenu $menuInstance) {
152                 // Get a new instance
153                 $templateInstance = new MenuTemplateEngine();
154
155                 // Get the application instance from registry
156                 $applicationInstance = GenericRegistry::getRegistry()->getInstance('application');
157
158                 // Determine base path
159                 $templateBasePath = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('application_base_path') . $applicationInstance->getAppShortName(). '/';
160
161                 // Is the base path valid?
162                 if (empty($templateBasePath)) {
163                         // Base path is empty
164                         throw new UnexpectedValueException(sprintf('[%s:%d] Variable templateBasePath is empty.', $templateInstance->__toString(), __LINE__), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
165                 } elseif (!is_string($templateBasePath)) {
166                         // Is not a string
167                         throw new UnexpectedValueException(sprintf('[%s:%d] %s is not a string with a base path.', $templateInstance->__toString(), __LINE__, $templateBasePath), self::EXCEPTION_INVALID_STRING);
168                 } elseif (!is_dir($templateBasePath)) {
169                         // Is not a path
170                         throw new InvalidDirectoryException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME);
171                 } elseif (!is_readable($templateBasePath)) {
172                         // Is not readable
173                         throw new BasePathReadProtectedException(array($templateInstance, $templateBasePath), self::EXCEPTION_READ_PROTECED_PATH);
174                 }
175
176                 // Set the base path
177                 $templateInstance->setTemplateBasePath($templateBasePath);
178
179                 // Set template extensions
180                 $templateInstance->setRawTemplateExtension(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('raw_template_extension'));
181                 $templateInstance->setCodeTemplateExtension(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('menu_template_extension'));
182
183                 // Absolute output path for compiled templates
184                 $templateInstance->setCompileOutputPath(sprintf('%s%s/',
185                         $templateBasePath,
186                         FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('compile_output_path')
187                 ));
188
189                 // Set the menu instance
190                 $templateInstance->setMenuInstance($menuInstance);
191
192                 // Init a variable stacker
193                 $stackInstance = ObjectFactory::createObjectByConfiguredName('menu_stacker_class');
194
195                 // Set it
196                 $templateInstance->setStackInstance($stackInstance);
197
198                 // Return the prepared instance
199                 return $templateInstance;
200         }
201
202         /**
203          * Setter for the menu instance
204          *
205          * @param       $menuInstance   A RenderableMenu instance
206          * @return      void
207          */
208         protected final function setMenuInstance (RenderableMenu $menuInstance) {
209                 $this->menuInstance = $menuInstance;
210         }
211
212         /**
213          * Getter for the menu instance
214          *
215          * @return      $menuInstance   A RenderableMenu instance
216          */
217         private final function getMenuInstance () {
218                 return $this->menuInstance;
219         }
220
221         /**
222          * Load a specified menu template into the engine
223          *
224          * @param       $template       The menu template we shall load which is
225          *                                              located in 'menu' by default
226          * @return      void
227          */
228         public function loadMenuTemplate ($template) {
229                 // Set template type
230                 $this->setTemplateType(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('menu_template_type'));
231
232                 // Load the special template
233                 $this->loadTemplate($template);
234         }
235
236         /**
237          * Getter for current main node
238          *
239          * @return      $currMainNode   Current main node
240          */
241         public final function getCurrMainNode () {
242                 return $this->curr['main_node'];
243         }
244
245         /**
246          * Setter for current main node
247          *
248          * @param       $element                Element name to set as current main node
249          * @return      $currMainNode   Current main node
250          */
251         private final function setCurrMainNode ($element) {
252                 $this->curr['main_node'] = (string) $element;
253         }
254
255         /**
256          * Getter for main node array
257          *
258          * @return      $mainNodes      Array with valid main node names
259          */
260         public final function getMainNodes () {
261                 return $this->mainNodes;
262         }
263
264         /**
265          * Getter for sub node array
266          *
267          * @return      $subNodes       Array with valid sub node names
268          */
269         public final function getSubNodes () {
270                 return $this->subNodes;
271         }
272
273         /**
274          * Handles the start element of an XML resource
275          *
276          * @param       $resource               XML parser resource (currently ignored)
277          * @param       $element                The element we shall handle
278          * @param       $attributes             All attributes
279          * @return      void
280          * @throws      InvalidXmlNodeException         If an unknown/invalid XML node name was found
281          */
282         public function startElement ($resource, $element, array $attributes) {
283                 // Initial method name which will never be called...
284                 $methodName = 'initMenu';
285
286                 // Make the element name lower-case
287                 $element = strtolower($element);
288
289                 // Is the element a main node?
290                 //* DEBUG: */ echo "START: &gt;".$element."&lt;<br />\n";
291                 if (in_array($element, $this->getMainNodes())) {
292                         // Okay, main node found!
293                         $methodName = 'start' . StringUtils::convertToClassName($element);
294
295                         // Set it
296                         $this->setCurrMainNode($element);
297                 } elseif (in_array($element, $this->getSubNodes())) {
298                         // Sub node found
299                         $methodName = 'start' . StringUtils::convertToClassName($element);
300                 } elseif ($element != 'menu') {
301                         // Invalid node name found
302                         throw new InvalidXmlNodeException(array($this, $element, $attributes), XmlParser::EXCEPTION_XML_NODE_UNKNOWN);
303                 }
304
305                 // Call method
306                 //* DEBUG: */ echo "call: ".$methodName."<br />\n";
307                 call_user_func_array(array($this, $methodName), $attributes);
308         }
309
310         /**
311          * Ends the main or sub node by sending out the gathered data
312          *
313          * @param       $resource       An XML resource pointer (currently ignored)
314          * @param       $nodeName       Name of the node we want to finish
315          * @return      void
316          * @throws      XmlNodeMismatchException        If current main node mismatches the closing one
317          */
318         public function finishElement ($resource, $nodeName) {
319                 // Make all lower-case
320                 $nodeName = strtolower($nodeName);
321
322                 // Does this match with current main node?
323                 //* DEBUG: */ echo "END: &gt;".$nodeName."&lt;<br />\n";
324                 if (($nodeName != $this->getCurrMainNode()) && (in_array($nodeName, $this->getMainNodes()))) {
325                         // Did not match!
326                         throw new XmlNodeMismatchException (array($this, $nodeName, $this->getCurrMainNode()), XmlParser::EXCEPTION_XML_NODE_MISMATCH);
327                 } // END - if
328
329                 // Construct method name
330                 $methodName = 'finish' . StringUtils::convertToClassName($nodeName);
331
332                 // Call the corresponding method
333                 //* DEBUG: */ echo "call: ".$methodName."<br />\n";
334                 call_user_func_array(array($this, $methodName), array());
335         }
336
337         /**
338          * Currently not used
339          *
340          * @param       $resource               XML parser resource (currently ignored)
341          * @param       $characters             Characters to handle
342          * @return      void
343          * @todo        Find something useful with this!
344          */
345         public function characterHandler ($resource, $characters) {
346                 // Trim all spaces away
347                 $characters = trim($characters);
348
349                 // Is this string empty?
350                 if (empty($characters)) {
351                         // Then skip it silently
352                         return;
353                 } // END - if
354
355                 // Assign the found characters to variable and use the last entry from
356                 // stack as the name
357                 parent::assignVariable($this->getStackInstance()->getNamed('current_node'), $characters);
358         }
359
360         /**
361          * Handles the template dependency for given node
362          *
363          * @param       $node                                   The node we should load a dependency template
364          * @param       $templateDependency             A template to load to satisfy dependencies
365          * @return      void
366          */
367         private function handleTemplateDependency ($node, $templateDependency) {
368                 // Is the template dependency set?
369                 if ((!empty($templateDependency)) && (!isset($this->dependencyContent[$node]))) {
370                         // Get a temporay menu template instance
371                         $templateInstance = ObjectFactory::createObjectByConfiguredName('menu_template_class', array($this->getMenuInstance()));
372
373                         // Then load it
374                         $templateInstance->loadMenuTemplate($templateDependency);
375
376                         // Parse the XML content
377                         $templateInstance->renderXmlContent();
378
379                         // Save the parsed raw content in our dependency array
380                         $this->dependencyContent[$node] = $templateInstance->getRawTemplateData();
381                 } // END - if
382         }
383
384         /**
385          * Intializes the menu
386          *
387          * @param       $templateDependency             A template to load to satisfy dependencies
388          * @return      void
389          * @todo        Add cache creation here
390          */
391         private function initMenu ($templateDependency = '') {
392                 // Get web template engine
393                 $this->setTemplateInstance(ObjectFactory::createObjectByConfiguredName('html_template_class', array(GenericRegistry::getRegistry()->getInstance('application'))));
394
395                 // Handle the dependency template
396                 $this->handleTemplateDependency('menu', $templateDependency);
397
398                 // Push the node name on the stacker
399                 $this->getStackInstance()->pushNamed('current_node', 'menu');
400         }
401
402         /**
403          * Starts the menu entries
404          *
405          * @param       $templateDependency             A template to load to satisfy dependencies
406          * @return      void
407          */
408         private function startEntryList () {
409                 // Push the node name on the stacker
410                 $this->getStackInstance()->pushNamed('current_node', 'entry-list');
411         }
412
413         /**
414          * Starts the menu block header
415          *
416          * @return      void
417          */
418         private function startBlockHeader () {
419                 // Push the node name on the stacker
420                 $this->getStackInstance()->pushNamed('current_node', 'block-header');
421         }
422
423         /**
424          * Starts the menu block footer
425          *
426          * @return      void
427          */
428         private function startBlockFooter () {
429                 // Push the node name on the stacker
430                 $this->getStackInstance()->pushNamed('current_node', 'block-footer');
431         }
432
433         /**
434          * Starts the menu property 'block-list'
435          *
436          * @return      void
437          */
438         private function startBlockList () {
439                 // Push the node name on the stacker
440                 $this->getStackInstance()->pushNamed('current_node', 'block-list');
441         }
442
443         /**
444          * Starts the menu property 'block'
445          *
446          * @return      void
447          */
448         private function startBlock () {
449                 // Push the node name on the stacker
450                 $this->getStackInstance()->pushNamed('current_node', 'block');
451         }
452
453         /**
454          * Starts the menu property 'title'
455          *
456          * @return      void
457          */
458         private function startTitle () {
459                 // Push the node name on the stacker
460                 $this->getStackInstance()->pushNamed('current_node', 'title');
461         }
462
463         /**
464          * Starts the menu property 'title-id'
465          *
466          * @return      void
467          */
468         private function startTitleId () {
469                 // Push the node name on the stacker
470                 $this->getStackInstance()->pushNamed('current_node', 'title-id');
471         }
472
473         /**
474          * Starts the menu property 'title-class'
475          *
476          * @return      void
477          */
478         private function startTitleClass () {
479                 // Push the node name on the stacker
480                 $this->getStackInstance()->pushNamed('current_node', 'title-class');
481         }
482
483         /**
484          * Starts the menu property 'title-text'
485          *
486          * @return      void
487          */
488         private function startTitleText () {
489                 // Push the node name on the stacker
490                 $this->getStackInstance()->pushNamed('current_node', 'title-text');
491         }
492
493         /**
494          * Starts the menu property 'entry'
495          *
496          * @return      void
497          */
498         private function startEntry () {
499                 // Push the node name on the stacker
500                 $this->getStackInstance()->pushNamed('current_node', 'entry');
501         }
502
503         /**
504          * Starts the menu property 'entry-id'
505          *
506          * @return      void
507          */
508         private function startEntryId () {
509                 // Push the node name on the stacker
510                 $this->getStackInstance()->pushNamed('current_node', 'entry-id');
511         }
512
513         /**
514          * Starts the menu property 'anchor'
515          *
516          * @return      void
517          */
518         private function startAnchor () {
519                 // Push the node name on the stacker
520                 $this->getStackInstance()->pushNamed('current_node', 'anchor');
521         }
522
523         /**
524          * Starts the menu property 'anchor-id'
525          *
526          * @return      void
527          */
528         private function startAnchorId () {
529                 // Push the node name on the stacker
530                 $this->getStackInstance()->pushNamed('current_node', 'anchor-id');
531         }
532
533         /**
534          * Starts the menu property 'anchor-text'
535          *
536          * @return      void
537          */
538         private function startAnchorText () {
539                 // Push the node name on the stacker
540                 $this->getStackInstance()->pushNamed('current_node', 'anchor-text');
541         }
542
543         /**
544          * Starts the menu property 'anchor-title'
545          *
546          * @return      void
547          */
548         private function startAnchorTitle () {
549                 // Push the node name on the stacker
550                 $this->getStackInstance()->pushNamed('current_node', 'anchor-title');
551         }
552
553         /**
554          * Starts the menu property 'anchor-href'
555          *
556          * @return      void
557          */
558         private function startAnchorHref () {
559                 // Push the node name on the stacker
560                 $this->getStackInstance()->pushNamed('current_node', 'anchor-href');
561         }
562
563         /**
564          * Starts the menu property 'footer-id'
565          *
566          * @return      void
567          */
568         private function startFooterId () {
569                 // Push the node name on the stacker
570                 $this->getStackInstance()->pushNamed('current_node', 'footer-id');
571         }
572
573         /**
574          * Starts the menu property 'footer-class'
575          *
576          * @return      void
577          */
578         private function startFooterClass () {
579                 // Push the node name on the stacker
580                 $this->getStackInstance()->pushNamed('current_node', 'footer-class');
581         }
582
583         /**
584          * Starts the menu property 'footer-text'
585          *
586          * @return      void
587          */
588         private function startFooterText () {
589                 // Push the node name on the stacker
590                 $this->getStackInstance()->pushNamed('current_node', 'footer-text');
591         }
592
593         /**
594          * Finishes the title node by added another template to the menu
595          *
596          * @return      void
597          */
598         private function finishTitle () {
599                 // Pop the last entry
600                 $this->getStackInstance()->popNamed('current_node');
601         }
602
603         /**
604          * Finishes the title-id node by
605          *
606          * @return      void
607          */
608         private function finishTitleId () {
609                 // Pop the last entry
610                 $this->getStackInstance()->popNamed('current_node');
611         }
612
613         /**
614          * Finishes the title-class node
615          *
616          * @return      void
617          */
618         private function finishTitleClass () {
619                 // Pop the last entry
620                 $this->getStackInstance()->popNamed('current_node');
621         }
622
623         /**
624          * Finishes the title-class node
625          *
626          * @return      void
627          */
628         private function finishTitleText () {
629                 // Pop the last entry
630                 $this->getStackInstance()->popNamed('current_node');
631         }
632
633         /**
634          * Finishes the footer-text node
635          *
636          * @return      void
637          */
638         private function finishFooterText () {
639                 // Pop the last entry
640                 $this->getStackInstance()->popNamed('current_node');
641         }
642
643         /**
644          * Finishes the footer-class node
645          *
646          * @return      void
647          */
648         private function finishFooterClass () {
649                 // Pop the last entry
650                 $this->getStackInstance()->popNamed('current_node');
651         }
652
653         /**
654          * Finishes the footer-id node
655          *
656          * @return      void
657          */
658         private function finishFooterId () {
659                 // Pop the last entry
660                 $this->getStackInstance()->popNamed('current_node');
661         }
662
663         /**
664          * Finishes the anchor-href node
665          *
666          * @return      void
667          */
668         private function finishAnchorHref () {
669                 // Pop the last entry
670                 $this->getStackInstance()->popNamed('current_node');
671         }
672
673         /**
674          * Finishes the anchor-title node
675          *
676          * @return      void
677          */
678         private function finishAnchorTitle () {
679                 // Pop the last entry
680                 $this->getStackInstance()->popNamed('current_node');
681         }
682
683         /**
684          * Finishes the anchor-text node
685          *
686          * @return      void
687          */
688         private function finishAnchorText () {
689                 // Pop the last entry
690                 $this->getStackInstance()->popNamed('current_node');
691         }
692
693         /**
694          * Finishes the anchor-id node
695          *
696          * @return      void
697          */
698         private function finishAnchorId () {
699                 // Pop the last entry
700                 $this->getStackInstance()->popNamed('current_node');
701         }
702
703         /**
704          * Finishes the anchor node
705          *
706          * @return      void
707          */
708         private function finishAnchor () {
709                 // Pop the last entry
710                 $this->getStackInstance()->popNamed('current_node');
711         }
712
713         /**
714          * Finishes the entry-id node
715          *
716          * @return      void
717          */
718         private function finishEntryId () {
719                 // Pop the last entry
720                 $this->getStackInstance()->popNamed('current_node');
721         }
722
723         /**
724          * Finishes the entry node
725          *
726          * @return      void
727          */
728         private function finishEntry () {
729                 // Pop the last entry
730                 $this->getStackInstance()->popNamed('current_node');
731
732                 // Render this menu entry
733                 $this->renderMenuEntry();
734         }
735
736         /**
737          * Finishes the block node
738          *
739          * @return      void
740          */
741         private function finishBlock () {
742                 // Pop the last entry
743                 $this->getStackInstance()->popNamed('current_node');
744
745                 // Render this menu block
746                 $this->renderMenuBlock();
747         }
748
749         /**
750          * Finishes the block-list node
751          *
752          * @return      void
753          */
754         private function finishBlockList () {
755                 // Pop the last entry
756                 $this->getStackInstance()->popNamed('current_node');
757         }
758
759         /**
760          * Finishes the menu entries
761          *
762          * @return      void
763          */
764         private function finishEntryList () {
765                 // Pop the last entry
766                 $this->getStackInstance()->popNamed('current_node');
767         }
768
769         /**
770          * Finishes the menu block header
771          *
772          * @return      void
773          */
774         private function finishBlockHeader () {
775                 // Pop the last entry
776                 $this->getStackInstance()->popNamed('current_node');
777         }
778
779         /**
780          * Finishes the menu block footer
781          *
782          * @return      void
783          */
784         private function finishBlockFooter () {
785                 // Pop the last entry
786                 $this->getStackInstance()->popNamed('current_node');
787         }
788
789         /**
790          * Finishes the menu
791          *
792          * @return      void
793          */
794         private function finishMenu () {
795                 // Pop the last entry
796                 $this->getStackInstance()->popNamed('current_node');
797         }
798
799         /**
800          * Renders this menu entry, as every block all variables got overwritten
801          * with data from next entry.
802          *
803          * @return      void
804          */
805         private function renderMenuEntry () {
806                 // Prepare template engine
807                 $templateInstance = $this->prepareTemplateInstance();
808
809                 // Load menu entry template
810                 $templateInstance->loadCodeTemplate('menu_entry');
811
812                 // Copy all variables over to it
813                 foreach ($this->menuEntryVariables as $variableName) {
814                         // Copy variable
815                         $variableValue = $this->readVariable($variableName);
816
817                         // Is the key 'anchor-href'?
818                         if ($variableName == 'anchor-href') {
819                                 // Expand variable with URL then
820                                 $variableValue = '{?base_url?}/' . $variableValue;
821                         } // END - if
822
823                         // ... into the instance
824                         $templateInstance->assignVariable($variableName, $variableValue);
825                 } // END - foreach
826
827                 // Compile template + variables
828                 $templateInstance->compileTemplate();
829                 $templateInstance->compileVariables();
830
831                 // Remember it here
832                 $this->menuEntries[$this->readVariable('entry_id')] = $templateInstance->getRawTemplateData();
833         }
834
835         /**
836          * Renders this menu block, as next block all data is overwritten with
837          * next block.
838          *
839          * @return      void
840          */
841         private function renderMenuBlock () {
842                 // Init block content
843                 $blockContent = implode('', $this->menuEntries);
844
845                 // Prepare template engine
846                 $templateInstance = $this->prepareTemplateInstance();
847
848                 // Load menu entry template
849                 $templateInstance->loadCodeTemplate('menu_block');
850
851                 // Copy all variables over to it
852                 foreach ($this->menuBlockVariables as $variableName) {
853                         // Copy variable
854                         $variableValue = $this->readVariable($variableName);
855
856                         // ... into the instance
857                         $templateInstance->assignVariable($variableName, $variableValue);
858                 } // END - foreach
859
860                 // Assign block content
861                 $templateInstance->assignVariable('block_content', $blockContent);
862
863                 // Compile template + variables
864                 $templateInstance->compileTemplate();
865                 $templateInstance->compileVariables();
866
867                 // Remember it here
868                 array_push($this->menuBlocks, $templateInstance->getRawTemplateData());
869
870                 // Reset rendered menu entries array
871                 $this->menuEntries = array();
872         }
873
874         /**
875          * "Getter" for menu content
876          *
877          * @return      $menuContent    Returned menu content
878          */
879         public function getMenuContent () {
880                 // Implode menuBlocks
881                 $menuContent = implode('', $this->menuBlocks);
882
883                 // Clean variable
884                 $this->menuBlocks = array();
885
886                 // And return it
887                 return $menuContent;
888         }
889
890         /**
891          * Getter for menu cache file instance
892          *
893          * @return      $fileInstance   Full-qualified file name of the menu cache
894          */
895         public function getMenuCacheFile () {
896                 // Get the application instance from registry
897                 $applicationInstance = GenericRegistry::getRegistry()->getInstance('application');
898
899                 // Get the file instance ready
900                 $fileInstance = new SplFileInfo(sprintf('%s%smenus/_cache/%s.%s',
901                         FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('application_base_path'),
902                         $applicationInstance->getAppShortName(),
903                         md5(
904                                 $this->getMenuInstance()->getMenuName() . ':' .
905                                 $this->__toString() . ':' .
906                                 $this->getMenuInstance()->__toString()
907                         ),
908                         $this->getMenuInstance()->getMenuType()
909                 ));
910
911                 // Return it
912                 return $fileInstance;
913         }
914
915 }