Packager script for latest dev version added, misc fixes, captcha verifier filter...
[shipsimu.git] / inc / classes / main / template / web / class_WebTemplateEngine.php
1 <?php
2 /**
3  * The own template engine for loading caching and sending out the web pages
4  * and emails.
5  *
6  * @author              Roland Haeder <webmaster@ship-simu.org>
7  * @version             0.0.0
8  * @copyright   Copyright(c) 2007, 2008 Roland Haeder, this is free software
9  * @license             GNU GPL 3.0 or any newer version
10  * @link                http://www.ship-simu.org
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 WebTemplateEngine extends BaseTemplateEngine implements CompileableTemplate {
26         /**
27          * Protected constructor
28          *
29          * @return      void
30          */
31         protected function __construct () {
32                 // Call parent constructor
33                 parent::__construct(__CLASS__);
34
35                 // Set part description
36                 $this->setObjectDescription("Web template engine");
37
38                 // Create unique ID number
39                 $this->generateUniqueId();
40         }
41
42         /**
43          * Creates an instance of the class TemplateEngine and prepares it for usage
44          *
45          * @param       $basePath               The local base path for all templates
46          * @param       $langInstance   An instance of LanguageSystem (default)
47          * @param       $ioInstance             An instance of FileIoHandler (default, middleware!)
48          * @return      $tplInstance    An instance of TemplateEngine
49          * @throws      BasePathIsEmptyException                If the provided $basePath is empty
50          * @throws      InvalidBasePathStringException  If $basePath is no string
51          * @throws      BasePathIsNoDirectoryException  If $basePath is no
52          *                                                                                      directory or not found
53          * @throws      BasePathReadProtectedException  If $basePath is
54          *                                                                                      read-protected
55          */
56         public final static function createWebTemplateEngine ($basePath, ManageableLanguage  $langInstance, FileIoHandler $ioInstance) {
57                 // Get a new instance
58                 $tplInstance = new WebTemplateEngine();
59
60                 // Is the base path valid?
61                 if (empty($basePath)) {
62                         // Base path is empty
63                         throw new BasePathIsEmptyException($tplInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
64                 } elseif (!is_string($basePath)) {
65                         // Is not a string
66                         throw new InvalidBasePathStringException(array($tplInstance, $basePath), self::EXCEPTION_INVALID_STRING);
67                 } elseif (!is_dir($basePath)) {
68                         // Is not a path
69                         throw new BasePathIsNoDirectoryException(array($tplInstance, $basePath), self::EXCEPTION_INVALID_PATH_NAME);
70                 } elseif (!is_readable($basePath)) {
71                         // Is not readable
72                         throw new BasePathReadProtectedException(array($tplInstance, $basePath), self::EXCEPTION_READ_PROTECED_PATH);
73                 }
74
75                 // Get configuration instance
76                 $cfgInstance = FrameworkConfiguration::getInstance();
77
78                 // Set the base path
79                 $tplInstance->setBasePath($basePath);
80
81                 // Set the language and IO instances
82                 $tplInstance->setLanguageInstance($langInstance);
83                 $tplInstance->setFileIoInstance($ioInstance);
84
85                 // Set template extensions
86                 $tplInstance->setRawTemplateExtension($cfgInstance->readConfig('raw_template_extension'));
87                 $tplInstance->setCodeTemplateExtension($cfgInstance->readConfig('code_template_extension'));
88
89                 // Absolute output path for compiled templates
90                 $tplInstance->setCompileOutputPath(PATH . $cfgInstance->readConfig('compile_output_path'));
91
92                 // Return the prepared instance
93                 return $tplInstance;
94         }
95 }
96
97 // [EOF]
98 ?>