]> git.mxchange.org Git - core.git/blobdiff - inc/classes/main/io/class_FileIoStream.php
Renamed 'seperator' to 'separator'
[core.git] / inc / classes / main / io / class_FileIoStream.php
index fb7096d4648214f7b7bbef924e5c32df5e8fd4d0..e1ccd8aa6333984e30e42995bcbfa3bbb87aeecd 100644 (file)
@@ -25,22 +25,22 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil
        /**
         * File header indicator
         */
-       private $fileHeader = '@head';
+       const FILE_IO_FILE_HEADER_ID = '@head';
 
        /**
         * Data block indicator
         */
-       private $dataBlock = '@data';
+       const FILE_IO_DATA_BLOCK_ID = '@data';
 
        /**
-        * Seperator #1
+        * Separator #1
         */
-       private $chunker = ':';
+       const FILE_IO_CHUNKER = ':';
 
        /**
-        * Seperator #2
+        * Separator #2
         */
-       private $seperator = '^';
+       const FILE_IO_SEPARATOR = '^';
 
        /**
         * Protected constructor
@@ -75,7 +75,7 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil
         */
        public final function saveFile ($fileName, $dataArray) {
                // Try it five times
-               $dirName = ''; $fileInstance = null;
+               $dirName = ''; $fileInstance = NULL;
                for ($idx = 0; $idx < 5; $idx++) {
                        // Get a file output pointer
                        try {
@@ -94,14 +94,14 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil
 
                // Write a header information for validation purposes
                $fileInstance->writeToFile(sprintf("%s%s%s%s%s%s%s%s%s\n",
-                       $this->fileHeader,
-                       $this->seperator,
+                       self::FILE_IO_FILE_HEADER_ID,
+                       self::FILE_IO_SEPARATOR,
                        $dataArray[0],
-                       $this->chunker,
+                       self::FILE_IO_CHUNKER,
                        time(),
-                       $this->chunker,
+                       self::FILE_IO_CHUNKER,
                        strlen($dataArray[1]),
-                       $this->chunker,
+                       self::FILE_IO_CHUNKER,
                        md5($dataArray[1])
                ));
 
@@ -116,10 +116,10 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil
 
                        // Save it to the stream
                        $fileInstance->writeToFile(sprintf("%s%s%s%s%s\n",
-                               $this->dataBlock,
-                               $this->seperator,
+                               self::FILE_IO_DATA_BLOCK_ID,
+                               self::FILE_IO_SEPARATOR,
                                $line,
-                               $this->chunker,
+                               self::FILE_IO_CHUNKER,
                                md5($line)
                        ));
 
@@ -165,7 +165,7 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil
                $fileInstance->closeFile();
 
                // Convert it into an array
-               $inputBuffer = explode("\n", $inputBuffer);
+               $inputBuffer = explode(chr(10), $inputBuffer);
 
                // Now process the read lines and verify it's content
                foreach ($inputBuffer as $rawLine) {
@@ -173,26 +173,26 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil
                        $rawLine = rtrim($rawLine);
 
                        // Analyze this line
-                       if (substr($rawLine, 0, 5) == $this->fileHeader) {
+                       if (substr($rawLine, 0, 5) == self::FILE_IO_FILE_HEADER_ID) {
                                // Header found, so let's extract it
-                               $header = explode($this->seperator, $rawLine);
+                               $header = explode(self::FILE_IO_SEPARATOR, $rawLine);
                                $header = trim($header[1]);
 
                                // Now we must convert it again into an array
-                               $header = explode($this->chunker, $header);
+                               $header = explode(self::FILE_IO_CHUNKER, $header);
 
                                // Is the header (maybe) valid?
                                if (count($header) != 4) {
                                        // Throw an exception
                                        throw new InvalidArrayCountException(array($this, 'header', count($header), 4), self::EXCEPTION_ARRAY_HAS_INVALID_COUNT);
                                } // END - if
-                       } elseif (substr($rawLine, 0, 5) == $this->dataBlock) {
+                       } elseif (substr($rawLine, 0, 5) == self::FILE_IO_DATA_BLOCK_ID) {
                                // Is a data line!
-                               $data = explode($this->seperator, $rawLine);
+                               $data = explode(self::FILE_IO_SEPARATOR, $rawLine);
                                $data = $data[1];
 
                                // First element is the data, second the MD5 checksum
-                               $data = explode($this->chunker, $data);
+                               $data = explode(self::FILE_IO_CHUNKER, $data);
 
                                // Validate the read line
                                if (count($data) == 2) {
@@ -209,7 +209,7 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil
                                $readData .= $data[0];
                        } else {
                                // Other raw lines than header/data tagged lines and re-add the new-line char
-                               $readData .= $rawLine . "\n";
+                               $readData .= $rawLine . chr(10);
                        }
                } // END - foreach