Continued:
[core.git] / inc / main / classes / factories / database / class_DatabaseWrapperFactory.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Factory\Database\Wrapper;
4
5 /**
6  * A factory class for socket registries
7  *
8  * @author              Roland Haeder <webmaster@shipsimu.org>
9  * @version             0.0.0
10  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
11  * @license             GNU GPL 3.0 or any newer version
12  * @link                http://www.shipsimu.org
13  *
14  * This program is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation, either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program. If not, see <http://www.gnu.org/licenses/>.
26  */
27 class DatabaseWrapperFactory extends ObjectFactory {
28         /**
29          * Protected constructor
30          *
31          * @return      void
32          */
33         protected function __construct () {
34                 // Call parent constructor
35                 parent::__construct(__CLASS__);
36         }
37
38         /**
39          * Returns a singleton socket registry instance. If an instance is found in
40          * the registry it will be returned, else a new instance is created and
41          * stored in the same registry entry.
42          *
43          * @return      $wrapperInstance        A database wrapper instance
44          */
45         public static final function createWrapperByConfiguredName ($wrapperName) {
46                 // Get registry instance
47                 $registryInstance = Registry::getRegistry();
48
49                 // Do we have an instance in the registry?
50                 if ($registryInstance->instanceExists($wrapperName)) {
51                         // Then use this instance
52                         $wrapperInstance = $registryInstance->getInstance($wrapperName);
53                 } else {
54                         // Get the registry instance
55                         $wrapperInstance = self::createObjectByConfiguredName($wrapperName);
56
57                         // Set the instance in registry for further use
58                         $registryInstance->addInstance($wrapperName, $wrapperInstance);
59                 }
60
61                 // Return the instance
62                 return $wrapperInstance;
63         }
64
65 }