3 namespace Org\Mxchange\CoreFramework\Factory\Template;
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;
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).
15 * @author Roland Haeder <webmaster@shipsimu.org>
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
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.
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.
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/>.
34 class XmlTemplateEngineFactory extends BaseFactory {
36 * Protected constructor
40 protected function __construct () {
41 // Call parent constructor
42 parent::__construct(__CLASS__);
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.
50 * @param $configKey Config entry name for the template engine
51 * @return $templateInstance A template engine instance
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);
59 // Get the XML template instance
60 $templateInstance = ObjectFactory::createObjectByConfiguredName($configKey);
62 // Disable language support
63 $templateInstance->enableLanguageSupport(false);
66 * Enable compacting/rewriting of the XML to save bandwidth from XML
67 * comments. This is expensive and should be avoided in general.
69 $templateInstance->enableXmlCompacting();
71 // Set the instance in registry for further use
72 GenericRegistry::getRegistry()->addInstance($configKey, $templateInstance);
75 // Return the instance
76 return $templateInstance;