use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
+// Import SPL stuff
+use \InvalidArgumentException;
+
/**
* A factory class for communicator
*
* be generated and stored in registry, else the communicator from the
* registry will be returned.
*
- * @param $configEntry A configuration entry naming the real class' name
- * @parasm $communicatorType Type of the communicator, can currently be 'node'
+ * @param $configKey A configuration key naming the real class' name
+ * @parasm $communicatorType Type of the communicator, can currently be 'node'
* @return $communicatorInstance An instance of a Communicator class
*/
- public static final function createCommunicatorInstance ($configEntry, $communicatorType) {
+ public static final function createCommunicatorInstance (string $configKey, string $communicatorType) {
+ // Validate parameter
+ if (empty($configKey)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "configKey" is empty');
+ } elseif (empty($communicatorType)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "communicatorType" is empty');
+ }
+
// If there is no communicator?
if (GenericRegistry::getRegistry()->instanceExists($communicatorType . '_communicator')) {
// Get communicator from registry
$communicatorInstance = GenericRegistry::getRegistry()->getInstance($communicatorType . '_communicator');
} else {
// Get the communicator instance
- $communicatorInstance = ObjectFactory::createObjectByConfiguredName($configEntry);
+ $communicatorInstance = ObjectFactory::createObjectByConfiguredName($configKey);
// Add it to the registry
GenericRegistry::getRegistry()->addInstance($communicatorType . '_communicator', $communicatorInstance);
use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
+// Import SPL stuff
+use \InvalidArgumentException;
+
/**
* A factory class for DHT objects
*
* @param $prefix Prefix for DHT class name and registry key
* @return $dhtInstance An instance of a DHT object class
*/
- public static final function createDhtInstance ($prefix) {
+ public static final function createDhtInstance (string $prefix) {
+ // Validate parameter
+ if (empty($prefix)) {
+ // Throe IAE
+ throw new InvalidArgumentException('Parameter "prefix" is empty');
+ }
+
// Set instance name
$name = $prefix . '_dht';
* Returns a singleton (registry-based) ShareableInfo instance
*
* @param $protocolName Name of protocol (e.g. 'tcp')
- * @param $type Connection type ('incoming', 'server', 'helper', ...)
+ * @param $connectionType Connection type ('incoming', 'server', 'helper', ...)
* @return $infoInstance An instance of a ShareableInfo class
* @throws InvalidArgumentException If one of the arguments are not valid
* @todo Also validate protocol to be sure if there is really a protocol handler for it available
*/
- public static final function createConnectionInfoInstance (string $protocolName, string $type) {
+ public static final function createConnectionInfoInstance (string $protocolName, string $connectionType) {
// Init factory instance
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO-FACTORY: protocolName=%s,type=%s - CALLED!', $protocolName, $type));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO-FACTORY: protocolName=%s,connectionType=%s - CALLED!', $protocolName, $connectionType));
$factoryInstance = new ConnectionInfoFactory();
// Validate parameter ...
if (empty($protocolName)) {
// Empty parameter
- throw new InvalidArgumentException('Parameter "protocolName" cannot be empty.');
- } elseif (empty($type)) {
+ throw new InvalidArgumentException('Parameter "protocolName" is empty');
+ } elseif (empty($connectionType)) {
// Empty parameter
- throw new InvalidArgumentException('Parameter "type" cannot be empty.');
- } elseif (!in_array($type, self::$validTypes, TRUE)) {
+ throw new InvalidArgumentException('Parameter "connectionType" is empty');
+ } elseif (!in_array($connectionType, self::$validTypes, TRUE)) {
// Not valid type
- throw new InvalidArgumentException(sprintf('type=%s is not valid.', $type));
+ throw new InvalidArgumentException(sprintf('connectionType=%s is not valid.', $connectionType));
}
// Generate key
- $key = sprintf('connection_info_%s_%s', $protocolName, $type);
+ $key = sprintf('connection_info_%s_%s', $protocolName, $connectionType);
// If there is no info?
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO-FACTORY: key=%s', $key));
$infoInstance = GenericRegistry::getRegistry()->getInstance($key);
} else {
// Get the info instance
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO-FACTORY: Creating info instance for type=%s ...', $type));
- $infoInstance = ObjectFactory::createObjectByConfiguredName('connection_info_class', array($type));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO-FACTORY: Creating info instance for connectionType=%s ...', $connectionType));
+ $infoInstance = ObjectFactory::createObjectByConfiguredName('connection_info_class', array($connectionType));
// Add it to the registry
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO-FACTORY: Adding key=%s,infoInstance=%s ...', $key, $infoInstance->__toString()));
use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
+// Import SPL stuff
+use \InvalidArgumentException;
+
/**
* A factory class for fragmenter
*
* @param $fragmenterType The fragmenter's type
* @return $fragmenterInstance A fragmenter instance
*/
- public static final function createFragmenterInstance ($fragmenterType) {
+ public static final function createFragmenterInstance (string $fragmenterType) {
+ // Validate parameter
+ if (empty($fragmenterType)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "fragmenterType" is empty');
+ }
+
// If there is no fragmenter?
if (GenericRegistry::getRegistry()->instanceExists($fragmenterType . '_fragmenter')) {
// Get fragmenter from registry
* @parasm $producerType Type of the producer, can be 'key', 'test_unit', etc.
* @return $producerInstance A producer instance
*/
- public static final function createProducerInstance ($configEntry, $producerType) {
+ public static final function createProducerInstance (string $configEntry, string $producerType) {
// If there is no producer?
if (GenericRegistry::getRegistry()->instanceExists($producerType . '_producer')) {
// Get producer from registry
* @param $hash Previously generated hash for valdiation
* @return $isValid Whether the given hash matches a new one from given data
*/
- public function featureMethodCheckHash ($data, $hash) {
+ public function featureMethodCheckHash ($data, string $hash) {
// Make sure the feature is available
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: data()=%d,hash=%s - CALLED!', __METHOD__, __LINE__, strlen($data), $hash));
assert(FrameworkFeature::isFeatureAvailable('hubcoin_reward'));
* @param $listenerType The listener's type (hub/peer)
* @return void
*/
- protected final function setListenerType ($listenerType) {
+ protected final function setListenerType (string $listenerType) {
$this->listenerType = $listenerType;
}
* @param $version Version number of this miner
* @return void
*/
- protected final function setVersion ($version) {
- $this->version = (string) $version;
+ protected final function setVersion (string $version) {
+ $this->version = $version;
}
/**
* @throws DatabaseUpdateSupportException If this class does not support database updates
* @todo Try to make this method more generic so we can move it in BaseFrameworkSystem
*/
- public function updateDatabaseField ($fieldName, $fieldValue) {
+ public function updateDatabaseField (string $fieldName, $fieldValue) {
// Unfinished
$this->partialStub('Unfinished!');
return;
* @param $rawData Raw data
* @return void
*/
- public final function setRawData ($rawData) {
+ public final function setRawData (string $rawData) {
$this->rawData = $rawData;
}
// Return the prepared instance
return $sourceInstance;
}
-}
-// [EOF]
-?>
+}
* @throws InvalidSessionIdException If the provided session id is invalid (and no Universal Node Locator)
* @throws NoValidHostnameException If the provided hostname cannot be resolved into an IP address
*/
- public static function resolveSessionIdToUnl ($address) {
+ public static function resolveSessionIdToUnl (string $address) {
// Get an own instance
$selfInstance = self::getSelfInstance();
*
* @return void
*/
- private function __construct () {
+ protected function __construct () {
// Call parent constructor
parent::__construct(__CLASS__);
}
* @param $unl Universal Node Locator to validate
* @return $isValid Whether the UNL is valid
*/
- public static function isValidUniversalNodeLocator ($unl) {
+ public static function isValidUniversalNodeLocator (string $unl) {
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UNIVERSAL-NODE-LOCATOR: unl=' . $unl . ' - CALLED!');
* @param $code Error code
* @return void
*/
- public function __construct ($sessionId, $code) {
+ public function __construct (string $sessionId, int $code) {
// Construct the message
$message = sprintf('Session id %s is invalid.',
$sessionId
* @param $rawData Raw data
* @return void
*/
- function setRawData ($rawData);
+ function setRawData (string $rawData);
/**
* Getter for error code
* @param $configKey Key for address to get (valid: internal,external)
* @return $unl Universal node locator
*/
- function discoverUniversalNodeLocatorByConfiguredAddress ($configKey);
+ function discoverUniversalNodeLocatorByConfiguredAddress (string $configKey);
}
* @param $unl UNL string
* @return void
*/
- function parseStringAsUnl ($unl);
+ function parseStringAsUnl (string $unl);
}
* @param $poolType Pool type (e.g. 'socket_listen', 'network_listen')
* @return $iteratorInstance An instance of a Iterator class
*/
- function createListIteratorInstance ($poolType);
+ function createListIteratorInstance (string $poolType);
}
* @param $rawPackageContent The raw package content to be "decoded"
* @return $packageInstance An instance of a DeliverablePackage class
*/
- function decodeRawContent ($rawPackageContent);
+ function decodeRawContent (string $rawPackageContent);
/**
* Checks whether the assembler has pending data left
* @param $configKey Configuration key for UNL address (valid: internal,external)
* @return $unl Universal node locator
*/
- function resolveUniversalNodeLocatorFromConfigKey ($configKey);
+ function resolveUniversalNodeLocatorFromConfigKey (string $configKey);
}
* @return $isValid Whether the given state is valid
* @throws EmptyVariableException Thrown if given state is not set
*/
- function isStateValid ($stateName);
+ function isStateValid (string $stateName);
}