chubbyphp / chubbyphp-serialization
Chubbyphp Serialize
Installs: 40 863
Dependents: 3
Suggesters: 0
Security: 0
Stars: 25
Watchers: 3
Forks: 4
Open Issues: 0
Requires
- php: ^8.0
- ext-dom: *
- ext-json: *
- chubbyphp/chubbyphp-decode-encode: ^1.0.0
- doctrine/inflector: ^1.4.4|^2.0.4
- psr/http-message: ^1.0.1
- psr/link: ^1.0
- psr/log: ^1.1.4|^2.0|^3.0
Requires (Dev)
- chubbyphp/chubbyphp-container: ^2.1
- chubbyphp/chubbyphp-dev-helper: dev-master
- chubbyphp/chubbyphp-laminas-config-factory: ^1.2
- chubbyphp/chubbyphp-mock: ^1.6.1
- doctrine/persistence: ^2.3
- infection/infection: ^0.26.5
- php-coveralls/php-coveralls: ^2.5.2
- phploc/phploc: ^7.0.2
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.4.8
- phpunit/phpunit: ^9.5.17
- pimple/pimple: ^3.5
- psr/container: ^1.1.2|^2.0.2
- symfony/config: ^4.4.38|^5.4.5|^6.0
- symfony/dependency-injection: ^4.4.38|^5.4.5|^6.0
- dev-master / 3.3.x-dev
- 3.3.1
- 3.3.0
- 3.2.0
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.1
- 3.0.0
- 3.0-rc1
- v2.x-dev
- 2.15.0
- 2.14.1
- 2.14.0
- 2.13.3
- 2.13.2
- 2.13.1
- 2.13.0
- 2.12.4
- 2.12.3
- 2.12.2
- 2.12.1
- 2.12.0
- 2.11.2
- 2.11.1
- 2.11.0
- 2.10.1
- 2.10.0
- 2.9.0
- 2.8.1
- 2.8.0
- 2.7.2
- 2.7.1
- 2.7.0
- 2.6.1
- 2.6.0
- 2.5.1
- 2.5.0
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.0
- 2.2.0
- 2.1.2
- 2.1.1
- 2.1.0
- 2.1-beta2
- 2.1-beta1
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 2.0-beta6
- 2.0-beta5
- 2.0-beta4
- 2.0-beta3
- 2.0-beta2
- 2.0-beta1
- 2.0-alpha10
- 2.0-alpha9
- 2.0-alpha8
- 2.0-alpha7
- 2.0-alpha6
- 2.0-alpha5
- 2.0-alpha4
- 2.0-alpha3
- 2.0-alpha2
- 2.0-alpha1
- v1.x-dev
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.2
- 1.0.1
- 1.0.0
- 1.0-beta2
- 1.0-beta1
- 1.0-alpha1
This package is auto-updated.
Last update: 2023-01-06 10:31:05 UTC
README
Description
A simple serialization.
Requirements
- php: ^8.0
- chubbyphp/chubbyphp-decode-encode: ^1.0.0
- doctrine/inflector: ^1.4.4|^2.0.4
- psr/http-message: ^1.0.1
- psr/link: ^1.0
- psr/log: ^1.1.4|^2.0|^3.0
Suggest
- chubbyphp/chubbyphp-container: ^2.1
- pimple/pimple: ^3.5
- psr/container: ^1.1.2|^2.0.2
- symfony/dependency-injection: ^4.4.38|^5.4.5|^6.0 (symfony integration)
Installation
Through Composer as chubbyphp/chubbyphp-serialization.
composer require chubbyphp/chubbyphp-serialization "^3.3"
Usage
Accessor
Encoder
Type Encoder
Link
Normalizer
Field Normalizer
Relation Field Normalizer
- EmbedManyFieldNormalizer
- EmbedOneFieldNormalizer
- ReferenceManyFieldNormalizer
- ReferenceOneFieldNormalizer
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
2023 Dominik Zogg