]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/file_directories/binary/index/class_IndexFile.php
Continued:
[core.git] / framework / main / classes / file_directories / binary / index / class_IndexFile.php
index 65044b2049236a97024349030c9803852ccb3888..3de99584a81b123af3dae12f319a7f7ca0eb359f 100644 (file)
@@ -8,6 +8,7 @@ use Org\Mxchange\CoreFramework\Filesystem\File\BaseBinaryFile;
 use Org\Mxchange\CoreFramework\Filesystem\Index\IndexableFile;
 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
 use Org\Mxchange\CoreFramework\Index\Indexable;
+use Org\Mxchange\CoreFramework\Utils\Crypto\CryptoUtils;
 
 // Import SPL stuff
 use \BadMethodCallException;
@@ -166,6 +167,7 @@ class IndexFile extends BaseBinaryFile implements IndexableFile {
         * @param       $value          Value to be added to the stack
         * @return      $data           Hash and gap position
         * @throws      InvalidArgumentException        If a parameter is not valid
+        * @throws      BadMethodCallException  If this->indexInstance is not properly set
         */
        public function writeValueToFile (string $stackName, $value) {
                // Validate parameter
@@ -176,6 +178,9 @@ class IndexFile extends BaseBinaryFile implements IndexableFile {
                } elseif (is_object($value) || is_resource($value)) {
                        // Not wanted here
                        throw new InvalidArgumentException(sprintf('value[]=%s is not stackable in files', gettype($value)));
+               } elseif (!($this->getIndexInstance() instanceof Indexable)) {
+                       // Index instance not set
+                       throw new BadMethodCallException('this->indexInstance[] is not properly set.');
                }
 
                // Encode/convert the value into a "binary format"
@@ -183,7 +188,7 @@ class IndexFile extends BaseBinaryFile implements IndexableFile {
 
                // Get a strong hash for the "encoded" data
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: encoded=%s', $encoded));
-               $hash = self::hash($encoded);
+               $hash = CryptoUtils::hash($encoded);
 
                // Then write it to the next free gap
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: hash=%s', $hash));