Continued:
[core.git] / inc / main / classes / factories / xml / class_XmlTemplateEngineFactory.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Factory\Template;
4
5 /**
6  * A factory class for XML template engines. All instances generated by this
7  * factory does have language support disabled and XML-compacting enabled (to
8  * save memory/network load).
9  *
10  * @author              Roland Haeder <webmaster@shipsimu.org>
11  * @version             0.0.0
12  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
13  * @license             GNU GPL 3.0 or any newer version
14  * @link                http://www.shipsimu.org
15  *
16  * This program is free software: you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation, either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program. If not, see <http://www.gnu.org/licenses/>.
28  */
29 class XmlTemplateEngineFactory extends ObjectFactory {
30         /**
31          * Protected constructor
32          *
33          * @return      void
34          */
35         protected function __construct () {
36                 // Call parent constructor
37                 parent::__construct(__CLASS__);
38         }
39
40         /**
41          * Returns a singleton network package instance. If an instance is found in
42          * the registry it will be returned, else a new instance is created and
43          * stored in the same registry entry.
44          *
45          * @param       $configEntry            Config entry name for the template engine
46          * @return      $templateInstance       A template engine instance
47          */
48         public static final function createXmlTemplateEngineInstance ($configEntry) {
49                 // Do we have an instance in the registry?
50                 if (Registry::getRegistry()->instanceExists($configEntry)) {
51                         // Then use this instance
52                         $templateInstance = Registry::getRegistry()->getInstance($configEntry);
53                 } else {
54                         // Now prepare the tags instance
55                         $templateInstance = ObjectFactory::createObjectByConfiguredName($configEntry);
56
57                         // Disable language support
58                         $templateInstance->enableLanguageSupport(FALSE);
59
60                         /*
61                          * Enable compacting/rewriting of the  XML to save bandwidth from XML
62                          * comments. This is expensive and should be avoided in general.
63                          */
64                         $templateInstance->enableXmlCompacting();
65
66                         // Set the instance in registry for further use
67                         Registry::getRegistry()->addInstance($configEntry, $templateInstance);
68                 }
69
70                 // Return the instance
71                 return $templateInstance;
72         }
73
74 }