Encodes data as a JSON string representation.

@param mixed $data
@param int   $options

@throws \Rexlabs\Smokescreen\Exception\JsonEncodeException

@return string
487141
public static function encode($data, $options = 0): string
    {
        $json = json_encode($data, $options);
        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new JsonEncodeException(json_last_error_msg());
        }

        return $json;
    }
107138
public function encode(array $data)
    {
        $data = $this->escapeFloatsIfNeeded($data);

        $json = json_encode($data, $this->jsonEncodeOptions);
        if ($json === false || json_last_error() != JSON_ERROR_NONE) {
            if (json_last_error() != JSON_ERROR_UTF8) {
                throw new JsonSerializerException('Invalid data to encode to JSON. Error: ' . json_last_error_msg());
            }

            $data = $this->encodeNonUtf8ToUtf8($data);
            $json = json_encode($data, $this->jsonEncodeOptions);

            if ($json === false || json_last_error() != JSON_ERROR_NONE) {
                throw new JsonSerializerException('Invalid data to encode to JSON. Error: ' . json_last_error_msg());
            }
        }

        return $this->unescapeFloatsIfNeeded($json);
    }
994518
public function jsonEncode($data)
    {
        if (is_array($data)) {
            $ret = "";
            $blWasOne = false;
            $blNumerical = true;
            reset($data);
            while ($blNumerical && $key = key($data)) {
                $blNumerical = !is_string($key);
            }
            if ($blNumerical) {
                return '[' . implode(',', array_map([$this, 'jsonEncode'], $data)) . ']';
            } else {
                foreach ($data as $key => $val) {
                    if ($blWasOne) {
                        $ret .= ',';
                    } else {
                        $blWasOne = true;
                    }
                    $ret .= '"' . addslashes($key) . '":' . $this->jsonEncode($val);
                }

                return "{" . $ret . "}";
            }
        } else {
            return '"' . addcslashes((string) $data, "\r\n\t\"\\") . '"';
        }
    }
465232
public static function dump(string $filename, $data, array $options = []): bool
    {
        return file_put_contents($filename, self::encode($data, $options)) !== false;
    }
139942
public function embedData($data, $options=[]) {
		$image = \Swift_Image::newInstance($data);
		if(isset($options['filename']))
			$image->setFilename($options['filename']);
		if(isset($options['mime']))
			$image->setContentType($options['mime']);
		return $this->embed($image);
	}
1027637
public function toJson($options = 0)
	{
		$json = json_encode($this->jsonSerialize(), $options);

		if (JSON_ERROR_NONE !== json_last_error()) {
			throw JsonEncodingException::forObject($this, json_last_error_msg());
		}

		return $json;
	}
1182003
public function setJsonBody(array $data, int $options=JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK)
  {
    $this->setContentType('application/json')
         ->setBody( json_encode($data,$options) );

    return $this;
  }
1203793
public function setJsonOptions($options)
    {
        $this->encodingOptions = (int) $options;

        return $this->setData($this->getData());
    }
1370181
protected static function _arrayToString($data, $options)
    {
        if (empty($data)) {
            return '[]';
        }

        extract($options['array']);
        /**
         * @var string $char
         * @var int $indent
         * @var int $multiplier
         */
        $comma = false;

        $tab = str_repeat($char, $indent * $multiplier);

        $string = "[\n";

        foreach ($data as $key => $value) {
            if ($comma) {
                $string .= ",\n";
            }
            $comma = true;
            $key = filter_var($key, FILTER_VALIDATE_INT) ? $key : static::dump($key, $options['quote']);
            $string .= $tab . $key . ' => ';
            if (is_array($value)) {
                $options['array']['indent'] = $indent + 1;
                $string .= static::_arrayToString($value, $options);
            } else {
                $string .= static::toString($value, $options);
            }
        }
        $tab = str_repeat($char, ($indent - 1) * $multiplier);
        return $string . "\n" . $tab . "]";
    }
220788
public static function encode(/*mixed*/ $data) {
    $json = json_encode($data, JSON_UNESCAPED_SLASHES);

    // Turn some special characters into their JSON representation.
    $json = str_replace(["\t", "\r", "\n"], ['\\t', '\\r', '\\n'], $json);

    return $json;
  }
801681
public static function encode($value, $options = JSON_UNESCAPED_UNICODE | JSON_NUMERIC_CHECK)
    {
        if ($value instanceof \Traversable)
        {
            $value = \iterator_to_array($value);
        }

        return \json_encode($value, $options);
    }
1323036
public function update($data, $options)
    {
        $set  = [];
        $data = $this->parseData($data, $options);
        if (empty($data)) {
            return '';
        }
        foreach ($data as $key => $val) {
            $set[] = $key . '=' . $val;
        }

        $sql = str_replace(
            ['%TABLE%', '%SET%', '%JOIN%', '%WHERE%', '%ORDER%', '%LIMIT%', '%LOCK%', '%COMMENT%'],
            [
                $this->parseTable($options['table'], $options),
                implode(',', $set),
                $this->parseJoin($options['join'], $options),
                $this->parseWhere($options['where'], $options),
                $this->parseOrder($options['order'], $options),
                $this->parseLimit($options['limit']),
                $this->parseLock($options['lock']),
                $this->parseComment($options['comment']),
            ], $this->updateSql);

        return $sql;
    }
1159660
private function convertToJson($data)
    {
        if (is_array($data)) {
            return json_encode($data);
        }

        if ($data instanceof Jsonable) {
            return $data->toJson();
        }

        if ($data instanceof Arrayable) {
            return json_encode($data->toArray());
        }

        return null;
    }
766824
protected function jsonEncode($data)
    {
        $return = json_encode($data);

        if ($return === false) {
            throw new ConverterException(
                sprintf(
                    "Could not convert %s data to JSON. Driver returned '%s'.",
                    gettype($data),
                    json_last_error()
                )
            );
        }

        return $return;
    }
541801
protected function encodeData(array $data): string
    {
        $json = \json_encode(
            $data,
            JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
        );

        return \base64_encode($json);
    }
249125
public static final function jsonEncode($data, array $options = null): array
    {
        $encoder = new JsonEncoder($options);

        return [$encoder->encode($data), $encoder->hasError()
            ? new EncoderException('JSON Error: '. $encoder->getError()) : null];
    }
1268853
public function createFromArrayWithContext($data, $options)
    {
        $_edgeClass = $this->_edgeClass;

        return $_edgeClass::createFromArray($data, $options);
    }