]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/resolver/protocol/tcp/class_TcpProtocolResolver.php
Continued rewriting:
[hub.git] / application / hub / main / resolver / protocol / tcp / class_TcpProtocolResolver.php
index 41a1f6d2093d97ae50c91c15785126c81ec94f2f..8a3aae4bf4f5a01c33bba2dab2e088ff1124ca36 100644 (file)
@@ -36,7 +36,7 @@ class TcpProtocolResolver extends BaseProtocolResolver implements ProtocolResolv
        }
 
        /**
-        * Creates an instance of a Tcp command resolver with a given default command
+        * Creates an instance of a TCP protocol resolver
         *
         * @return      $resolverInstance       The prepared command resolver instance
         */
@@ -49,15 +49,54 @@ class TcpProtocolResolver extends BaseProtocolResolver implements ProtocolResolv
        }
 
        /**
-        * Returns an command instance for a given NodeHelper instance or null if it
-        * was not found.
+        * Returns an instance of a LocateableNode class for a given NodeHelper
+        * instance or null if it was not found.
         *
         * @param       $nodeInstance   An instance of a NodeHelper class
         * @return      $unlInstance    An instance of a LocateableNode class
         * @todo        0% done
         */
-       public function resolveUniversalResourceLocatorFromNodeHelper (NodeHelper $nodeInstance) {
-               $this->partialStub('Please implement this method.');
+       public function resolveUniversalNodeLocatorFromNodeHelper (NodeHelper $nodeInstance) {
+               // Get result instance
+               $resultInstance = $nodeInstance->getResultInstance();
+
+               // Make sure the result instance is valid
+               assert($resultInstance instanceof SearchableResult);
+
+               // Rewind iterator
+               $resultInstance->rewind();
+
+               // Lookup node's id
+               while ($resultInstance->next()) {
+                       // Get current entry
+                       $current = $resultInstance->current();
+
+                       // Do we have found an entry?
+                       // $nodeInstance->getNodeId()
+                       die(print_r($current, TRUE));
+               } // END - while
+       }
+
+       /**
+        * Returns the UNL as string from given configuration key.
+        *
+        * @param       $configKey      Configuration key for UNL address (valid: internal,external)
+        * @return      $unl            Universal node locator
+        */
+       public function resolveUniversalNodeLocatorFromConfigKey ($configKey) {
+               // Put all together
+               $unl = sprintf('%s://%s:%s',
+                       $this->getProtocolName(),
+                       $this->getConfigInstance()->getConfigEntry($configKey . '_address'),
+                       $this->getConfigInstance()->getConfigEntry('node_listen_port')
+               );
+
+               /*
+                * And return it. Please note that e.g. a FaxProtocolResolver will
+                * return a different UNL and therefore all protocol resolvers must do
+                * it on their own way.
+                */
+               return $unl;
        }
 }