]> git.mxchange.org Git - shipsimu.git/blob - inc/classes/main/template/web/class_WebTemplateEngine.php
Image generator added, first CAPTCHA added with missing controller (partly work)
[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                 // Clean up a little
42                 $this->removeNumberFormaters();
43                 $this->removeSystemArray();
44         }
45
46         /**
47          * Creates an instance of the class TemplateEngine and prepares it for usage
48          *
49          * @param       $basePath               The local base path for all templates
50          * @param       $langInstance   An instance of LanguageSystem (default)
51          * @param       $ioInstance             An instance of FileIoHandler (default, middleware!)
52          * @return      $tplInstance    An instance of TemplateEngine
53          * @throws      BasePathIsEmptyException                If the provided $basePath is empty
54          * @throws      InvalidBasePathStringException  If $basePath is no string
55          * @throws      BasePathIsNoDirectoryException  If $basePath is no
56          *                                                                                      directory or not found
57          * @throws      BasePathReadProtectedException  If $basePath is
58          *                                                                                      read-protected
59          */
60         public final static function createWebTemplateEngine ($basePath, ManageableLanguage  $langInstance, FileIoHandler $ioInstance) {
61                 // Get a new instance
62                 $tplInstance = new WebTemplateEngine();
63
64                 // Is the base path valid?
65                 if (empty($basePath)) {
66                         // Base path is empty
67                         throw new BasePathIsEmptyException($tplInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
68                 } elseif (!is_string($basePath)) {
69                         // Is not a string
70                         throw new InvalidBasePathStringException(array($tplInstance, $basePath), self::EXCEPTION_INVALID_STRING);
71                 } elseif (!is_dir($basePath)) {
72                         // Is not a path
73                         throw new BasePathIsNoDirectoryException(array($tplInstance, $basePath), self::EXCEPTION_INVALID_PATH_NAME);
74                 } elseif (!is_readable($basePath)) {
75                         // Is not readable
76                         throw new BasePathReadProtectedException(array($tplInstance, $basePath), self::EXCEPTION_READ_PROTECED_PATH);
77                 }
78
79                 // Get configuration instance
80                 $cfgInstance = FrameworkConfiguration::getInstance();
81
82                 // Set the base path
83                 $tplInstance->setBasePath($basePath);
84
85                 // Set the language and IO instances
86                 $tplInstance->setLanguageInstance($langInstance);
87                 $tplInstance->setFileIoInstance($ioInstance);
88
89                 // Set template extensions
90                 $tplInstance->setRawTemplateExtension($cfgInstance->readConfig('raw_template_extension'));
91                 $tplInstance->setCodeTemplateExtension($cfgInstance->readConfig('code_template_extension'));
92
93                 // Absolute output path for compiled templates
94                 $tplInstance->setCompileOutputPath(PATH . $cfgInstance->readConfig('compile_output_path'));
95
96                 // Return the prepared instance
97                 return $tplInstance;
98         }
99 }
100
101 // [EOF]
102 ?>