3 namespace CoreFramework\Template\Engine;
5 // Import framework stuff
6 use CoreFramework\Template\CompileableTemplate;
9 * A Console template engine class
11 * @author Roland Haeder <webmaster@shipsimu.org>
13 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
14 * @license GNU GPL 3.0 or any newer version
15 * @link http://www.shipsimu.org
16 * @todo This template engine does not make use of setTemplateType()
18 * This program is free software: you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation, either version 3 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 class ConsoleTemplateEngine extends BaseTemplateEngine implements CompileableTemplate {
33 * Protected constructor
37 protected function __construct () {
38 // Call parent constructor
39 parent::__construct(__CLASS__);
43 * Creates an instance of the class TemplateEngine and prepares it for usage
45 * @return $templateInstance An instance of TemplateEngine
46 * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
47 * @throws InvalidBasePathStringException If $templateBasePath is no string
48 * @throws BasePathIsNoDirectoryException If $templateBasePath is no
49 * directory or not found
50 * @throws BasePathReadProtectedException If $templateBasePath is
53 public static final function createConsoleTemplateEngine () {
55 $templateInstance = new ConsoleTemplateEngine();
57 // Get the application instance from registry
58 $applicationInstance = Registry::getRegistry()->getInstance('app');
60 // Determine base path
61 $templateBasePath = $templateInstance->getConfigInstance()->getConfigEntry('application_base_path') . $applicationInstance->getRequestInstance()->getRequestElement('app') . '/';
63 // Is the base path valid?
64 if (empty($templateBasePath)) {
66 throw new BasePathIsEmptyException($templateInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
67 } elseif (!is_string($templateBasePath)) {
69 throw new InvalidBasePathStringException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_STRING);
70 } elseif (!is_dir($templateBasePath)) {
72 throw new BasePathIsNoDirectoryException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME);
73 } elseif (!is_readable($templateBasePath)) {
75 throw new BasePathReadProtectedException(array($templateInstance, $templateBasePath), self::EXCEPTION_READ_PROTECED_PATH);
79 $templateInstance->setTemplateBasePath($templateBasePath);
81 // Set template extensions
82 $templateInstance->setRawTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('raw_template_extension'));
83 $templateInstance->setCodeTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('code_template_extension'));
85 // Absolute output path for compiled templates
86 $templateInstance->setCompileOutputPath($templateInstance->getConfigInstance()->getConfigEntry('base_path') . $templateInstance->getConfigInstance()->getConfigEntry('compile_output_path'));
88 // Return the prepared instance
89 return $templateInstance;