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