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