3 namespace Org\Mxchange\CoreFramework\Registry;
6 * A registry for several data types and objects. Objects should be added by
7 * addInstance() and therefore must implement the interface Registerable.
9 * @author Roland Haeder <webmaster@shipsimu.org>
11 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
12 * @license GNU GPL 3.0 or any newer version
13 * @link http://www.shipsimu.org
15 * This program is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 class GenericRegistry extends BaseRegistry implements Register {
30 * Instance of this class
32 private static $registryInstance = NULL;
35 * Protected constructor
39 private function __construct () {
40 // Call parent constructor
41 parent::__construct(__CLASS__);
45 * Singleton getter for self instance. This class has no factory pattern
46 * because here is no need for special parameters.
48 * @param $key Key for for this instance
49 * @return $registryInstance Instance of this class
50 * @throws InvalidArgumentException If a parameter has an invalid value
52 public static final function getRegistry (string $key) {
54 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('OBJECT-REGISTRY: key=%s - CALLED!', $key));
57 throw new InvalidArgumentException('Parameter "key" is empty');
60 // Is an instance there?
61 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('OBJECT-REGISTRY: self::registryInstance[%s][]=%s', $key, gettype(self::$registryInstances[$key])));
62 if (is_null(self::$registryInstances[$key])) {
63 // Not yet, so create one
64 self::$registryInstances[$key] = new ObjectRegistry();
67 // Return the instance
68 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('OBJECT-REGISTRY: self::registryInstance[%s]=%s - EXIT!', $key, self::$registryInstances[$key]->__toString()));
69 return self::$registryInstances[$key];