A simple deserialization.
- php: ^8.2
- chubbyphp/chubbyphp-decode-encode: ^1.1
- psr/http-message: ^1.1|^2.0
- psr/log: ^2.0|^3.0.2
- chubbyphp/chubbyphp-container: ^2.2
- pimple/pimple: ^3.5
- psr/container: ^2.0.2
- symfony/config: ^5.4.46|^6.4.14|^7.2 (symfony integration)
- symfony/dependency-injection: ^5.4.46|^6.4.14|^7.2 (symfony integration)
Through Composer as chubbyphp/chubbyphp-deserialization.
composer require chubbyphp/chubbyphp-deserialization "^4.2"
- CallbackFieldDenormalizer
- DateTimeImmutableFieldDenormalizer
- FieldDenormalizer
- ConvertTypeFieldDenormalizer
- EmbedManyFieldDenormalizer
- EmbedOneFieldDenormalizer
- ReferenceManyFieldDenormalizer
- ReferenceOneFieldDenormalizer
<?php
use Chubbyphp\DecodeEncode\Decoder\Decoder;
use Chubbyphp\DecodeEncode\Decoder\JsonTypeDecoder;
use Chubbyphp\DecodeEncode\Decoder\JsonxTypeDecoder;
use Chubbyphp\DecodeEncode\Decoder\UrlEncodedTypeDecoder;
use Chubbyphp\DecodeEncode\Decoder\XmlTypeDecoder;
use Chubbyphp\DecodeEncode\Decoder\YamlTypeDecoder;
use Chubbyphp\Deserialization\Denormalizer\Denormalizer;
use Chubbyphp\Deserialization\Denormalizer\DenormalizerObjectMappingRegistry;
use Chubbyphp\Deserialization\Deserializer;
use MyProject\Deserialization\ModelMapping;
use MyProject\Model\Model;
$logger = ...;
$deserializer = new Deserializer(
new Decoder([
new JsonTypeDecoder(),
new JsonxTypeDecoder(),
new UrlEncodedTypeDecoder(),
new XmlTypeDecoder(),
new YamlTypeDecoder()
]),
new Denormalizer(
new DenormalizerObjectMappingRegistry([
new ModelMapping()
]),
$logger
)
);
$model = $deserializer->deserialize(
Model::class,
'{"name": "php"}',
'application/json'
);
echo $model->getName();
// 'php'
print_r($deserializer->getContentTypes());
//[
// 'application/json',
// 'application/jsonx+xml',
// 'application/x-www-form-urlencoded',
// 'application/xml',
// 'application/x-yaml'
//]
print_r($deserializer->decode(
'{"name": "php"}',
'application/json'
));
// ['name' => 'php']
$model = $denormalizer->denormalize(
Model::class,
['name' => 'php']
);
echo $model->getName();
// 'php'
- DenormalizationFieldMappingFactoryFactory
- DenormalizerFactory
- DenormalizerObjectMappingRegistryFactory
- DeserializerFactory
2024 Dominik Zogg