- public function writeValueToFile (string $groupId, $value) {
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: groupId=' . $groupId . ',value[' . gettype($value) . ']=' . print_r($value, true));
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ public function writeValueToFile (string $stackName, $value) {
+ // Validate parameter
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: stackName=%s,value[]=%s - CALLED!', $stackName, gettype($value)));
+ if (empty($stackName)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "stackName" is empty');
+ } elseif (is_object($value) || is_resource($value)) {
+ // Not wanted here
+ throw new InvalidArgumentException(sprintf('value[]=%s is not stackable in files', gettype($value)));
+ }
+
+ // Encode/convert the value into a "binary format"
+ $encoded = StringUtils::encodeData($value);
+
+ // 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);
+
+ // Then write it to the next free gap
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: hash=%s', $hash));
+ $data = $this->getIndexInstance()->writeDataToFreeGap($stackName, $hash, $encoded);
+
+ // Return info
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: data[]=%s - EXIT!', gettype($data)));
+ return $data;