3 namespace Org\Mxchange\CoreFramework\Factory\Database\Frontend;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Factory\BaseFactory;
7 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
8 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
9 use Org\Mxchange\CoreFramework\Registry\Object\ObjectRegistry;
12 use \InvalidArgumentException;
15 * A factory class for socket registries
17 * @author Roland Haeder <webmaster@shipsimu.org>
19 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
20 * @license GNU GPL 3.0 or any newer version
21 * @link http://www.shipsimu.org
23 * This program is free software: you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation, either version 3 of the License, or
26 * (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with this program. If not, see <http://www.gnu.org/licenses/>.
36 class DatabaseFrontendFactory extends BaseFactory {
38 * "Cache" for frontend factory
40 private static $registryInstance = NULL;
43 * Protected constructor
47 private function __construct () {
48 // Call parent constructor
49 parent::__construct(__CLASS__);
53 * Some "static initializer
57 public final static function staticInitializer () {
59 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('frontend-FACTORY: self::registryInstance[]=%s - CALLED!', gettype(self::$registryInstance)));
60 if (is_null(self::$registryInstance)) {
61 // No, then initialize it
62 self::$registryInstance = ObjectRegistry::getRegistry('factory');
66 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('frontend-FACTORY: self::registryInstance=%s - EXIT!', self::$registryInstance));
70 * Returns a singleton socket registry instance. If an instance is found in
71 * the registry it will be returned, else a new instance is created and
72 * stored in the same registry entry.
74 * @return $frontendInstance A database frontend instance
76 public static final function createFrontendByConfiguredName (string $frontendName) {
78 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DATABASE-FRONTEND-FACTORY: frontendName=%s - CALLED!', $frontendName));
79 if (empty($frontendName)) {
81 throw new InvalidArgumentException('Parameter "frontendName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
84 // Invoke "static initializer"
85 self::staticInitializer();
87 // Do we have an instance in the registry?
88 if (self::$registryInstance->instanceExists($frontendName)) {
89 // Then use this instance
90 $frontendInstance = self::$registryInstance->getInstance($frontendName);
92 // Get the registry instance
93 $frontendInstance = ObjectFactory::createObjectByConfiguredName($frontendName);
95 // Set the instance in registry for further use
96 self::$registryInstance->addInstance($frontendName, $frontendInstance);
99 // Return the instance
100 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DATABASE-FRONTEND-FACTORY: frontendInstance=%s - EXIT!', $frontendInstance->__toString()));
101 return $frontendInstance;