// Import framework stuff
use Org\Mxchange\CoreFramework\Factory\BaseFactory;
use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
use Org\Mxchange\CoreFramework\Registry\Object\ObjectRegistry;
+// Import SPL stuff
+use \InvalidArgumentException;
+
/**
* A factory class for socket registries
*
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class DatabaseFrontendFactory extends BaseFactory {
+ /**
+ * "Cache" for frontend factory
+ */
+ private static $registryInstance = NULL;
+
/**
* Protected constructor
*
parent::__construct(__CLASS__);
}
+ /**
+ * Some "static initializer
+ *
+ * @return void
+ */
+ public final static function staticInitializer () {
+ // Is it initialized?
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('frontend-FACTORY: self::registryInstance[]=%s - CALLED!', gettype(self::$registryInstance)));
+ if (is_null(self::$registryInstance)) {
+ // No, then initialize it
+ self::$registryInstance = ObjectRegistry::getRegistry('factory');
+ }
+
+ // Trace message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('frontend-FACTORY: self::registryInstance=%s - EXIT!', self::$registryInstance));
+ }
+
/**
* Returns a singleton socket registry instance. If an instance is found in
* the registry it will be returned, else a new instance is created and
* @return $frontendInstance A database frontend instance
*/
public static final function createFrontendByConfiguredName (string $frontendName) {
- // Get registry instance
- $registryInstance = ObjectRegistry::getRegistry('factory');
+ // Check parameter
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DATABASE-FRONTEND-FACTORY: frontendName=%s - CALLED!', $frontendName));
+ if (empty($frontendName)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "frontendName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+ }
+
+ // Invoke "static initializer"
+ self::staticInitializer();
// Do we have an instance in the registry?
- if ($registryInstance->instanceExists($frontendName)) {
+ if (self::$registryInstance->instanceExists($frontendName)) {
// Then use this instance
- $frontendInstance = $registryInstance->getInstance($frontendName);
+ $frontendInstance = self::$registryInstance->getInstance($frontendName);
} else {
// Get the registry instance
$frontendInstance = ObjectFactory::createObjectByConfiguredName($frontendName);
// Set the instance in registry for further use
- $registryInstance->addInstance($frontendName, $frontendInstance);
+ self::$registryInstance->addInstance($frontendName, $frontendInstance);
}
// Return the instance
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DATABASE-FRONTEND-FACTORY: frontendInstance=%s - EXIT!', $frontendInstance->__toString()));
return $frontendInstance;
}