3 namespace Org\Mxchange\CoreFramework\Template\Engine;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Filesystem\InvalidDirectoryException;
7 use Org\Mxchange\CoreFramework\Registry\Registry;
8 use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
9 use Org\Mxchange\CoreFramework\Template\Engine\BaseTemplateEngine;
12 use \UnexpectedValueException;
15 * A Console template engine class
17 * @author Roland Haeder <webmaster@shipsimu.org>
19 <<<<<<< HEAD:framework/main/classes/template/console/class_ConsoleTemplateEngine.php
20 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
22 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
23 >>>>>>> Some updates::inc/main/classes/template/console/class_ConsoleTemplateEngine.php
24 * @license GNU GPL 3.0 or any newer version
25 * @link http://www.shipsimu.org
26 * @todo This template engine does not make use of setTemplateType()
28 * This program is free software: you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation, either version 3 of the License, or
31 * (at your option) any later version.
33 * This program is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 * GNU General Public License for more details.
38 * You should have received a copy of the GNU General Public License
39 * along with this program. If not, see <http://www.gnu.org/licenses/>.
41 class ConsoleTemplateEngine extends BaseTemplateEngine implements CompileableTemplate {
43 * Protected constructor
47 protected function __construct () {
48 // Call parent constructor
49 parent::__construct(__CLASS__);
53 * Creates an instance of the class TemplateEngine and prepares it for usage
55 * @return $templateInstance An instance of TemplateEngine
56 * @throws UnexpectedValueException If the provided $templateBasePath is empty or no string
57 * @throws InvalidDirectoryException If $templateBasePath is no
58 * directory or not found
59 * @throws BasePathReadProtectedException If $templateBasePath is
62 public static final function createConsoleTemplateEngine () {
64 $templateInstance = new ConsoleTemplateEngine();
66 // Get the application instance from registry
67 $applicationInstance = Registry::getRegistry()->getInstance('app');
69 // Determine base path
70 $templateBasePath = $templateInstance->getConfigInstance()->getConfigEntry('application_base_path') . $applicationInstance->getAppShortName(). '/';
72 // Is the base path valid?
73 if (empty($templateBasePath)) {
75 throw new UnexpectedValueException(sprintf('[%s:%d] Variable templateBasePath is empty.', $templateInstance->__toString(), __LINE__), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
76 } elseif (!is_string($templateBasePath)) {
78 throw new UnexpectedValueException(sprintf('[%s:%d] %s is not a string with a base path.', $templateInstance->__toString(), __LINE__, $templateBasePath), self::EXCEPTION_INVALID_STRING);
79 } elseif (!is_dir($templateBasePath)) {
81 throw new InvalidDirectoryException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME);
82 } elseif (!is_readable($templateBasePath)) {
84 throw new BasePathReadProtectedException(array($templateInstance, $templateBasePath), self::EXCEPTION_READ_PROTECED_PATH);
88 $templateInstance->setTemplateBasePath($templateBasePath);
90 // Set template extensions
91 $templateInstance->setRawTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('raw_template_extension'));
92 $templateInstance->setCodeTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('code_template_extension'));
94 // Absolute output path for compiled templates
95 $templateInstance->setCompileOutputPath(sprintf('%s%s/',
97 $templateInstance->getConfigInstance()->getConfigEntry('compile_output_path')
100 // Return the prepared instance
101 return $templateInstance;