From: Roland Häder Date: Tue, 7 Aug 2012 00:21:28 +0000 (+0000) Subject: Used exit() instead of die() X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b7c47cd5ca83bb9f8d5a1b46d553b5f1f2bbd80f;p=hub.git Used exit() instead of die() --- diff --git a/application/hub/class_ApplicationHelper.php b/application/hub/class_ApplicationHelper.php index cdc0ada96..82c3ae471 100644 --- a/application/hub/class_ApplicationHelper.php +++ b/application/hub/class_ApplicationHelper.php @@ -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 } diff --git a/application/hub/interfaces/nodes/class_NodeHelper.php b/application/hub/interfaces/nodes/class_NodeHelper.php index 1f279bbbf..f3c87c29d 100644 --- a/application/hub/interfaces/nodes/class_NodeHelper.php +++ b/application/hub/interfaces/nodes/class_NodeHelper.php @@ -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); diff --git a/application/hub/main/class_BaseHubSystem.php b/application/hub/main/class_BaseHubSystem.php index e72cbd3ef..035792279 100644 --- a/application/hub/main/class_BaseHubSystem.php +++ b/application/hub/main/class_BaseHubSystem.php @@ -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] diff --git a/application/hub/main/filter/cruncher/class_CruncherInitializationFilter.php b/application/hub/main/filter/cruncher/class_CruncherInitializationFilter.php index 75ce11dc8..0f3920e6d 100644 --- a/application/hub/main/filter/cruncher/class_CruncherInitializationFilter.php +++ b/application/hub/main/filter/cruncher/class_CruncherInitializationFilter.php @@ -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.'); } diff --git a/application/hub/main/filter/node/class_NodeInitializationFilter.php b/application/hub/main/filter/node/class_NodeInitializationFilter.php index 838e12aff..6eaec8309 100644 --- a/application/hub/main/filter/node/class_NodeInitializationFilter.php +++ b/application/hub/main/filter/node/class_NodeInitializationFilter.php @@ -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.'); } diff --git a/application/hub/main/handler/chunks/class_ChunkHandler.php b/application/hub/main/handler/chunks/class_ChunkHandler.php index 991a95aa3..739e07e24 100644 --- a/application/hub/main/handler/chunks/class_ChunkHandler.php +++ b/application/hub/main/handler/chunks/class_ChunkHandler.php @@ -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 diff --git a/application/hub/main/handler/network/class_BaseRawDataHandler.php b/application/hub/main/handler/network/class_BaseRawDataHandler.php index 331f160fe..9e7c63191 100644 --- a/application/hub/main/handler/network/class_BaseRawDataHandler.php +++ b/application/hub/main/handler/network/class_BaseRawDataHandler.php @@ -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 */ diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index d7833dac4..2eae02a2b 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -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)); } } diff --git a/application/hub/main/package/assembler/class_PackageAssembler.php b/application/hub/main/package/assembler/class_PackageAssembler.php index 994544e1b..3c377d145 100644 --- a/application/hub/main/package/assembler/class_PackageAssembler.php +++ b/application/hub/main/package/assembler/class_PackageAssembler.php @@ -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; diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index a116d7cec..81f262119 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -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 */ diff --git a/application/hub/main/streams/raw_data/input/class_RawDataInputStream.php b/application/hub/main/streams/raw_data/input/class_RawDataInputStream.php index 38deb7aa4..d7cb9d8f3 100644 --- a/application/hub/main/streams/raw_data/input/class_RawDataInputStream.php +++ b/application/hub/main/streams/raw_data/input/class_RawDataInputStream.php @@ -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 diff --git a/application/hub/main/streams/raw_data/output/class_RawDataOutputStream.php b/application/hub/main/streams/raw_data/output/class_RawDataOutputStream.php index 32fb286ba..60571432e 100644 --- a/application/hub/main/streams/raw_data/output/class_RawDataOutputStream.php +++ b/application/hub/main/streams/raw_data/output/class_RawDataOutputStream.php @@ -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; diff --git a/application/hub/starter.php b/application/hub/starter.php index e5ea218bc..8266d3128 100644 --- a/application/hub/starter.php +++ b/application/hub/starter.php @@ -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 %s could not be launched because the helper class %s is not loaded.", + ApplicationEntryPoint::app_exit(sprintf("[Main:] The application %s could not be launched because the helper class %s is not loaded.", $application, FrameworkConfiguration::getSelfInstance()->getConfigEntry('app_helper_class') )); } elseif (!is_object($app)) { // No object! - ApplicationEntryPoint::app_die(sprintf("[Main:] The application %s could not be launched because 'app' is not an object.", + ApplicationEntryPoint::app_exit(sprintf("[Main:] The application %s could not be launched because 'app' is not an object.", $application )); } elseif (!method_exists($app, FrameworkConfiguration::getSelfInstance()->getConfigEntry('entry_method'))) { // Method not found! - ApplicationEntryPoint::app_die(sprintf("[Main:] The application %s could not be launched because the method %s is missing.", + ApplicationEntryPoint::app_exit(sprintf("[Main:] The application %s could not be launched because the method %s is missing.", $application, FrameworkConfiguration::getSelfInstance()->getConfigEntry('entry_method') )); diff --git a/index.php b/index.php index 851f50002..a14e71b0b 100644 --- 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: %s", + exit(sprintf("[Main:] Could not initialize template engine for reason: %s", $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: %s", + exit(sprintf("[Main:] Emergency exit reached: %s", $message )); }