// Is the call-back method there?
if (!method_exists($this, $handlerName)) {
// Please implement this
- throw new UnsupportedSocketErrorHandlerException(array($this, $handlerName, $errorCode), BaseConnectionHelper::EXCEPTION_UNSUPPORTED_ERROR_HANDLER);
+ throw new UnsupportedSocketErrorHandlerException([$this, $handlerName, $errorCode], BaseConnectionHelper::EXCEPTION_UNSUPPORTED_ERROR_HANDLER);
}
// Return it
// Is the node registered?
if ($this->isNodeRegistered($nodeData)) {
// Throw an exception
- throw new NodeAlreadyRegisteredException(array($this, $nodeData), self::EXCEPTION_NODE_ALREADY_REGISTERED);
+ throw new NodeAlreadyRegisteredException([$this, $nodeData], self::EXCEPTION_NODE_ALREADY_REGISTERED);
}
// @TODO Unimplemented part
// Is the node registered?
if (!$this->isNodeRegistered($nodeData)) {
// No, then throw an exception
- throw new NodeDataMissingException(array($this, $nodeData), self::EXCEPTION_NODE_NOT_REGISTERED);
+ throw new NodeDataMissingException([$this, $nodeData], self::EXCEPTION_NODE_NOT_REGISTERED);
}
// Get a search instance
// Make sure only new peers can be registered with package data
if (!$this->isSenderNewPeer($packageInstance)) {
// Throw an exception because this should normally not happen
- throw new PeerAlreadyRegisteredException(array($this, $packageInstance), self::EXCEPTION_PEER_ALREADY_REGISTERED);
+ throw new PeerAlreadyRegisteredException([$this, $packageInstance], self::EXCEPTION_PEER_ALREADY_REGISTERED);
}
// Generate a dataset instance
* Do not register non-existent nodes here. This is maybe fatal,
* caused by "stolen" session id and/or not matching address.
*/
- throw new NodeSessionIdVerficationException(array($this, $messageInstance), DistributableNode::EXCEPTION_NODE_SESSION_ID_NOT_VERIFYING);
+ throw new NodeSessionIdVerficationException([$this, $messageInstance], DistributableNode::EXCEPTION_NODE_SESSION_ID_NOT_VERIFYING);
}
// Save last exception
use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
+// Import SPL stuff
+use \InvalidArgumentException;
+
/**
* A factory class for communicator states
*
}
// Get a class from that configuration entry
- $stateInstance = ObjectFactory::createObjectByConfiguredName('node_' . $stateName . '_state_class', array($nodeInstance));
+ $stateInstance = ObjectFactory::createObjectByConfiguredName('node_' . $stateName . '_state_class', [$nodeInstance]);
// Debug message
self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-STATE-FACTORY: Node state has changed from ' . $nodeInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: chunkSplits()=%d - CALLED!', count($chunkSplits)));
if (isset($this->finalPackageChunks[$chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL]])) {
// Then throw an exception
- throw new ChunkAlreadyAssembledException(array($this, $chunkSplits), HandleableChunks::EXCEPTION_CHUNK_ALREADY_ASSEMBLED);
+ throw new ChunkAlreadyAssembledException([$this, $chunkSplits], HandleableChunks::EXCEPTION_CHUNK_ALREADY_ASSEMBLED);
}
// Add the chunk data (index 2) to the final array and use the serial number as index
try {
// Validate final chunk
$this->isFinalChunkValid($chunks);
- } catch (AssertionException $e) {
+ } catch (AssertionException $exception) {
// Last chunk is not valid
- throw new FinalChunkVerificationException(array($this, $chunks, $e), self::EXCEPTION_FINAL_CHUNK_VERIFICATION);
+ throw new FinalChunkVerificationException([$this, $chunks, $exception], self::EXCEPTION_FINAL_CHUNK_VERIFICATION);
}
// Do we have some pending chunks (no final)?
* This node is not accepting announcements, then someone wants to
* announce his node to a non-bootstrap and non-master node.
*/
- throw new AnnouncementNotAcceptedException(array($this, $nodeInstance, $messageInstance), HandleableMessage::EXCEPTION_ANNOUNCEMENT_NOT_ACCEPTED);
+ throw new AnnouncementNotAcceptedException([$this, $nodeInstance, $messageInstance], HandleableMessage::EXCEPTION_ANNOUNCEMENT_NOT_ACCEPTED);
}
// Register the announcing node with this node
* This node has never announced itself, so it doesn't expect
* announcement answer messages.
*/
- throw new NoAnnouncementAttemptedException(array($this, $nodeInstance, $messageInstance), HandleableMessage::EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED);
+ throw new NoAnnouncementAttemptedException([$this, $nodeInstance, $messageInstance], HandleableMessage::EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED);
}
// Register the announcing node with this node
* This DHT has never bootstrapped, so it doesn't expect
* announcement answer messages.
*/
- throw new NoDhtBootstrapAttemptedException(array($this, $dhtInstance, $messageInstance), HandleableMessage::EXCEPTION_DHT_BOOTSTRAP_NOT_ATTEMPTED);
+ throw new NoDhtBootstrapAttemptedException([$this, $dhtInstance, $messageInstance], HandleableMessage::EXCEPTION_DHT_BOOTSTRAP_NOT_ATTEMPTED);
}
// Unfinished
* This node has never announced itself, so it doesn't expect
* request-node-list answer messages.
*/
- throw new NoRequestNodeListAttemptedException(array($this, $nodeInstance, $messageInstance), HandleableMessage::EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED);
+ throw new NoRequestNodeListAttemptedException([$this, $nodeInstance, $messageInstance], HandleableMessage::EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED);
}
// Register the announcing node with this node
/*
* This node is not accepting DHT bootstrap requests.
*/
- throw new DhtBootstrapNotAcceptedException(array($this, $messageInstance), HandleableMessage::EXCEPTION_DHT_BOOTSTRAP_NOT_ACCEPTED);
+ throw new DhtBootstrapNotAcceptedException([$this, $messageInstance], HandleableMessage::EXCEPTION_DHT_BOOTSTRAP_NOT_ACCEPTED);
}
// Register the DHT bootstrap requesting node with this node
* This node is not accepting node list requests. Throw an
* exception to abort any further processing.
*/
- throw new RequestNotAcceptedException(array($this, $nodeInstance, $messageInstance), HandleableMessage::EXCEPTION_REQUEST_NOT_ACCEPTED);
+ throw new RequestNotAcceptedException([$this, $nodeInstance, $messageInstance], HandleableMessage::EXCEPTION_REQUEST_NOT_ACCEPTED);
}
// Register the announcing node with this node
// Is the package status 'failed'?
if ($packageInstance->getPackageStatus() != self::PACKAGE_STATUS_FAILED) {
// Not failed!
- throw new UnexpectedPackageStatusException(array($this, $packageInstance, self::PACKAGE_STATUS_FAILED), self::EXCEPTION_UNEXPECTED_PACKAGE_STATUS);
+ throw new UnexpectedPackageStatusException([$this, $packageInstance, self::PACKAGE_STATUS_FAILED], self::EXCEPTION_UNEXPECTED_PACKAGE_STATUS);
}
// Remove this entry
throw new InvalidArgumentException('messageInstance does not contain senderId');
} elseif (empty($messageInstance->getSenderPrivateKeyHash())) {
// This needs fixing
- throw new InvalidPrivateKeyHashException(array($this, $senderData, 'empty hash in decodedData'), DiscoverableUniversalNodeLocator::EXCEPTION_INVALID_PRIVATE_KEY_HASH);
+ throw new InvalidPrivateKeyHashException([$this, $senderData, 'empty hash in decodedData'], DiscoverableUniversalNodeLocator::EXCEPTION_INVALID_PRIVATE_KEY_HASH);
} elseif (!$this->isMessageContentHashValid($messageInstance)) {
// Is not valid, so throw an exception here
ApplicationEntryPoint::exitApplication(__METHOD__ . ':INVALID HASH! UNDER CONSTRUCTION!' . PHP_EOL);
throw new InvalidArgumentException('packageInstance does not contain senderId');
} elseif (empty($packageInstance->getSenderPrivateKeyHash())) {
// This needs fixing
- throw new InvalidPrivateKeyHashException(array($this, $senderData, 'empty hash in decodedData'), DiscoverableUniversalNodeLocator::EXCEPTION_INVALID_PRIVATE_KEY_HASH);
+ throw new InvalidPrivateKeyHashException([$this, $senderData, 'empty hash in decodedData'], DiscoverableUniversalNodeLocator::EXCEPTION_INVALID_PRIVATE_KEY_HASH);
} elseif (!$this->isPackageContentHashValid($packageInstance)) {
// Is not valid, so throw an exception here
ApplicationEntryPoint::exitApplication(__METHOD__ . ':INVALID HASH! UNDER CONSTRUCTION!' . PHP_EOL);
// Is the element there?
if (!isset($unlData[NodeInformationDatabaseFrontend::DB_COLUMN_EXTERNAL_UNL])) {
// Is not there
- throw new MissingArrayElementsException(array($this, 'unlData', array(NodeInformationDatabaseFrontend::DB_COLUMN_EXTERNAL_UNL)), self::EXCEPTION_ARRAY_ELEMENTS_MISSING);
+ throw new MissingArrayElementsException([$this, 'unlData', [NodeInformationDatabaseFrontend::DB_COLUMN_EXTERNAL_UNL]], self::EXCEPTION_ARRAY_ELEMENTS_MISSING);
} elseif ($unlData[NodeInformationDatabaseFrontend::DB_COLUMN_EXTERNAL_UNL] == 'invalid') {
// Is not valid/method to early used
throw new BadMethodCallException(sprintf('unlData[%s] is invalid. Maybe called this method to early?', NodeInformationDatabaseFrontend::DB_COLUMN_EXTERNAL_UNL), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
// Is the element there?
if (!isset($unlData[NodeInformationDatabaseFrontend::DB_COLUMN_INTERNAL_UNL])) {
// Is not there
- throw new MissingArrayElementsException(array($this, 'unlData', array(NodeInformationDatabaseFrontend::DB_COLUMN_INTERNAL_UNL)), self::EXCEPTION_ARRAY_ELEMENTS_MISSING);
+ throw new MissingArrayElementsException([$this, 'unlData', [NodeInformationDatabaseFrontend::DB_COLUMN_INTERNAL_UNL]], self::EXCEPTION_ARRAY_ELEMENTS_MISSING);
} elseif ($unlData[NodeInformationDatabaseFrontend::DB_COLUMN_INTERNAL_UNL] == 'invalid') {
// Is not valid/method to early used
throw new BadMethodCallException(sprintf('unlData[%s] is invalid. Maybe called this method to early?', NodeInformationDatabaseFrontend::DB_COLUMN_INTERNAL_UNL), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
// Abort if the call-back method is not there
if (!method_exists($callable[0], $callable[1])) {
// Throw an exception
- throw new UnsupportedPackageCodeHandlerException(array($callable, $packageInstance), self::EXCEPTION_UNSUPPORTED_PACKAGE_CODE_HANDLER);
+ throw new UnsupportedPackageCodeHandlerException([$callable, $packageInstance], self::EXCEPTION_UNSUPPORTED_PACKAGE_CODE_HANDLER);
}
// Call it back
// Is the connection type valid?
if (!$socketInstance->isValidConnectionType($connectionType)) {
// Is not a valid connection type!
- throw new InvalidConnectionTypeException(array($this, $connectionType), StorableSocket::EXCEPTION_INVALID_CONNECTION_TYPE);
+ throw new InvalidConnectionTypeException([$this, $connectionType], StorableSocket::EXCEPTION_INVALID_CONNECTION_TYPE);
}
// Default is this peer's IP
// Is the connection type valid?
if (!$socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->isValidConnectionType($connectionType)) {
// Is not a valid connection type!
- throw new InvalidConnectionTypeException(array($this, $connectionType), self::EXCEPTION_INVALID_CONNECTION_TYPE);
+ throw new InvalidConnectionTypeException([$this, $connectionType], self::EXCEPTION_INVALID_CONNECTION_TYPE);
}
// Add the socket
throw new LogicException(sprintf('socketArray[%s] is not set.', Poolable::SOCKET_ARRAY_CONN_TYPE));
} elseif ((!empty($connectionType)) && (!$socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->isValidConnectionType($connectionType))) {
// Is not a valid connection type!
- throw new InvalidConnectionTypeException(array($this, $connectionType), self::EXCEPTION_INVALID_CONNECTION_TYPE);
+ throw new InvalidConnectionTypeException([$this, $connectionType], self::EXCEPTION_INVALID_CONNECTION_TYPE);
} elseif ((!empty($connectionType)) && ($socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE] !== $connectionType)) {
// Skip unwanted sockets
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL: Skipping unwanted socket %s of type %s/%s ...', $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getPrintableName(), $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE], $connectionType));
use Org\Mxchange\CoreFramework\Resolver\Command\BaseCommandResolver;
use Org\Mxchange\CoreFramework\Resolver\Command\CommandResolver;
+// Import SPL stuff
+use \InvalidArgumentException;
+
/**
* A command resolver for local (non-hubbed) web commands
*
* @param $commandName The default command we shall execute
* @param $applicationInstance An instance of a manageable application helper class
* @return $resolverInstance The prepared command resolver instance
- * @throws EmptyVariableException Thrown if default command is not set
+ * @throws InvalidArgumentException Thrown if default command is not set
* @throws InvalidCommandException Thrown if default command is invalid
*/
- public static final function createHubConsoleCommandResolver ($commandName, ManageableApplication $applicationInstance) {
+ public static final function createHubConsoleCommandResolver (string $commandName, ManageableApplication $applicationInstance) {
// Create the new instance
$resolverInstance = new HubConsoleCommandResolver();
// Is the variable $commandName set and the command is valid?
if (empty($commandName)) {
// Then thrown an exception here
- throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+ throw new InvalidArgumentException('Parameter "commandName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
} elseif ($resolverInstance->isCommandValid('Org\Shipsimu\Hub\Command', $commandName) === FALSE) {
// Invalid command found
- throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND);
+ throw new InvalidCommandException([$resolverInstance, $commandName], self::EXCEPTION_INVALID_COMMAND);
}
// Set namespace and application instance
use Org\Mxchange\CoreFramework\Resolver\Command\BaseCommandResolver;
use Org\Mxchange\CoreFramework\Resolver\Command\CommandResolver;
+// Import SPL stuff
+use \InvalidArgumentException;
+
/**
* A command resolver for HTML commands
*
* @param $commandName The default command we shall execute
* @param $applicationInstance An instance of a manageable application helper class
* @return $resolverInstance The prepared command resolver instance
- * @throws EmptyVariableException Thrown if default command is not set
+ * @throws InvalidArgumentException Thrown if default command is not set
* @throws InvalidCommandException Thrown if default command is invalid
*/
- public static final function createHubHtmlCommandResolver ($commandName, ManageableApplication $applicationInstance) {
+ public static final function createHubHtmlCommandResolver (string $commandName, ManageableApplication $applicationInstance) {
// Create the new instance
$resolverInstance = new HubHtmlCommandResolver();
// Is the variable $commandName set and the command is valid?
if (empty($commandName)) {
// Then thrown an exception here
- throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+ throw new InvalidArgumentException('Parameter "commandName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
} elseif ($resolverInstance->isCommandValid('Org\Shipsimu\Hub\Command', $commandName) === FALSE) {
// Invalid command found
- throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND);
+ throw new InvalidCommandException([$resolverInstance, $commandName], self::EXCEPTION_INVALID_COMMAND);
}
// Set namespace and application instance
*
* @param $controllerName The controller we shall resolve
* @return $resolverInstance The prepared controller resolver instance
- * @throws EmptyVariableException Thrown if default command is not set
+ * @throws InvalidArgumentException Thrown if default command is not set
* @throws InvalidControllerException Thrown if default controller is invalid
*/
public static final function createHubConsoleControllerResolver ($controllerName) {
// Is the variable $controllerName set and the command is valid?
if (empty($controllerName)) {
// Then thrown an exception here
- throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+ throw new InvalidArgumentException('Parameter "controllerName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
} elseif ($resolverInstance->isControllerValid('Org\Shipsimu\Hub\Controller', $controllerName) === false) {
// Invalid command found
- throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
+ throw new InvalidControllerException([$resolverInstance, $controllerName], self::EXCEPTION_INVALID_CONTROLLER);
}
// Set namespace and command name
// And validate it
if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) {
// This command has an invalid instance!
- throw new InvalidControllerInstanceException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
+ throw new InvalidControllerInstanceException([$this, $controllerName], self::EXCEPTION_INVALID_CONTROLLER);
}
// Set last controller
*
* @param $controllerName The controller we shall resolve
* @return $resolverInstance The prepared controller resolver instance
- * @throws EmptyVariableException Thrown if default command is not set
+ * @throws InvalidArgumentException Thrown if default command is not set
* @throws InvalidControllerException Thrown if default controller is invalid
*/
public static final function createHubHtmlControllerResolver ($controllerName) {
// Is the variable $controllerName set and the command is valid?
if (empty($controllerName)) {
// Then thrown an exception here
- throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+ throw new InvalidArgumentException('Parameter "controllerName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
} elseif ($resolverInstance->isControllerValid('Org\Shipsimu\Hub\Controller', $controllerName) === false) {
// Invalid command found
- throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
+ throw new InvalidControllerException([$resolverInstance, $controllerName], self::EXCEPTION_INVALID_CONTROLLER);
}
// Set namespace and command name
// And validate it
if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) {
// This command has an invalid instance!
- throw new InvalidControllerInstanceException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
+ throw new InvalidControllerInstanceException([$this, $controllerName], self::EXCEPTION_INVALID_CONTROLLER);
}
// Set last controller
* @param $statePrefix Last validated statePrefix
* @return void
*/
- protected final function setStatePrefix ($statePrefix) {
+ protected final function setStatePrefix (string $statePrefix): void {
$this->statePrefix = $statePrefix;
}
* @param $statePrefix Last validated statePrefix
* @return void
*/
- protected final function getStatePrefix () {
+ protected final function getStatePrefix (): string {
return $this->statePrefix;
}
* @param $stateName Last validated state name
* @return void
*/
- protected final function setStateName ($stateName) {
+ protected final function setStateName (string $stateName): void {
$this->stateName = $stateName;
}
*
* @return $stateName Last validated state name
*/
- public final function getStateName () {
+ public final function getStateName (): string {
return $this->stateName;
}
*
* @param $stateName A state name we shall look for
* @return $stateInstance A loaded state instance
+ * @throws InvalidArgumentException Thrown if given state is not set
* @throws UnresolveableStateException Thrown if even the requested
* state class is missing (bad!)
*/
- protected function loadState ($stateName) {
+ protected function loadState (string $stateName) {
+ // Is a state set?
+ if (empty($stateName)) {
+ // Then thrown an exception here
+ throw new InvalidArgumentException('Parameter "stateName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+ }
+
// Init state instance
$stateInstance = NULL;
// Is this class loaded?
if (!class_exists($this->getClassName())) {
// Throw an exception here
- throw new UnresolveableStateException(array($this, $stateName), self::EXCEPTION_INVALID_STATE);
+ throw new UnresolveableStateException([$this, $stateName], self::EXCEPTION_INVALID_STATE);
}
// Initialize the state
*
* @param $stateName The default state we shall execute
* @return $isValid Whether the given state is valid
- * @throws EmptyVariableException Thrown if given state is not set
+ * @throws InvalidArgumentException Thrown if given state is not set
* @throws DefaultStateException Thrown if default state was not found
*/
- public function isStateValid ($stateName) {
- // By default nothing shall be valid
- $isValid = FALSE;
-
+ public function isStateValid (string $stateName): bool {
// Is a state set?
if (empty($stateName)) {
// Then thrown an exception here
- throw new EmptyVariableException(array($this, 'stateName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+ throw new InvalidArgumentException('Parameter "stateName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
}
+ // By default nothing shall be valid
+ $isValid = FALSE;
+
// Create class name
$className = $this->statePrefix . StringUtils::convertToClassName($stateName) . 'State';
//* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d] entry=%s', __METHOD__, __LINE__, print_r($entry, TRUE)));
if ((!is_array($entry)) || (count($entry) == 0) || (!isset($entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_PROTOCOL])) || (!isset($entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_RECIPIENT_TYPE]))) {
// Invalid entry found
- throw new InvalidTagException(array($this, $tag), self::EXCEPTION_INVALID_TAG);
+ throw new InvalidTagException([$this, $tag], self::EXCEPTION_INVALID_TAG);
}
// Now save the last discovered protocol/recipient type
*
* @param $stateName The default state we shall execute
* @return $isValid Whether the given state is valid
- * @throws EmptyVariableException Thrown if given state is not set
+ * @throws InvalidArgumentException Thrown if given state is not set
*/
- function isStateValid (string $stateName);
+ function isStateValid (string $stateName): void;
}
-Subproject commit ff2afec772b7b5959d6225d70d2bd352d0f8c684
+Subproject commit 7c9c09a0065013ed20f8361e87ad6ceda7896cb9