botanick/serializer
Laravel/PHP serializer package for converting objects and arrays to structured formats and back. Aims to simplify data transformation with configurable normalization/denormalization for APIs, DTOs, and persistence layers.
ScalarSerializer can convert only PHP scalars.
$scalarSerializer = new \Botanick\Serializer\Serializer\DataSerializer\ScalarSerializer();
$scalarSerializer->setDefaultOptions($defaultOptions);
if ($scalarSerializer->supports($data)) {
$serializedData = $scalarSerializer->serialize($data, null, $options);
}
array(
'type' => 'bool', // supports: 'bool', 'boolean', 'int', 'integer', 'number', 'float', 'double', 'real', 'string'
'format' => 'anything processable by sprintf() containing one and only one placeholder (e.g. %s)'
)
is_scalar($data)
When type is provided and is one of supported ones, then an argument will be converted using (casting) (e.g. return (bool)$data;).
If format option is provided, then sprintf($format, $data) is used.
If neither supported type nor format is provided, then serializer returns an argument itself.
How can I help you explore Laravel packages today?