]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/streams/raw_data/input/class_RawDataInputStream.php
RawDataInputStream does now throw exceptions if the BASE64-encoded data is not well...
[hub.git] / application / hub / main / streams / raw_data / input / class_RawDataInputStream.php
index d7cb9d8f3fa9843bd527aa35741e9fe276dae478..ba34700b7bf56505c2547a4bff487a5305f0ae16 100644 (file)
@@ -1,6 +1,11 @@
 <?php
 /**
- * A RawDataInputStream class
+ * A class for handling incoming (encoded) raw data with start and end markers.
+ * The "stream" is being verified by its length (if modulo 4 of it is always
+ * zero) and if the "stream" contains all valid characters (the BASE64
+ * "alphabet").
+ *
+ * Since the latest refacturing this class works "handler-less".
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
@@ -41,9 +46,6 @@ class RawDataInputStream extends BaseStream implements InputStreamable {
                // Get a new instance
                $streamInstance = new RawDataInputStream();
 
-               // Set the handler instance
-               $streamInstance->setHandlerInstance($handlerInstance);
-
                // Return the instance
                return $streamInstance;
        }
@@ -54,6 +56,8 @@ class RawDataInputStream extends BaseStream implements InputStreamable {
         * @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?
+        * @throws      Base64EncodingModuloException   If the data's length modulo 4 is not zero
+        * @throws      Base64EncodingBadException              If the data contains characters which are not in the "alphabet" of BASE64 messages.
         */
        public function streamData ($data) {
                // Do we have start and end marker again?
@@ -65,12 +69,10 @@ class RawDataInputStream extends BaseStream implements InputStreamable {
                // Can it be validated?
                if ((strlen($data) % 4) != 0) {
                        // Length modulo 4 must be zero, else it is an invalid Base64 message
-                       $handlerInstance->setErrorCode(BaseRawDataHandler::SOCKET_ERROR_INVALID_BASE64_MODULO);
-                       $data = false;
+                       throw new Base64EncodingModuloException(array($this, $data), self::EXCEPTION_BASE64_ENCODING_NOT_MODULO_4);
                } elseif (!$this->isBase64Encoded($data)) {
                        // Is not a valid Base64-encoded message
-                       $handlerInstance->setErrorCode(BaseRawDataHandler::SOCKET_ERROR_INVALID_BASE64_MESSAGE);
-                       $data = false;
+                       throw new Base64EncodingBadException(array($this, $data), self::EXCEPTION_BASE64_BAD_ENCODING);
                } else {
                        // Decode the data with BASE64-encoding
                        $data = base64_decode($data);