]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/tags/package/class_PackageTags.php
Package data 'recipient', 'sender' and 'content' are now replaceable
[hub.git] / application / hub / main / tags / package / class_PackageTags.php
index a8fd09a2598c5ad5ece8226a2816f3bf7f32246e..79ced828473d0c9a3c5e82a658b574bc50ebd174 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  *
@@ -30,6 +30,11 @@ class PackageTags extends BaseTags implements Tagable {
         */
        private $lastProtocol = 'invalid';
 
+       /**
+        * Last found recipient type
+        */
+       private $lastRecipientType = 'invalid';
+
        /**
         * Protected constructor
         *
@@ -48,7 +53,7 @@ class PackageTags extends BaseTags implements Tagable {
         *
         * @return      $tagsInstance   An instance of a Tagable class
         */
-       public final static function createPackageTags () {
+       public static final function createPackageTags () {
                // Get new instance
                $tagsInstance = new PackageTags();
 
@@ -66,19 +71,10 @@ class PackageTags extends BaseTags implements Tagable {
                $this->debugOutput('TAGS: Initializing object registry - START');
 
                // Get the application instance
-               $appInstance = Registry::getRegistry()->getInstance('app');
+               $applicationInstance = Registry::getRegistry()->getInstance('app');
 
                // Get a XML template instance
-               $templateInstance = ObjectFactory::createObjectByConfiguredName('object_registry_template_class', array($appInstance));
-
-               // Disable language support
-               $templateInstance->enableLanguageSupport(false);
-
-               /*
-                * Enable compacting/rewriting of the  XML to save bandwidth from XML
-                * comments. This is expensive and should be avoided in general.
-                */
-               $templateInstance->enableXmlCompacting();
+               $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_object_registry_template_class');
 
                // Set it for later use
                $this->setTemplateInstance($templateInstance);
@@ -104,7 +100,7 @@ class PackageTags extends BaseTags implements Tagable {
                 * We take a look at the tags (in most cases only one is needed) so
                 * first we need the content data splitted up into all it's parts.
                 */
-               $contentData = explode(NetworkPackage::PACKAGE_MASK_SEPERATOR, $packageData['content']);
+               $contentData = explode(NetworkPackage::PACKAGE_MASK_SEPERATOR, $packageData[NetworkPackage::PACKAGE_DATA_CONTENT]);
 
                // Get the tags and store them locally
                $this->setTags(explode(NetworkPackage::PACKAGE_TAGS_SEPERATOR, $contentData[NetworkPackage::INDEX_TAGS]));
@@ -121,10 +117,13 @@ class PackageTags extends BaseTags implements Tagable {
         */
        private function verifyAllTags () {
                // Get the registry
-               $objectRegistryInstance = ObjectFactory::createObjectByConfiguredName('object_type_registry_class');
+               $objectRegistryInstance = ObjectFactory::createObjectByConfiguredName('node_object_type_registry_class');
 
                // "Walk" over all tags
                foreach ($this->getTags() as $tag) {
+                       // Debug output
+                       $this->debugOutput('TAGS: Validating tag ' . $tag . ' ...');
+
                        // Get an array from this tag
                        $entry = $objectRegistryInstance->getArrayFromKey($tag);
 
@@ -134,8 +133,9 @@ class PackageTags extends BaseTags implements Tagable {
                                throw new InvalidTagException(array($this, $tag), self::EXCEPTION_INVALID_TAG);
                        } // END - if
 
-                       // Now save the last discovered protocol
-                       $this->lastProtocol = $entry['object-protocol'];
+                       // Now save the last discovered protocol/recipient type
+                       $this->lastProtocol      = $entry['object-protocol'];
+                       $this->lastRecipientType = $entry['object-recipient-type'];
                } // END - foreach
        }
 
@@ -158,6 +158,27 @@ class PackageTags extends BaseTags implements Tagable {
                // Return it
                return $protocolName;
        }
+
+       /**
+        * Checks wether the given package data is accepted by the listener
+        *
+        * @param       $packageData            Raw package data
+        * @param       $listenerInstance       A Listenable instance
+        * @return      $accepts                        Wether it is accepted
+        */
+       public function ifPackageDataIsAcceptedByListener (array $packageData, Listenable $listenerInstance) {
+               // Extract the tags
+               $this->extractTagsFromPackageData($packageData);
+
+               // Now we need to verify every single tag
+               $this->verifyAllTags();
+
+               // Now simply check it out
+               $accepts = (($this->lastRecipientType == $listenerInstance->getListenerType()) && ($listenerInstance->getListenerType() != 'invalid'));
+
+               // And return the result
+               return $accepts;
+       }
 }
 
 // [EOF]