EnumFormatter
in package
FinalYes
Formatting strategies (exclusive): - Name (UnitEnum::name) - Value (BackedEnum::value) - JSON (JsonSerializable) - callback
Table of Contents
Constants
- CALLBACK_FORMAT = 'callback'
- JSON_FORMAT = 'json'
- NAME_FORMAT = 'name'
- VALUE_FORMAT = 'value'
Properties
Methods
- __invoke() : array<string|int, mixed>
- Enable using the class as a formatter for the {@link Writer}.
- encode() : mixed
- Encodes the UnitEnum in a representation suitable to be used by PHP's fputcsv and fwrite functions without emitting errors
- usingCallback() : self
- Register a callback that will convert the UnitEnum in a representation suitable to be used by PHP's fputcsv and fwrite functions without emitting errors
- usingJson() : self
- usingName() : self
- usingValue() : self
- __construct() : mixed
Constants
CALLBACK_FORMAT
private
mixed
CALLBACK_FORMAT
= 'callback'
JSON_FORMAT
private
mixed
JSON_FORMAT
= 'json'
NAME_FORMAT
private
mixed
NAME_FORMAT
= 'name'
VALUE_FORMAT
private
mixed
VALUE_FORMAT
= 'value'
Properties
$callback read-only
private
Closure|null
$callback
$format read-only
private
string
$format
Methods
__invoke()
Enable using the class as a formatter for the {@link Writer}.
public
__invoke(array<string|int, mixed> $record) : array<string|int, mixed>
Parameters
- $record : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>encode()
Encodes the UnitEnum in a representation suitable to be used by PHP's fputcsv and fwrite functions without emitting errors
public
encode(UnitEnum $value) : mixed
Parameters
- $value : UnitEnum
Tags
usingCallback()
Register a callback that will convert the UnitEnum in a representation suitable to be used by PHP's fputcsv and fwrite functions without emitting errors
public
static usingCallback(callable(UnitEnum): mixed $callback) : self
Parameters
- $callback : callable(UnitEnum): mixed
Return values
selfusingJson()
public
static usingJson() : self
Return values
selfusingName()
public
static usingName() : self
Return values
selfusingValue()
public
static usingValue() : self
Return values
self__construct()
private
__construct(string $format, Closure|null $callback) : mixed
Parameters
- $format : string
- $callback : Closure|null