chubbyphp / chubbyphp-serialization
Chubbyphp Serialize
Installs: 48 932
Dependents: 2
Suggesters: 0
Security: 0
Stars: 26
Watchers: 3
Forks: 3
Open Issues: 0
Requires
- php: ^8.2
- ext-dom: *
- ext-json: *
- ext-mbstring: *
- chubbyphp/chubbyphp-decode-encode: ^1.1
- doctrine/inflector: ^1.4.4|^2.0.10
- psr/http-message: ^1.1|^2.0
- psr/link: ^1.1.1|^2.0.1
- psr/log: ^2.0|^3.0.2
Requires (Dev)
- chubbyphp/chubbyphp-container: ^2.2
- chubbyphp/chubbyphp-dev-helper: dev-master
- chubbyphp/chubbyphp-laminas-config-factory: ^1.3
- chubbyphp/chubbyphp-mock: ^1.8.0
- doctrine/collections: ^2.2.2
- doctrine/persistence: ^4.0
- infection/infection: ^0.29.8
- php-coveralls/php-coveralls: ^2.7.0
- phpstan/extension-installer: ^1.4.3
- phpstan/phpstan: ^2.0.3
- phpunit/phpunit: ^11.5.0
- pimple/pimple: ^3.5
- psr/container: ^2.0.2
- symfony/config: ^5.4.46|^6.4.14|^7.2
- symfony/dependency-injection: ^5.4.46|^6.4.14|^7.2
- dev-master / 4.2.x-dev
- 4.1.0
- 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-12-07 16:15:30 UTC
README
Description
A simple serialization.
Requirements
- php: ^8.2
- chubbyphp/chubbyphp-decode-encode: ^1.1
- doctrine/inflector: ^1.4.4|^2.0.10
- psr/http-message: ^1.1|^2.0
- psr/link: ^1.1.1|^2.0.1
- psr/log: ^2.0|^3.0.2
Suggest
- chubbyphp/chubbyphp-container: ^2.2
- pimple/pimple: ^3.5
- psr/container: ^2.0.2
- symfony/config: ^5.4.46|^6.4.14|^7.2 (symfony integration)
- symfony/dependency-injection: ^5.4.46|^6.4.14|^7.2 (symfony integration)
Installation
Through Composer as chubbyphp/chubbyphp-serialization.
composer require chubbyphp/chubbyphp-serialization "^4.1"
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