chubbyphp / chubbyphp-serialization
Chubbyphp Serialize
Installs: 48 455
Dependents: 2
Suggesters: 0
Security: 0
Stars: 27
Watchers: 3
Forks: 4
Open Issues: 0
Requires
- php: ^8.1
- ext-dom: *
- ext-json: *
- ext-mbstring: *
- 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
Requires (Dev)
- chubbyphp/chubbyphp-container: ^2.2
- chubbyphp/chubbyphp-dev-helper: dev-master
- chubbyphp/chubbyphp-laminas-config-factory: ^1.3
- chubbyphp/chubbyphp-mock: ^1.7.0
- doctrine/collections: ^2.1.4
- doctrine/persistence: ^3.2
- infection/infection: ^0.27.8
- php-coveralls/php-coveralls: ^2.7.0
- phpstan/extension-installer: ^1.3.1
- phpstan/phpstan: ^1.10.45
- phpunit/phpunit: ^10.4.2
- pimple/pimple: ^3.5
- psr/container: ^2.0.2
- symfony/config: ^5.4.31|^6.3.8|^7.0
- symfony/dependency-injection: ^5.4.31|^6.3.8|^7.0
- dev-master / 4.0.x-dev
- 4.0.0
- v3.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: 2024-10-10 17:22:07 UTC
README
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
- 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
2024 Dominik Zogg