]> git.mxchange.org Git - hub.git/commitdiff
Used exit() instead of die()
authorRoland Häder <roland@mxchange.org>
Tue, 7 Aug 2012 00:21:28 +0000 (00:21 +0000)
committerRoland Häder <roland@mxchange.org>
Tue, 7 Aug 2012 00:21:28 +0000 (00:21 +0000)
14 files changed:
application/hub/class_ApplicationHelper.php
application/hub/interfaces/nodes/class_NodeHelper.php
application/hub/main/class_BaseHubSystem.php
application/hub/main/filter/cruncher/class_CruncherInitializationFilter.php
application/hub/main/filter/node/class_NodeInitializationFilter.php
application/hub/main/handler/chunks/class_ChunkHandler.php
application/hub/main/handler/network/class_BaseRawDataHandler.php
application/hub/main/nodes/class_BaseHubNode.php
application/hub/main/package/assembler/class_PackageAssembler.php
application/hub/main/package/class_NetworkPackage.php
application/hub/main/streams/raw_data/input/class_RawDataInputStream.php
application/hub/main/streams/raw_data/output/class_RawDataOutputStream.php
application/hub/starter.php
index.php

index cdc0ada96ac24b7516ac5bcc7f7015f87847de7d..82c3ae4712be464034fe0f757b9ff5646740cf07 100644 (file)
@@ -222,7 +222,7 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica
        public function handleFatalMessages (array $messageList) {
                // Walk through all messages
                foreach ($messageList as $message) {
-                       die(__METHOD__ . ':MSG:' . $message);
+                       exit(__METHOD__ . ':MSG:' . $message);
                } // END - foreach
        }
 
index 1f279bbbfb67d6453e823fc095dd4f81c5f46e06..f3c87c29dff164edce19d318c2ce35ff79703e16 100644 (file)
@@ -125,7 +125,7 @@ interface NodeHelper extends FrameworkInterface {
        /**
         * "Getter for address:port combination
         *
-        * @param       $handlerInstance        A valid Networkable instance
+        * @param       $handlerInstance        An instance of a Networkable class
         * @return      $addressPort            A address:port combination for this node
         */
        function getAddressPort (Networkable $handlerInstance);
index e72cbd3ef39a8524df1729eda5632504e4ef3630..03579227987b32f3114470a5900b96f0ebb9471d 100644 (file)
@@ -593,6 +593,20 @@ class BaseHubSystem extends BaseFrameworkSystem {
                // Return result
                return $stateName;
        }
+
+       /**
+        * Checks whether start/end marker are set
+        *
+        * @param       $data   Data to be checked
+        * @return      $isset  Whether start/end marker are set
+        */
+       public final function ifStartEndMarkerSet ($data) {
+               // Determine it
+               $isset = ((substr($data, 0, strlen(BaseRawDataHandler::STREAM_START_MARKER)) == BaseRawDataHandler::STREAM_START_MARKER) && (substr($data, -1 * strlen(BaseRawDataHandler::STREAM_END_MARKER), strlen(BaseRawDataHandler::STREAM_END_MARKER)) == BaseRawDataHandler::STREAM_END_MARKER));
+
+               // ... and return it
+               return $isset;
+       }
 }
 
 // [EOF]
index 75ce11dc8aa43542e9bfb437bf5743486313dda4..0f3920e6d643100e44be9350a39a25f73141c2cb 100644 (file)
@@ -84,7 +84,7 @@ class CruncherInitializationFilter extends BaseFilter implements Filterable {
                        $cruncherInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance);
                } catch (ClassNotFoundException $e) {
                        // This exception means, the cruncher mode is invalid.
-                       // @TODO Can we rewrite this to app_die() ?
+                       // @TODO Can we rewrite this to app_exit() ?
                        $this->debugBackTrace('[' . __METHOD__ . ':' . __LINE__ . ']:  cruncher mode ' . $cruncherMode . ' is invalid.');
                }
 
index 838e12aff4c48d557b36390ed88d42c6fe930c4e..6eaec8309b5cb0b333478599c004922135318113 100644 (file)
@@ -84,7 +84,7 @@ class NodeInitializationFilter extends BaseFilter implements Filterable {
                        $nodeInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance);
                } catch (ClassNotFoundException $e) {
                        // This exception means, the node mode is invalid.
-                       // @TODO Can we rewrite this to app_die() ?
+                       // @TODO Can we rewrite this to app_exit() ?
                        $this->debugBackTrace('[' . __METHOD__ . ':' . __LINE__ . ']:  node mode ' . $nodeMode . ' is invalid.');
                }
 
index 991a95aa3c09106a3faaefbf87f384dba27d6efc..739e07e247bfd2b7a0ae9bca34f214d1d706fdc9 100644 (file)
@@ -246,7 +246,7 @@ class ChunkHandler extends BaseHandler implements HandleableChunks, Registerable
        private function preparePackageAssmble () {
                // Make sure both arrays have same count (this however should always be true)
                assert(count($this->finalPackageChunks['hashes']) == count($this->finalPackageChunks['content']));
-               //* DIE: */ die(__METHOD__ . ':finalPackageChunks='.print_r($this->finalPackageChunks['content'],true));
+               //* DIE: */ exit(__METHOD__ . ':finalPackageChunks='.print_r($this->finalPackageChunks['content'],true));
 
                /*
                 * Remove last element (hash chunk) from 'hashes'. This hash will never
index 331f160fe5d2f256569b48faf3c8ebd736dc473c..9e7c63191bb54f1459a22d66b33edaf28ef6747a 100644 (file)
@@ -48,6 +48,10 @@ class BaseRawDataHandler extends BaseHandler {
        const PACKAGE_RAW_DATA   = 'raw_data';
        const PACKAGE_ERROR_CODE = 'error_code';
 
+       // Start/end marker
+       const STREAM_START_MARKER = '[[S]]';
+       const STREAM_EN_MARKER    = '[[E]]';
+
        /**
         * Stacker for raw data
         */
index d7833dac4cac5d888241c9280580abb7a15103e1..2eae02a2b7d3caa5731824439311909781ae0231 100644 (file)
@@ -737,7 +737,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
        /**
         * "Getter" for address:port combination
         *
-        * @param       $handlerInstance        A valid Networkable instance
+        * @param       $handlerInstance        An instance of a Networkable class
         * @return      $addressPort            A address:port combination for this node
         */
        public final function getAddressPort (Networkable $handlerInstance) {
@@ -769,7 +769,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
         * @return      void
         */
        public function handleAnswerStatusByMessageData (array $messageData) {
-               die('messageData=' . print_r($messageData, true));
+               exit('messageData=' . print_r($messageData, true));
        }
 }
 
index 994544e1b4a34c69cda8a4147dfbff5ee23e468f..3c377d145716ef02002f58c29acddd7f37aed2cb 100644 (file)
@@ -52,7 +52,7 @@ class PackageAssembler extends BaseHubSystem implements Assembler, Registerable
                $assemblerInstance->setPackageInstance($packageInstance);
 
                // Create an instance of a raw data input stream
-               $streamInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_input_stream_class', array($packageInstance));
+               $streamInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_input_stream_class');
 
                // And set it
                $assemblerInstance->setInputStreamInstance($streamInstance);
@@ -85,7 +85,7 @@ class PackageAssembler extends BaseHubSystem implements Assembler, Registerable
         */
        private function isPackageContentCompleted (array $packageContent) {
                // Check both
-               $isCompleted = ((substr($packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA], 0, 5) == '[[S]]') && (substr($packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA], -5, 5) == '[[E]]'));
+               $isCompleted = $this->ifStartEndMarkerSet($packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA]);
 
                // Return status
                return $isCompleted;
index a116d7cecf2f246c509f37f7fa219976a72162d9..81f262119f17f74b4907a499ea5021166ea6b5b4 100644 (file)
@@ -249,17 +249,15 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                // Init all stacker
                $packageInstance->initStackers();
 
-               // Get a visitor instance for speeding up things
+               // Get a visitor instance for speeding up things and set it
                $visitorInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_monitor_visitor_class', array($packageInstance));
-
-               // Set it in this package
                $packageInstance->setVisitorInstance($visitorInstance);
 
-               // Get crypto instance and set it in this package
+               // Get crypto instance and set it, too
                $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
                $packageInstance->setCryptoInstance($cryptoInstance);
 
-               // Get a singleton package assembler instance from factory and set it here
+               // Get a singleton package assembler instance from factory and set it here, too
                $assemblerInstance = PackageAssemblerFactory::createAssemblerInstance($packageInstance);
                $packageInstance->setAssemblerInstance($assemblerInstance);
 
@@ -577,7 +575,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
 
                // Is it the same?
                //$isSignatureValid = 
-               die(__METHOD__.': signature='.$signature.chr(10).',decodedArray='.print_r($decodedArray,true));
+               exit(__METHOD__.': signature='.$signature.chr(10).',decodedArray='.print_r($decodedArray,true));
        }
 
        /**
@@ -996,7 +994,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                 * @todo Unsupported feature of "signed" messages commented out
                if (!$this->isPackageSignatureValid($decodedArray)) {
                        // Is not valid, so throw an exception here
-                       die(__METHOD__ . ':INVALID SIG! UNDER CONSTRUCTION!' . chr(10));
+                       exit(__METHOD__ . ':INVALID SIG! UNDER CONSTRUCTION!' . chr(10));
                } // END - if
                */
 
index 38deb7aa40cf6e0e30e2d931625f32a79db421c9..d7cb9d8f3fa9843bd527aa35741e9fe276dae478 100644 (file)
@@ -35,10 +35,9 @@ class RawDataInputStream extends BaseStream implements InputStreamable {
        /**
         * Creates an instance of this node class
         *
-        * @param       $handlerInstance        An instance of a Networkable class
         * @return      $streamInstance         An instance of this node class
         */
-       public final static function createRawDataInputStream (Networkable $handlerInstance) {
+       public final static function createRawDataInputStream () {
                // Get a new instance
                $streamInstance = new RawDataInputStream();
 
@@ -58,19 +57,19 @@ class RawDataInputStream extends BaseStream implements InputStreamable {
         */
        public function streamData ($data) {
                // Do we have start and end marker again?
-               assert((substr($data, 0, 5) == '[[S]]') && (substr($data, -5, 5) == '[[E]]'));
+               assert($this->ifStartEndMarkerSet($data));
 
                // Remove both
-               $data = substr($data, 6 - 5);
+               $data = substr($data, strlen(BaseRawDataHandler::STREAM_START_MARKER), -1 * strlen(BaseRawDataHandler::STREAM_END_MARKER));
 
                // Can it be validated?
                if ((strlen($data) % 4) != 0) {
                        // Length modulo 4 must be zero, else it is an invalid Base64 message
-                       $this->getHandlerInstance()->setErrorCode(BaseRawDataHandler::SOCKET_ERROR_INVALID_BASE64_MODULO);
+                       $handlerInstance->setErrorCode(BaseRawDataHandler::SOCKET_ERROR_INVALID_BASE64_MODULO);
                        $data = false;
                } elseif (!$this->isBase64Encoded($data)) {
                        // Is not a valid Base64-encoded message
-                       $this->getHandlerInstance()->setErrorCode(BaseRawDataHandler::SOCKET_ERROR_INVALID_BASE64_MESSAGE);
+                       $handlerInstance->setErrorCode(BaseRawDataHandler::SOCKET_ERROR_INVALID_BASE64_MESSAGE);
                        $data = false;
                } else {
                        // Decode the data with BASE64-encoding
index 32fb286ba3a39a8c47ad095742015983a9981700..60571432ea284f48b7c1eca4d6d4fe9115bb12e8 100644 (file)
@@ -50,7 +50,6 @@ class RawDataOutputStream extends BaseStream implements OutputStreamable {
         *
         * @param       $data   The data (string mostly) to "stream"
         * @return      $data   The data (string mostly) to "stream"
-        * @todo        Do we need to do something more here?
         */
        public function streamData ($data) {
                /*
@@ -59,7 +58,7 @@ class RawDataOutputStream extends BaseStream implements OutputStreamable {
                 * [[S]] - Start marker
                 * [[E]] - End marker
                 */
-               $data = '[[S]]' . base64_encode($data) . '[[E]]';
+               $data = BaseRawDataHandler::STREAM_START_MARKER . base64_encode($data) . BaseRawDataHandler::STREAM_END_MARKER;
 
                // Return it
                return $data;
index e5ea218bc3e36a250ddf49fd87df04cb3c67bae2..8266d3128fdea5c1acc45cacfdf74b8e7bd88802 100644 (file)
@@ -33,18 +33,18 @@ $app = call_user_func_array(
 // Some sanity checks
 if ((empty($app)) || (is_null($app))) {
        // Something went wrong!
-       ApplicationEntryPoint::app_die(sprintf("[Main:] The application <span class=\"app_name\">%s</span> could not be launched because the helper class <span class=\"class_name\">%s</span> is not loaded.",
+       ApplicationEntryPoint::app_exit(sprintf("[Main:] The application <span class=\"app_name\">%s</span> could not be launched because the helper class <span class=\"class_name\">%s</span> is not loaded.",
                $application,
                FrameworkConfiguration::getSelfInstance()->getConfigEntry('app_helper_class')
        ));
 } elseif (!is_object($app)) {
        // No object!
-       ApplicationEntryPoint::app_die(sprintf("[Main:] The application <span class=\"app_name\">%s</span> could not be launched because &#39;app&#39; is not an object.",
+       ApplicationEntryPoint::app_exit(sprintf("[Main:] The application <span class=\"app_name\">%s</span> could not be launched because &#39;app&#39; is not an object.",
                $application
        ));
 } elseif (!method_exists($app, FrameworkConfiguration::getSelfInstance()->getConfigEntry('entry_method'))) {
        // Method not found!
-       ApplicationEntryPoint::app_die(sprintf("[Main:] The application <span class=\"app_name\">%s</span> could not be launched because the method <span class=\"method_name\">%s</span> is missing.",
+       ApplicationEntryPoint::app_exit(sprintf("[Main:] The application <span class=\"app_name\">%s</span> could not be launched because the method <span class=\"method_name\">%s</span> is missing.",
                $application,
                FrameworkConfiguration::getSelfInstance()->getConfigEntry('entry_method')
        ));
index 851f50002b47c015102cdefe2df3d8a54e8c42d7..a14e71b0b5f8275639eb7a3ad1ef652288a9d34a 100644 (file)
--- a/index.php
+++ b/index.php
@@ -41,7 +41,7 @@ final class ApplicationEntryPoint {
                'debug',  // Debug output
                'db',     // Database layer
                'io',     // Base I/O system (local file [or network])
-               'engine', // Template engine ( for ApplicationEntryPoint::app_die() )
+               'engine', // Template engine ( for ApplicationEntryPoint::app_exit() )
                'lang',   // Language sub-system
                'app',    // The ApplicationHelper instance
        );
@@ -56,11 +56,11 @@ final class ApplicationEntryPoint {
         * @return      void
         * @todo        This method is old code and needs heavy rewrite and should be moved to ApplicationHelper
         */
-       public static final function app_die ($message = '', $code = false, $extraData = '', $silentMode = false) {
+       public static final function app_exit ($message = '', $code = false, $extraData = '', $silentMode = false) {
                // Is this method already called?
                if (isset($GLOBALS['app_die_called'])) {
                        // Then output the text directly
-                       die($message);
+                       exit($message);
                } // END - if
 
                // This method shall not be called twice
@@ -78,7 +78,7 @@ final class ApplicationEntryPoint {
                // Do we have debug installation?
                if (($configInstance->getConfigEntry('product_install_mode') == 'productive') || ($silentMode === true)) {
                        // Abort here
-                       die();
+                       exit();
                } // END - if
 
                // Get some instances
@@ -98,7 +98,7 @@ final class ApplicationEntryPoint {
                                // Get the template instance from our object factory
                                $templateInstance = ObjectFactory::createObjectByName($tpl);
                        } catch (FrameworkException $e) {
-                               die(sprintf("[Main:] Could not initialize template engine for reason: <span class=\"exception_reason\">%s</span>",
+                               exit(sprintf("[Main:] Could not initialize template engine for reason: <span class=\"exception_reason\">%s</span>",
                                        $e->getMessage()
                                ));
                        }
@@ -166,14 +166,14 @@ final class ApplicationEntryPoint {
                                $responseInstance->flushBuffer();
                        } catch (FileIoException $e) {
                                // Even the template 'emergency_exit' wasn't found so output both message
-                               die($message . ', exception: ' . $e->getMessage());
+                               exit($message . ', exception: ' . $e->getMessage());
                        }
 
                        // Good bye...
                        exit();
                } else {
                        // Output message and die
-                       die(sprintf("[Main:] Emergency exit reached: <span class=\"emergency_span\">%s</span>",
+                       exit(sprintf("[Main:] Emergency exit reached: <span class=\"emergency_span\">%s</span>",
                                $message
                        ));
                }