PHPEncoder
class PHPEncoder (View source)
A highly customisable library for generating PHP code from variables.
PHPEncoder provides a functionality similar to var_export(), but allows more customisation and wider range of features. Better customisation options make it easier to generate static PHP files when you need the file to formatted in specific way.
Methods
Creates a new PHPEncoder instance.
Sets the value for an encoder option.
Generates the PHP code for the given value.
Returns a list of all encoder options.
Details
at line 50
__construct(array $options = [], array $encoders = null)
Creates a new PHPEncoder instance.
The constructor allows you to provide the list of default encoding options used by the encoder. Note that if you are using custom value encoders, you must provide them in the constructor if you are providing options for them or otherwise the options will be considered invalid.
Using the second parameter you can also provide a list of value encoders used by the encoder. If null is provided, the list of default value encoders will be used instead.
at line 84
addEncoder(Encoder $encoder, bool $prepend = false)
Adds a new encoder.
Values are always encoded by the first encoder that supports encoding that type of value. By setting the second optional parameter to true, you can prepend the encoder to the list to ensure that it will be tested first.
at line 95
setOption(string $option, mixed $value)
Sets the value for an encoder option.
at line 133
string
encode(mixed $variable, array $options = [])
Generates the PHP code for the given value.
at line 144
array
getAllOptions(array $overrides = [])
Returns a list of all encoder options.