3 * A Console template engine class
5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Core Developer Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.ship-simu.org
10 * @todo This template engine does not make use of setTemplateType()
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 ConsoleTemplateEngine 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 $appInstance A manageable application
40 * @return $templateInstance An instance of TemplateEngine
41 * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
42 * @throws InvalidBasePathStringException If $templateBasePath is no string
43 * @throws BasePathIsNoDirectoryException If $templateBasePath is no
44 * directory or not found
45 * @throws BasePathReadProtectedException If $templateBasePath is
48 public final static function createConsoleTemplateEngine (ManageableApplication $appInstance) {
50 $templateInstance = new ConsoleTemplateEngine();
52 // Get language and file I/O instances from application
53 $langInstance = $appInstance->getLanguageInstance();
54 $ioInstance = $appInstance->getFileIoInstance();
56 // Determine base path
57 $templateBasePath = $templateInstance->getConfigInstance()->getConfigEntry('application_base_path') . $appInstance->getRequestInstance()->getRequestElement('app') . '/';
59 // Is the base path valid?
60 if (empty($templateBasePath)) {
62 throw new BasePathIsEmptyException($templateInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
63 } elseif (!is_string($templateBasePath)) {
65 throw new InvalidBasePathStringException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_STRING);
66 } elseif (!is_dir($templateBasePath)) {
68 throw new BasePathIsNoDirectoryException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME);
69 } elseif (!is_readable($templateBasePath)) {
71 throw new BasePathReadProtectedException(array($templateInstance, $templateBasePath), self::EXCEPTION_READ_PROTECED_PATH);
74 // Get configuration instance
75 $configInstance = FrameworkConfiguration::getInstance();
78 $templateInstance->setTemplateBasePath($templateBasePath);
80 // Set the language and IO instances
81 $templateInstance->setLanguageInstance($langInstance);
82 $templateInstance->setFileIoInstance($ioInstance);
84 // Set template extensions
85 $templateInstance->setRawTemplateExtension($configInstance->getConfigEntry('raw_template_extension'));
86 $templateInstance->setCodeTemplateExtension($configInstance->getConfigEntry('code_template_extension'));
88 // Absolute output path for compiled templates
89 $templateInstance->setCompileOutputPath($configInstance->getConfigEntry('base_path') . $configInstance->getConfigEntry('compile_output_path'));
91 // Return the prepared instance
92 return $templateInstance;