3 * The own template engine for loading caching and sending out the web pages
6 * @author Roland Haeder <webmaster@ship-simu.org>
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
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.
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.
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/>.
25 class WebTemplateEngine extends BaseTemplateEngine implements CompileableTemplate {
27 * Protected constructor
31 protected function __construct () {
32 // Call parent constructor
33 parent::__construct(__CLASS__);
37 * Creates an instance of the class TemplateEngine and prepares it for usage
39 * @param $basePath The local base path for all templates
40 * @param $langInstance An instance of LanguageSystem (default)
41 * @param $ioInstance An instance of FileIoHandler (default, middleware!)
42 * @return $tplInstance An instance of TemplateEngine
43 * @throws BasePathIsEmptyException If the provided $basePath is empty
44 * @throws InvalidBasePathStringException If $basePath is no string
45 * @throws BasePathIsNoDirectoryException If $basePath is no
46 * directory or not found
47 * @throws BasePathReadProtectedException If $basePath is
50 public final static function createWebTemplateEngine ($basePath, ManageableLanguage $langInstance, FileIoHandler $ioInstance) {
52 $tplInstance = new WebTemplateEngine();
54 // Is the base path valid?
55 if (empty($basePath)) {
57 throw new BasePathIsEmptyException($tplInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
58 } elseif (!is_string($basePath)) {
60 throw new InvalidBasePathStringException(array($tplInstance, $basePath), self::EXCEPTION_INVALID_STRING);
61 } elseif (!is_dir($basePath)) {
63 throw new BasePathIsNoDirectoryException(array($tplInstance, $basePath), self::EXCEPTION_INVALID_PATH_NAME);
64 } elseif (!is_readable($basePath)) {
66 throw new BasePathReadProtectedException(array($tplInstance, $basePath), self::EXCEPTION_READ_PROTECED_PATH);
69 // Get configuration instance
70 $cfgInstance = FrameworkConfiguration::getInstance();
73 $tplInstance->setBasePath($basePath);
75 // Set the language and IO instances
76 $tplInstance->setLanguageInstance($langInstance);
77 $tplInstance->setFileIoInstance($ioInstance);
79 // Set template extensions
80 $tplInstance->setRawTemplateExtension($cfgInstance->readConfig('raw_template_extension'));
81 $tplInstance->setCodeTemplateExtension($cfgInstance->readConfig('code_template_extension'));
83 // Absolute output path for compiled templates
84 $tplInstance->setCompileOutputPath($cfgInstance->readConfig('base_path') . $cfgInstance->readConfig('compile_output_path'));
86 // Return the prepared instance