chubbyphp/chubbyphp-deserialization

Chubbyphp Deserialize

3.3.4 2021-10-03 10:24 UTC

README

CI Coverage Status Infection MSI Latest Stable Version Total Downloads Monthly Downloads

bugs code_smells coverage duplicated_lines_density ncloc sqale_rating alert_status reliability_rating security_rating sqale_index vulnerabilities

Description

A simple deserialization.

Requirements

  • php: ^7.4|^8.0
  • psr/http-message: ^1.0.1
  • psr/log: ^1.1.3
  • symfony/yaml: ^4.4.34|^5.3.11|^6.0.0

Suggest

  • chubbyphp/chubbyphp-container: ^1.1
  • pimple/pimple: ^3.3
  • psr/container: ^1.0
  • symfony/dependency-injection: ^4.4.34|^5.3.11|^6.0.0 (symfony integration)

Installation

Through Composer as chubbyphp/chubbyphp-deserialization.

composer require chubbyphp/chubbyphp-deserialization "^3.3"

Usage

Accessor

Decoder

Type Decoder

Denormalizer

Field Denormalizer

Relation Field Denormalizer

Denormalizer Context

DenormalizerObjectMappingRegistry

Deserializer

<?php

use Chubbyphp\Deserialization\Decoder\Decoder;
use Chubbyphp\Deserialization\Decoder\JsonTypeDecoder;
use Chubbyphp\Deserialization\Decoder\JsonxTypeDecoder;
use Chubbyphp\Deserialization\Decoder\UrlEncodedTypeDecoder;
use Chubbyphp\Deserialization\Decoder\XmlTypeDecoder;
use Chubbyphp\Deserialization\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'

Mapping

DenormalizationFieldMapping

DenormalizationObjectMapping

LazyDenormalizationObjectMapping

Policy

ServiceFactory

chubbyphp-container

chubbyphp-laminas-config-factory

ServiceProvider

Copyright

Dominik Zogg 2021