class ConfigOptimizer

This class creates local variables to deduplicate complex configValues

Properties

protected array $configValues
protected Encoder $encoder
protected array $jsLengths

Methods

__construct(Encoder $encoder)

Constructor

string
getVarDeclarations()

Return the var declarations for all deduplicated config values

array|Dictionary
optimize(array|Dictionary $object)

Optimize given config object

void
reset()

Clear the deduplicated config values stored in this instance

bool
canDeduplicate(mixed $value)

Test whether given value can be deduplicated

void
deduplicateConfigValues()

Mark ConfigValue instances that have been used multiple times

string
getVarName(string $js)

Return the name of the variable that will a given value

bool
isIterable(mixed $value)

Test whether given value is iterable

array|Dictionary
optimizeObjectContent(array|Dictionary $object)

Optimize given object's content

recordObject(array|Code|Dictionary $object)

Record a given config object as a ConfigValue instance

array|Dictionary
recordObjectContent(array|Dictionary $object)

Record the content of given config object

bool
shouldPreserve(mixed $value)

Test whether given value should be preserved and not deduplicated

Details

at line 35
__construct(Encoder $encoder)

Constructor

Parameters

Encoder $encoder

at line 46
string getVarDeclarations()

Return the var declarations for all deduplicated config values

Return Value

string

JavaScript code

at line 69
array|Dictionary optimize(array|Dictionary $object)

Optimize given config object

Parameters

array|Dictionary $object

Original config object

Return Value

array|Dictionary

Modified config object

at line 79
void reset()

Clear the deduplicated config values stored in this instance

Return Value

void

at line 91
protected bool canDeduplicate(mixed $value)

Test whether given value can be deduplicated

Parameters

mixed $value

Return Value

bool

at line 107
protected void deduplicateConfigValues()

Mark ConfigValue instances that have been used multiple times

Return Value

void

at line 126
protected string getVarName(string $js)

Return the name of the variable that will a given value

Parameters

string $js

JavaScript representation of the value

Return Value

string

at line 137
protected bool isIterable(mixed $value)

Test whether given value is iterable

Parameters

mixed $value

Return Value

bool

at line 148
protected array|Dictionary optimizeObjectContent(array|Dictionary $object)

Optimize given object's content

Parameters

array|Dictionary $object

Original object

Return Value

array|Dictionary

Modified object

at line 162
protected ConfigValue recordObject(array|Code|Dictionary $object)

Record a given config object as a ConfigValue instance

Parameters

array|Code|Dictionary $object

Original object

Return Value

ConfigValue

Stored ConfigValue instance

at line 188
protected array|Dictionary recordObjectContent(array|Dictionary $object)

Record the content of given config object

Parameters

array|Dictionary $object

Original object

Return Value

array|Dictionary

Modified object containing ConfigValue instances

at line 207
protected bool shouldPreserve(mixed $value)

Test whether given value should be preserved and not deduplicated

Parameters

mixed $value

Return Value

bool