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__);
35 // Set part description
36 $this->setObjectDescription("Web template engine");
38 // Create unique ID number
39 $this->generateUniqueId();
42 $this->removeNumberFormaters();
43 $this->removeSystemArray();
47 * Creates an instance of the class TemplateEngine and prepares it for usage
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
60 public final static function createWebTemplateEngine ($basePath, ManageableLanguage $langInstance, FileIoHandler $ioInstance) {
62 $tplInstance = new WebTemplateEngine();
64 // Is the base path valid?
65 if (empty($basePath)) {
67 throw new BasePathIsEmptyException($tplInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
68 } elseif (!is_string($basePath)) {
70 throw new InvalidBasePathStringException(array($tplInstance, $basePath), self::EXCEPTION_INVALID_STRING);
71 } elseif (!is_dir($basePath)) {
73 throw new BasePathIsNoDirectoryException(array($tplInstance, $basePath), self::EXCEPTION_INVALID_PATH_NAME);
74 } elseif (!is_readable($basePath)) {
76 throw new BasePathReadProtectedException(array($tplInstance, $basePath), self::EXCEPTION_READ_PROTECED_PATH);
79 // Get configuration instance
80 $cfgInstance = FrameworkConfiguration::getInstance();
83 $tplInstance->setBasePath($basePath);
85 // Set the language and IO instances
86 $tplInstance->setLanguageInstance($langInstance);
87 $tplInstance->setFileIoInstance($ioInstance);
89 // Set template extensions
90 $tplInstance->setRawTemplateExtension($cfgInstance->readConfig('raw_template_extension'));
91 $tplInstance->setCodeTemplateExtension($cfgInstance->readConfig('code_template_extension'));
93 // Absolute output path for compiled templates
94 $tplInstance->setCompileOutputPath(PATH . $cfgInstance->readConfig('compile_output_path'));
96 // Return the prepared instance