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