class Js implements Htmlable, Stringable

Constants

protected REQUIRED_FLAGS

Flags that should be used when encoding to JSON.

Properties

protected string $js

The JavaScript string.

Methods

__construct(mixed $data, int $flags = 0, int $depth = 512)

Create a new class instance.

static Js
from(mixed $data, int $flags = 0, int $depth = 512)

Create a new JavaScript string from the given data.

string
convertDataToJavaScriptExpression(mixed $data, int $flags = 0, int $depth = 512)

Convert the given data to a JavaScript expression.

static string
encode(mixed $data, int $flags = 0, int $depth = 512)

Encode the given data as JSON.

string
convertJsonToJavaScriptExpression(string $json, int $flags = 0)

Convert the given JSON to a JavaScript expression.

string
toHtml()

Get the string representation of the data for use in HTML.

string
__toString()

Get the string representation of the data for use in HTML.

Details

at line 39
__construct(mixed $data, int $flags = 0, int $depth = 512)

Create a new class instance.

Parameters

mixed $data
int $flags
int $depth

Exceptions

JsonException

at line 49
static Js from(mixed $data, int $flags = 0, int $depth = 512)

Create a new JavaScript string from the given data.

Parameters

mixed $data
int $flags
int $depth

Return Value

Js

Exceptions

JsonException

at line 59
protected string convertDataToJavaScriptExpression(mixed $data, int $flags = 0, int $depth = 512)

Convert the given data to a JavaScript expression.

Parameters

mixed $data
int $flags
int $depth

Return Value

string

Exceptions

JsonException

at line 92
static string encode(mixed $data, int $flags = 0, int $depth = 512)

Encode the given data as JSON.

Invalid UTF-8 sequences are replaced with � instead of throwing.

Parameters

mixed $data
int $flags
int $depth

Return Value

string

Exceptions

JsonException

at line 110
protected string convertJsonToJavaScriptExpression(string $json, int $flags = 0)

Convert the given JSON to a JavaScript expression.

Parameters

string $json
int $flags

Return Value

string

Exceptions

JsonException

at line 126
string toHtml()

Get the string representation of the data for use in HTML.

Return Value

string

at line 134
string __toString()

Get the string representation of the data for use in HTML.

Return Value

string