]> git.mxchange.org Git - core.git/blob - inc/main/classes/template/html/class_HtmlTemplateEngine.php
Continued:
[core.git] / inc / main / classes / template / html / class_HtmlTemplateEngine.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Template\Engine;
4
5 // Import framework stuff
6 use CoreFramework\Template\CompileableTemplate;
7
8 /**
9  * The own template engine for loading caching and sending out the web pages
10  * and emails.
11  *
12  * @author              Roland Haeder <webmaster@shipsimu.org>
13  * @version             0.0.0
14  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
15  * @license             GNU GPL 3.0 or any newer version
16  * @link                http://www.shipsimu.org
17  *
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.
22  *
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.
27  *
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/>.
30  */
31 class HtmlTemplateEngine extends BaseTemplateEngine implements CompileableTemplate {
32         /**
33          * Protected constructor
34          *
35          * @return      void
36          */
37         protected function __construct () {
38                 // Call parent constructor
39                 parent::__construct(__CLASS__);
40         }
41
42         /**
43          * Creates an instance of the class TemplateEngine and prepares it for usage
44          *
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
51          *                                                                                      read-protected
52          */
53         public static final function createHtmlTemplateEngine () {
54                 // Get a new instance
55                 $templateInstance = new HtmlTemplateEngine();
56
57                 // Get the application instance from registry
58                 $applicationInstance = Registry::getRegistry()->getInstance('app');
59
60                 // Determine base path
61                 $templateBasePath = $templateInstance->getConfigInstance()->getConfigEntry('application_base_path') . $applicationInstance->getRequestInstance()->getRequestElement('app') . '/';
62
63                 // Is the base path valid?
64                 if (empty($templateBasePath)) {
65                         // Base path is empty
66                         throw new BasePathIsEmptyException($templateInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
67                 } elseif (!is_string($templateBasePath)) {
68                         // Is not a string
69                         throw new InvalidBasePathStringException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_STRING);
70                 } elseif (!is_dir($templateBasePath)) {
71                         // Is not a path
72                         throw new BasePathIsNoDirectoryException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME);
73                 } elseif (!is_readable($templateBasePath)) {
74                         // Is not readable
75                         throw new BasePathReadProtectedException(array($templateInstance, $templateBasePath), self::EXCEPTION_READ_PROTECED_PATH);
76                 }
77
78                 // Set the base path
79                 $templateInstance->setTemplateBasePath($templateBasePath);
80
81                 // Set template extensions
82                 $templateInstance->setRawTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('raw_template_extension'));
83                 $templateInstance->setCodeTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('code_template_extension'));
84
85                 // Absolute output path for compiled templates
86                 $templateInstance->setCompileOutputPath($templateInstance->getConfigInstance()->getConfigEntry('base_path') . $templateInstance->getConfigInstance()->getConfigEntry('compile_output_path'));
87
88                 // Return the prepared instance
89                 return $templateInstance;
90         }
91
92 }