Подготавливает данные для передачи json_encode

@param mixed $data
@return mixed
180283
private function prepareResponseData($data)
    {
        switch (true)
        {
            case is_object($data):
                if (method_exists($data, 'toArray'))
                {
                    $data = $data->toArray();
                }
                else
                {
                    $data = get_object_vars($data);
                }
                $data = $this->prepareResponseData($data);
                break;
            case is_array($data):
                foreach ($data as $key => $value)
                {
                    $data[$key] = $this->prepareResponseData($value);
                }
                break;
        }
        return $data;
    }
1173644
protected function _jsonEncode($data)
    {
        return is_string($data) ? $data : json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . PHP_EOL;
    }
874694
private function deserializeData($data)
    {
        $result = $this->get('jms_serializer')->deserialize(
            $data,
            $this->getTargetGroupRepository()->getClassName(),
            'json',
            DeserializationContext::create()
                ->setSerializeNull(true)
        );

        return $result;
    }
1352219
public function encodeArray($data) {
        $d = array();
        foreach ($data as $key => $value) {
            if (is_string($key))
                $key = htmlspecialchars($key);
            if (is_string($value))
                $value = htmlspecialchars($value);
            elseif (is_array($value))
                $value = self::encodeArray($value);
            $d[$key] = $value;
        }
        return $d;
    }
613870
protected function encode(array $data)
    {

        foreach ($data as $key => $value) {
            if (is_string($value)) {
                $data[$key] = base64_encode($value);
            }
        }

        return $data;
    }
917928
public static function encode($data)
    {
        switch (gettype($data)) {
            case 'array':
                return self::encodeArray($data);
            case 'object':
                return self::encodeObject($data);
            case 'string':
                return self::encodeString($data);
            case 'integer':
                return self::encodeInteger($data);
            case 'boolean':
                return self::encodeBoolean($data);
            case 'double':
                return self::encodeDouble($data);
            case 'NULL':
                return self::encodeNull($data);
            case 'resource':
                // TODO
                break;
            default:
                throw new UnencodeableException('Contains unencodeable type', 3);
        }
    }
420957
public static function decodeData($data)
    {
        if (\is_array($data)) {
            foreach ($data as $key => $value) {
                $data[$key] = \urldecode($value);
            }

            return $data;
        }

        return \urldecode($data);
    }
1275242
public function encode($data, $options = 0) {
        $json = null;

        if ($data instanceof IArrayable) {
            $json = @json_encode($data->toArray(), $options);
        } else if ($data instanceof IJsonable) {
            $json = $data->toJson($options);
        } else if (is_array($data) || is_object($data)) {
            $json =  @json_encode($data, $options);
        } else {
            throw new InvalidDataTypeException(
                s('Can not convert data of type "%s" to json.', get_type($data))
            );
        }

        if ($json === false) {
            throw new JsonEncodeException(json_last_error_msg(), $data);
        }

        return $json;
    }
1107482
public function encode($data)
    {
        // loop over params, look for closure
        if (
            // not a server exception
            !($data instanceof \Plinker\Core\Exception\Server) &&
            // params should be set & array
            isset($data['params']) && is_array($data['params'])) {
            foreach ($data['params'] as $key => $param) {
                if (is_object($param) && ($param instanceof \Closure)) {
                    $data['params'][$key] = new SerializableClosure($param);
                }
            }
        }
        
        $data = serialize($data);

        return [
            "data"  => $this->encrypt($data, $this->config["secret"]),
            "token" => hash_hmac(
                "sha256",
                $data,
                $this->config["secret"]
            )
        ];
    }
1350191
public static function EncodeJson (& $data) {
		$flags = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP |
			(defined('JSON_UNESCAPED_SLASHES') ? JSON_UNESCAPED_SLASHES : 0) |
			(defined('JSON_UNESCAPED_UNICODE') ? JSON_UNESCAPED_UNICODE : 0) |
			(defined('JSON_PRESERVE_ZERO_FRACTION') ? JSON_PRESERVE_ZERO_FRACTION : 0);
		$json = json_encode($data, $flags);
		if ($errorCode = json_last_error()) {
			$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
			throw new \RuntimeException("[".$selfClass."] ".json_last_error_msg(), $errorCode);
		}
		if (PHP_VERSION_ID < 70100) {
			$json = strtr($json, [
				"\xe2\x80\xa8" => '\u2028',
				"\xe2\x80\xa9" => '\u2029',
			]);
		}
		return $json;
	}
1203570
public static function encode($data): string
    {
        if (PHP_VERSION_ID >= 50400) {
            return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
        }

        return json_encode($data);
    }
528809
protected function convertEncoding($data)
    {
        if ($this->getEncodingInput() == $this->getEncodingOutput()) {
            return $data;
        }

        if (is_null($data)) {
            return $data;
        }

        if (is_array($data)) {
            foreach ($data as $key => $value) {
                $data[$key] = $this->convertEncoding($value);
            }

            return $data;
        }

        if ($this->getEncodingOutput() == 'UTF-8') {
            return utf8_encode($data);
        }

        return utf8_decode($data);
    }
1362239
public function appendJson($data)
    {
        $jsonData = json_decode($data, true);

        if (is_null($jsonData)) {
            $this->_errorsList['json_decode'] = 'Json cannot be decoded.';
            $this->_hasErrors = true;
            return $this;
        }

        $this->appendArray($jsonData);

        if ($this->_objectCreation) {
            return $this->_afterAppendDataToNewObject();
        }
        return $this;
    }
289559
public function encode($data): string
    {
        $encoded = \json_encode($data, \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE);
        if (\json_last_error() !== JSON_ERROR_NONE) {
            throw new EncodingException(\json_last_error_msg());
        }
        return $encoded;
    }
856053
static public function encode($data)
	{
	    if (is_array($data)) {
	        foreach ($data as $k=>$v) {
	            if (is_array($v)) {
	                if (empty($v)) {
	                    $data[$k] = null;
	                } else {
	                    $data[$k] = implode('|', $v);
	                }
	            }
	        }
	        $data = implode(",", $data);
	    } elseif ((is_object($data) && !method_exists($data, '_toString'))) {
	        throw new \InvalidArgumentException(__CLASS__ . ' can not handle an array or non-stringable object.');
	    }

		return $data;
	}
1240560
public function encode($data) : string
    {
        $result = json_encode($data, $this->options, $this->maxDepth);

        $this->checkLastError();

        return $result;
    }
1251789
public function json(array $data)
    {
        $data = json_encode($data);
        $response = $this->withHeader('Content-Type', 'application/json');
        $response->getBody()->write($data);

        return $response;
    }