// Import framework stuff
use Org\Mxchange\CoreFramework\Registry\Registerable;
+// Import SPL stuff
+use \InvalidArgumentException;
+
/**
* A Protocol discovery class
*
*
* @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]);
use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
+// Import SPL stuff
+use \InvalidArgumentException;
+
/**
* A factory class for protocol handlers
*
*
* @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