Return value of the json-encoded value as a native PHP type

@param  mixed $value

@return string
324275
private function getJsonCastValue($value)
    {
        return method_exists($this, 'fromJson') ? $this->fromJson($value) : json_decode($value, true);
    }
215077
protected function wrapValue($value)
    {
        if ($value === '*') {
            return $value;
        }

        // If the given value is a JSON selector we will wrap it differently than a
        // traditional value. We will need to split this path and wrap each part
        // wrapped, etc. Otherwise, we will simply wrap the value as a string.
        if ($this->isJsonSelector($value)) {
            return $this->wrapJsonSelector($value);
        }

        return '`' . str_replace('`', '``', $value) . '`';
    }
403233
protected function formatParameter($value)
    {
        if (\is_bool($value) || \is_array($value) || (null === $value)) {
            $jsonString = json_encode($value);

            if (preg_match('/^(.{60})./us', $jsonString, $matches)) {
                return $matches[1].'...';
            }

            return $jsonString;
        }

        return (string) $value;
    }
107478
public function encodeValue($value)
    {
        $type = gettype($value);

        switch ($type) {
            case 'boolean':
                return ['booleanValue' => $value];
                break;

            case 'integer':
                return ['integerValue' => $value];
                break;

            case 'double':
                return ['doubleValue' => $value];
                break;

            case 'string':
                return ['stringValue' => $value];
                break;

            case 'resource':
                return ['bytesValue' => stream_get_contents($value)];
                break;

            case 'object':
                return $this->encodeObjectValue($value);
                break;

            case 'array':
                if (!empty($value) && $this->isAssoc($value)) {
                    return $this->encodeAssociativeArrayValue($value);
                }

                return ['arrayValue' => $this->encodeArrayValue($value)];
                break;

            case 'NULL':
                // @todo encode this in a way such that is compatible with a potential future REST transport.
                return ['nullValue' => NullValue::NULL_VALUE];
                break;

            // @codeCoverageIgnoreStart
            default:
                throw new \RuntimeException(sprintf(
                    'Invalid value type %s',
                    $type
                ));
                break;
            // @codeCoverageIgnoreEnd
        }
    }
625882
public function filter($value)
    {
        if (!is_string($value)) {
            return $value;
        }

        return json_decode($value, $this->assoc, $this->depth, $this->options);
    }
526705
public static function getType($value)
    {
        if (preg_match(self::REGEXP_TCP, $value)) {
            return self::TYPE_TCP;
        }

        if (preg_match(self::REGEXP_SSL, $value)) {
            return self::TYPE_SSL;
        }

        if (preg_match(self::REGEXP_UNIX, $value)) {
            return self::TYPE_UNIX;
        }

        return null;
    }
343337
protected function getDataTypeByValue($value)
    {
        if(null === $value)
        {
            return \PDO::PARAM_NULL;
        }
        if(is_bool($value))
        {
            return \PDO::PARAM_BOOL;
        }
        if(is_int($value))
        {
            return \PDO::PARAM_INT;
        }
        return \PDO::PARAM_STR;
    }
484806
protected function resolveValue($value)
    {
        do {
            if ($value instanceof \JsonSerializable) {
                $value = $value->jsonSerialize();
            } elseif ($value instanceof \Closure) {
                $value = $value();
            } else {
                break;
            }
        } while (true);

        return $value;
    }
322955
protected function getDataValue($value)
    {
        if (is_bool($value)) {
            return $value ? 'true' : 'false';
        } elseif (is_array($value)) {
            return Convert::array2json($value);
        } else {
            return Convert::raw2att($value);
        }
    }
963167
public function encode($value)
    {
        $json = json_encode($value);

        if ($code = json_last_error()) $this->throwError($code);

        return $json;
    }
1209546
public static function getStringForTable($value)
    {
        if (true === is_string($value)) {
            return wordwrap($value, self::MAX_STRING_LENGTH, PHP_EOL);
        }

        if (true === is_bool($value)) {
            if (true === $value) {
                return 'TRUE';
            }

            return 'FALSE';
        }

        if ($value instanceof \DateTime) {
            return $value->format('Y-m-d H:i:s');
        }

        if (null === $value) {
            return 'NULL';
        }

        if (true === is_array($value)) {
            $result = [];
            foreach ($value as $arrayIndex => $arrayValue) {
                if (true === is_numeric($arrayIndex)) {
                    $result[] = self::getStringForTable($arrayValue);

                    continue;
                }

                $result[] = sprintf('%s : %s', $arrayIndex, self::getStringForTable($arrayValue));
            }

            return implode(PHP_EOL, $result);
        }

        return json_encode($value);
    }
71920
private function decodeJson($value)
    {
        $decodedValue = json_decode($value, true);
        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new \InvalidArgumentException('JSON parsing error: ' . json_last_error_msg());
        }

        return $decodedValue;
    }
968680
public function getTypeFromValue($value = null)
    {
        $value = ($value === null ? $this->value : $value);
        return array_search($value, self::$typeList);
    }
428549
public function beforeSaveValue($value)
    {
        try
        {
            $value      = Json::encode($value);
        } catch (\Exception $e)
        {
            $value      = "{}";
        }

        return $value;
    }
1143349
public static function stringify($value)
    {
        if (is_string($value)) {
            return $value;
        }
        if ($value === null || is_bool($value)) {
            return var_export($value, true);
        }

        if (is_array($value) || (is_object($value) && !method_exists($value, '__toString'))) {
            return json_encode($value, JSON_ERROR_NONE | JSON_UNESCAPED_SLASHES);
        }
        return (string)$value;
    }
367374
public static function isJson($value): bool
    {
        if (!static::isStringCastable($value)) {
            return false;
        }

        if (((string) $value) === 'null') {
            return true;
        }

        return (json_decode((string) $value) !== null && json_last_error() === JSON_ERROR_NONE);
    }
480250
public function displayValue($value): string
    {
        if ($value === null) {
            return 'NULL';
        }

        if ($value === true) {
            return 'TRUE';
        }

        if ($value === false) {
            return 'FALSE';
        }

        if (is_array($value)) {
            return Json::encode($value);
        }

        return '"' . str_replace('"', '\"', $value) . '"';
    }