3 namespace CoreFramework\Template\Engine;
5 // Import framework stuff
6 use CoreFramework\Registry\Registry;
7 use CoreFramework\Template\CompileableTemplate;
10 * The own template engine for loading caching and sending out the web pages
13 * @author Roland Haeder <webmaster@shipsimu.org>
15 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
16 * @license GNU GPL 3.0 or any newer version
17 * @link http://www.shipsimu.org
19 * This program is free software: you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation, either version 3 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 class HtmlTemplateEngine extends BaseTemplateEngine implements CompileableTemplate {
34 * Protected constructor
38 protected function __construct () {
39 // Call parent constructor
40 parent::__construct(__CLASS__);
44 * Creates an instance of the class TemplateEngine and prepares it for usage
46 * @return $templateInstance An instance of TemplateEngine
47 * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
48 * @throws InvalidBasePathStringException If $templateBasePath is no string
49 * @throws BasePathIsNoDirectoryException If $templateBasePath is no
50 * directory or not found
51 * @throws BasePathReadProtectedException If $templateBasePath is
54 public static final function createHtmlTemplateEngine () {
56 $templateInstance = new HtmlTemplateEngine();
58 // Get the application instance from registry
59 $applicationInstance = Registry::getRegistry()->getInstance('app');
61 // Determine base path
62 $templateBasePath = $templateInstance->getConfigInstance()->getConfigEntry('application_base_path') . $applicationInstance->getRequestInstance()->getRequestElement('app') . '/';
64 // Is the base path valid?
65 if (empty($templateBasePath)) {
67 throw new BasePathIsEmptyException($templateInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
68 } elseif (!is_string($templateBasePath)) {
70 throw new InvalidBasePathStringException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_STRING);
71 } elseif (!is_dir($templateBasePath)) {
73 throw new BasePathIsNoDirectoryException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME);
74 } elseif (!is_readable($templateBasePath)) {
76 throw new BasePathReadProtectedException(array($templateInstance, $templateBasePath), self::EXCEPTION_READ_PROTECED_PATH);
80 $templateInstance->setTemplateBasePath($templateBasePath);
82 // Set template extensions
83 $templateInstance->setRawTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('raw_template_extension'));
84 $templateInstance->setCodeTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('code_template_extension'));
86 // Absolute output path for compiled templates
87 $templateInstance->setCompileOutputPath($templateInstance->getConfigInstance()->getConfigEntry('base_path') . $templateInstance->getConfigInstance()->getConfigEntry('compile_output_path'));
89 // Return the prepared instance
90 return $templateInstance;