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