Gets the hash key for a value

@param string|float|int|object|array|resource $value The value whose hash key we want
@return string The value's hash key
@throws RuntimeException Thrown if the value's hash key could not be calculated
323435
public function getHashKey($value) : string
    {
        if (is_string($value)) {
            return "__opulence:s:$value";
        }

        if (is_int($value)) {
            return "__opulence:i:$value";
        }

        if (is_float($value)) {
            return "__opulence:f:$value";
        }

        if (is_object($value)) {
            if (method_exists($value, '__toString')) {
                return "__opulence:so:$value";
            }

            return '__opulence:o:' . spl_object_hash($value);
        }

        if (is_array($value)) {
            return '__opulence:a:' . md5(serialize($value));
        }

        if (is_resource($value)) {
            return '__opulence:r:' . "$value";
        }

        // As a last-ditch effort, try to convert the value to a string
        try {
            return '__opulence:u' . (string)$value;
        } catch (Throwable $ex) {
            throw new RuntimeException('Value could not be converted to a key', 0, $ex);
        }
    }
48498
public function validate($value)
    {
        $original = $value;

        // Check if we are using a callable to get the pipeline
        if (is_callable($value) && $value instanceof \Closure) {
            $value = $value($this->container);
        }

        // Check if we have a valid pipeline instance
        if (!$value instanceof $this->contract) {
            throw new \RuntimeException('The configured value does not implement '. $this->contract);
        }

        // All good return original
        return $original;
    }
1193185
public static function hash($value) : string
    {
        if (is_object($value)) {
            if ($value instanceof IHashable) {
                return get_class($value) . ':' . $value->getObjectHash();
            } else {
                return serialize($value);
            }
        }

        return Identity::hash($value);
    }
725960
public function hash(string $password): string
    {
        $hash = password_hash(
            $password,
            $this->hashType,
            $this->hashOptions
        );

        if ($hash === false) {
            throw new RuntimeException('Failed to hash password.');
        }

        return $hash;
    }
1095287
private function makeSerializable($value)
    {
        if (null === $value) {
            return $value;
        }

        if ($value instanceof Traversable || is_array($value)) {
            $value = ArrayUtils::iteratorToArray($value);

            foreach ($value as $key => $val) {
                $value[$key] = $this->makeSerializable($val);
            }

            return $value;
        }

        if (is_scalar($value)) {
            return $value;
        }

        if (is_resource($value)) {
            return 'resource';
        }

        return new ObjectStub($value);
    }
787464
public static function phpToXml($value)
    {
        switch (true) {
            case null === $value:
                return 'null';
            case true === $value:
                return 'true';
            case false === $value:
                return 'false';
            case $value instanceof Parameter:
                return '%'.$value.'%';
            case is_object($value) || is_resource($value):
                throw new RuntimeException('Unable to dump a service container if a parameter is an object or a resource.');
            default:
                return (string) $value;
        }
    }
472027
public function keyOf($value)
    {
        foreach ($this->items as $key => $iValue) {
            if ($value === $iValue) {
                return $key;
            }
        }

        return null;
    }
220083
public function key($value)
    {
        if ($value instanceof Cacheable) {
            return $value->cacheId();
        }

        if (is_scalar($value)) {
            return $value;
        }

        if (is_array($value)) {
            return $this->arrayToKey($value);
        }

        if (is_object($value)) {
            return $this->objectToKey($value);
        }

        return null;
    }
223948
protected function castValueAsJson($value)
    {
        $value = $this->asJson($value);

        if ($value === false) {
            throw new \RuntimeException(
                sprintf(
                    "Unable to encode value [%s] for element [%s] to JSON: %s.",
                    $this->getName(),
                    get_class($this),
                    json_last_error_msg()
                )
            );
        }

        return $value;
    }
1275520
protected function castArrayValue($value)
    {
        if (!is_object($value)) {
            return $this->key($value);
        }

        try {
            if ($key = $this->objectCategorizer->key($value)) {
                return $this->hashIfToLong($key);
            }
        } catch (Exception $e) {
        }

        return $this->hashIfToLong($this->objectToKey($value));
    }
355419
public function getSecretAttribute($value)
  {
    if ($value == null) $this->update(['secret' => $secret = (new Hashids(Hash::random(20), 15))->encode($this->id)]);
    return $value ?? $secret;
  }
755376
private function getStatusString(Value $value): string
    {
        switch ($value->getStatus()) {
            case Value::STATUS_DRAFT:
                return 'DRAFT';
            case Value::STATUS_PUBLISHED:
                return 'PUBLISHED';
            case Value::STATUS_ARCHIVED:
                return 'ARCHIVED';
        }

        throw new RuntimeException(sprintf("Unknown status '%s'", var_export($value->getStatus(), true)));
    }
1233346
private function convertValue($value)
    {
        if (empty($value)) {
            return null;
        }

        if (\is_array($value)) {
            return $value;
        }

        switch ($this->fieldType) {
            case 'radio':
                return $value;
            case 'checkbox':
                $delimiter = (false !== \stripos($value, "\t")) ? "\t" : ',';

                return StringUtil::trimsplit($delimiter, $value);
            default:
        }
        throw new \RuntimeException('Unknown field type encountered: ' . $this->fieldType);
    }
609075
public static function keys($value)
    {

        if (is_array($value)) {
            return array_keys($value);
        }

        if (!is_object($value)) {
            return [];
        }

        if (!$value instanceof Traversable) {
            return array_keys(get_object_vars($value));
        }

        return array_keys(iterator_to_array($value, true));

    }
269690
private function hashKey(string $value): string
    {
        $ret = openssl_digest($value, $this->digestMethod, true);
        if ($ret === false) {
            throw new \Exception("digest failed; ".openssl_error_string());
        }
        return $ret;
    }
765263
public function put($value)
    {
        $len = strlen($value);
        if ($len > 2147483647) {
            throw new \RuntimeException('value is too long');
        }
        $raw = pack('N', $len) . $value;
        $write_len = $this->pipe->write($raw);

        return $write_len == strlen($raw);
    }
18375
public function getKey($value, ?string $defaultKey = null): string
    {
        if ($this->isValidType($value) === false) {
            throw new MWrongTypeException("\$value", $this->getType(), $value);
        }

        $key = array_search($value, $this->map);

        if ($key === false && is_null($defaultKey) === false) {
            $key = $defaultKey;
        }

        return $key;
    }