]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Mon, 26 Oct 2020 15:24:30 +0000 (16:24 +0100)
committerRoland Häder <roland@mxchange.org>
Mon, 26 Oct 2020 15:24:30 +0000 (16:24 +0100)
- throwed more InvalidArgumentException when some method arguments are not valid

Signed-off-by: Roland Häder <roland@mxchange.org>
application/hub/classes/discovery/protocol/class_ProtocolDiscovery.php
application/hub/classes/factories/handler/class_ProtocolHandlerFactory.php

index d4288d02c6f6573ad372962cd6182527e7ee261a..ffa39519ba8760662d777fec40737e44b76e9d95 100644 (file)
@@ -10,6 +10,9 @@ use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Registry\Registerable;
 
+// Import SPL stuff
+use \InvalidArgumentException;
+
 /**
  * A Protocol discovery class
  *
@@ -85,18 +88,21 @@ class ProtocolDiscovery extends BaseNodeDiscovery implements DiscoverableProtoco
         *
         * @param       $packageInstance        An instance of a DeliverablePackage class
         * @return      $protocolType   Type of protocol, e.g. 'tcp' for TCP/IPv4 connections
+        * @throws      InvalidArgumentException        If $packageInstance has no valid recipient UNL set
         */
        public static final function discoverProtocolByPackageInstance (DeliverablePackage $packageInstance) {
-               //* DEBUG: */ die(__METHOD__ . ':packageInstance=' . print_r($packageInstance, TRUE));
-
                /*
                 * "Explode" the 'recipient' array element into a new one, giving at
                 * least two entries: protocol://address
                 */
+               //* DEBUG: */ die(__METHOD__ . ':packageInstance=' . print_r($packageInstance, TRUE));
                $recipient = explode(':', $packageInstance->getRecipientUnl());
 
                // At least 2 entries must be found
-               assert(count($recipient) >= 2);
+               if (count($recipient) < 2) {
+                       // Not valid
+                       throw new InvalidArgumentException(sprintf('packageInstance with recipientType=%s has no valid UNL=%s set.', $packageInstance->getRecipientType(), $packageInstance->getRecipientUnl()));
+               }
 
                // Now get the first part (protocol type) and make all lower-case
                $protocolType = strtolower($recipient[0]);
index 34cb97932cad71005e63cc016e0a0d1845b7bea7..ddef8fc06235ceea3c1e1777c3d98458f5a9a15b 100644 (file)
@@ -11,6 +11,9 @@ use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
 
+// Import SPL stuff
+use \InvalidArgumentException;
+
 /**
  * A factory class for protocol handlers
  *
@@ -50,8 +53,15 @@ class ProtocolHandlerFactory extends ObjectFactory {
         *
         * @param       $protocolType           Protocol type to create/return a protocol handler instance for
         * @return      $handlerInstance        A protocol handler instance
+        * @throws      InvalidArgumentException        If protocolType is not valid
         */
        private static function createProtocolHandlerByType ($protocolType) {
+               // Is it valid?
+               if (empty($protocolType)) {
+                       // Throw excption
+                       throw new InvalidArgumentException('protocolType is empty');
+               }
+
                // Do we have an instance in the registry?
                if (GenericRegistry::getRegistry()->instanceExists($protocolType . '_protocol_handler')) {
                        // Then use this instance