Skip to content

healerz/chubbyphp-deserialization

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chubbyphp-deserialization

Build Status Total Downloads Latest Stable Version Scrutinizer Code Quality Code Coverage

Description

A simple deserialization.

Requirements

  • php: ~7.0
  • psr/http-message: ~1.0
  • psr/log: ~1.0

Suggest

  • container-interop/container-interop: ~1.0
  • pimple/pimple: ~3.0
  • symfony/yaml: ~2.7|~3.0 (application/x-yaml support)

Installation

Through Composer as chubbyphp/chubbyphp-deserialization.

composer require chubbyphp/chubbyphp-deserialization "~2.0@beta"

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\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 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/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

Provider

Copyright

Dominik Zogg 2017

About

A simple deserialization.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%