All XML-parsing-related stuff refactured to new XmlParser class
[core.git] / inc / classes / main / template / menu / class_MenuTemplateEngine.php
1 <?php
2 /**
3  * A Menu template engine class
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.ship-simu.org
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTemplate {
25         /**
26          * Protected constructor
27          *
28          * @return      void
29          */
30         protected function __construct () {
31                 // Call parent constructor
32                 parent::__construct(__CLASS__);
33         }
34
35         /**
36          * Creates an instance of the class TemplateEngine and prepares it for usage
37          *
38          * @param       $appInstance    A manageable application
39          * @return      $tplInstance    An instance of TemplateEngine
40          * @throws      BasePathIsEmptyException                If the provided $templateBasePath is empty
41          * @throws      InvalidBasePathStringException  If $templateBasePath is no string
42          * @throws      BasePathIsNoDirectoryException  If $templateBasePath is no
43          *                                                                                      directory or not found
44          * @throws      BasePathReadProtectedException  If $templateBasePath is
45          *                                                                                      read-protected
46          */
47         public final static function createMenuTemplateEngine (ManageableApplication $appInstance) {
48                 // Get a new instance
49                 $tplInstance = new MenuTemplateEngine();
50
51                 // Get language and file I/O instances from application
52                 $langInstance = $appInstance->getLanguageInstance();
53                 $ioInstance = $appInstance->getFileIoInstance();
54
55                 // Determine base path
56                 $templateBasePath = $tplInstance->getConfigInstance()->getConfigEntry('application_base_path') . $appInstance->getRequestInstance()->getRequestElement('app') . '/';
57
58                 // Is the base path valid?
59                 if (empty($templateBasePath)) {
60                         // Base path is empty
61                         throw new BasePathIsEmptyException($tplInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
62                 } elseif (!is_string($templateBasePath)) {
63                         // Is not a string
64                         throw new InvalidBasePathStringException(array($tplInstance, $templateBasePath), self::EXCEPTION_INVALID_STRING);
65                 } elseif (!is_dir($templateBasePath)) {
66                         // Is not a path
67                         throw new BasePathIsNoDirectoryException(array($tplInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME);
68                 } elseif (!is_readable($templateBasePath)) {
69                         // Is not readable
70                         throw new BasePathReadProtectedException(array($tplInstance, $templateBasePath), self::EXCEPTION_READ_PROTECED_PATH);
71                 }
72
73                 // Get configuration instance
74                 $configInstance = FrameworkConfiguration::getInstance();
75
76                 // Set the base path
77                 $tplInstance->setTemplateBasePath($templateBasePath);
78
79                 // Set the language and IO instances
80                 $tplInstance->setLanguageInstance($langInstance);
81                 $tplInstance->setFileIoInstance($ioInstance);
82
83                 // Set template extensions
84                 $tplInstance->setRawTemplateExtension($configInstance->getConfigEntry('raw_template_extension'));
85                 $tplInstance->setCodeTemplateExtension($configInstance->getConfigEntry('menu_template_extension'));
86
87                 // Absolute output path for compiled templates
88                 $tplInstance->setCompileOutputPath($configInstance->getConfigEntry('base_path') . $configInstance->getConfigEntry('compile_output_path'));
89
90                 // Return the prepared instance
91                 return $tplInstance;
92         }
93
94         /**
95          * Load a specified menu template into the engine
96          *
97          * @param       $template       The menu template we shall load which is
98          *                                              located in 'menu' by default
99          * @return      void
100          */
101         public function loadMenuTemplate ($template) {
102                 // Set template type
103                 $this->setTemplateType($this->getConfigInstance()->getConfigEntry('menu_template_type'));
104
105                 // Load the special template
106                 $this->loadTemplate($template);
107         }
108 }
109
110 // [EOF]
111 ?>