Giter Site home page Giter Site logo

chubbyphp-serialization's Introduction

chubbyphp-serialization

CI Coverage Status Mutation testing badge 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 serialization.

Requirements

  • php: ^8.1
  • chubbyphp/chubbyphp-decode-encode: ^1.1
  • doctrine/inflector: ^1.4.4|^2.0.8
  • psr/http-message: ^1.1|^2.0
  • psr/link: ^1.1.1|^2.0.1
  • psr/log: ^2.0|^3.0

Suggest

  • chubbyphp/chubbyphp-container: ^2.2
  • pimple/pimple: ^3.5
  • psr/container: ^2.0.2
  • symfony/dependency-injection: ^5.4.31|^6.3.8|^7.0 (symfony integration)

Installation

Through Composer as chubbyphp/chubbyphp-serialization.

composer require chubbyphp/chubbyphp-serialization "^4.0"

Usage

Accessor

Encoder

Type Encoder

Link

Normalizer

Field Normalizer

Relation Field Normalizer

Link Normalizer

Normalizer Context

NormalizerObjectMappingRegistry

Mapping

NormalizationFieldMapping

NormalizationLinkMapping

NormalizationObjectMapping

LazyNormalizationObjectMapping

Policy

ServiceFactory

chubbyphp-container

chubbyphp-laminas-config-factory

ServiceProvider

Serializer

<?php

use Chubbyphp\DecodeEncode\Encoder\Encoder;
use Chubbyphp\DecodeEncode\Encoder\JsonTypeEncoder;
use Chubbyphp\DecodeEncode\Encoder\JsonxTypeEncoder;
use Chubbyphp\DecodeEncode\Encoder\UrlEncodedTypeEncoder;
use Chubbyphp\DecodeEncode\Encoder\XmlTypeEncoder;
use Chubbyphp\DecodeEncode\Encoder\YamlTypeEncoder;
use Chubbyphp\Serialization\Normalizer\Normalizer;
use Chubbyphp\Serialization\Normalizer\NormalizerObjectMappingRegistry;
use Chubbyphp\Serialization\Serializer;
use MyProject\Serialization\ModelMapping;
use MyProject\Model\Model;
use Psr\Http\Message\ServerRequestInterface;

$logger...;

$serializer = new Serializer(
    new Normalizer(
        new NormalizerObjectMappingRegistry([
            new ModelMapping()
        ]),
        $logger
    ),
    new Encoder([
        new JsonTypeEncoder(),
        new JsonxTypeEncoder(),
        new UrlEncodedTypeEncoder(),
        new XmlTypeEncoder(),
        new YamlTypeEncoder()
    ])
);

$model = new Model;
$model->setName('php');

$json = $serializer->serialize(
    $model,
    'application/json'
);

echo $json;
// '{"name": "php"}'

$model = new Model;
$model->setName('php');

$data = $serializer->normalize(
    $model
);

print_r($data);
// ['name' => 'php']

print_r($serializer->getContentTypes());
//[
//    'application/json',
//    'application/jsonx+xml',
//    'application/x-www-form-urlencoded',
//    'application/xml',
//    'application/x-yaml'
//]

echo $serializer->encode(
    ['name' => 'php'],
    'application/json'
);
// '{"name": "php"}'

Copyright

2024 Dominik Zogg

chubbyphp-serialization's People

Contributors

dominikzogg avatar haeber avatar healerz avatar komando82 avatar marko-ilic avatar mavimo avatar timesplinter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

chubbyphp-serialization's Issues

4.0-dev

Hi @healerz @marko-ilic

I working on official PHP 8.3 support of my libraries. For this one i took the change to get rid of the deprecations. Would be great if you could test it with 4.0@dev if you're still using it.

Best

object instead of meta-type

<?xml version="1.0" encoding="UTF-8"?>
<meta-type value="patient-search">
    <page type="integer">1</page>
    <perPage type="integer">1</perPage>
    <sort></sort>
    <order type="string">asc</order>
    <meta-embedded>
        <count type="integer">0</count>
        <pages type="integer">0</pages>
        <patients></patients>
    </meta-embedded>
    <meta-links>
        <self>
            <href type="string">
                <![CDATA[/api/patients?page=1&perPage=1&order=asc]]>
            </href>
            <method type="string">GET</method>
        </self>
        <create>
            <href type="string">/api/patients</href>
            <method type="string">POST</method>
        </create>
    </meta-links>
</meta-type>

=>

<?xml version="1.0" encoding="UTF-8"?>
<object type="patient-search">
    <page type="integer">1</page>
    <perPage type="integer">1</perPage>
    <sort></sort>
    <order type="string">asc</order>
    <meta-embedded>
        <count type="integer">0</count>
        <pages type="integer">0</pages>
        <patients></patients>
    </meta-embedded>
    <meta-links>
        <self>
            <href type="string">
                <![CDATA[/api/patients?page=1&perPage=1&order=asc]]>
            </href>
            <method type="string">GET</method>
        </self>
        <create>
            <href type="string">/api/patients</href>
            <method type="string">POST</method>
        </create>
    </meta-links>
</object>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.