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