chubbyphp / chubbyphp-decode-encode
Chubbyphp decode/encode json/jsonx/url-encoded/xml/yaml
Installs: 5 002
Dependents: 6
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.0
- ext-dom: *
- ext-json: *
- ext-mbstring: *
- symfony/yaml: ^4.4.38|^5.4.5|^6.0
Requires (Dev)
- chubbyphp/chubbyphp-container: ^2.1
- chubbyphp/chubbyphp-dev-helper: dev-master
- chubbyphp/chubbyphp-laminas-config-factory: ^1.0
- chubbyphp/chubbyphp-mock: ^1.6.1
- 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
- psr/container: ^2.0.2
This package is auto-updated.
Last update: 2023-03-06 10:49:05 UTC
README
Description
A simple decode/encode solution for json / jsonx / url-encoded / xml / yaml.
Requirements
- php: ^8.0
- symfony/yaml: ^4.4.38|^5.4.5|^6.0
Suggest
- chubbyphp/chubbyphp-container: ^2.1
- psr/container: ^1.1.2|^2.0.2
Installation
Through Composer as chubbyphp/chubbyphp-decode-encode.
composer require chubbyphp/chubbyphp-decode-encode "^1.0"
Usage
Decoder
<?php use Chubbyphp\DecodeEncode\Decoder\Decoder; use Chubbyphp\DecodeEncode\Decoder\JsonTypeDecoder; use Chubbyphp\DecodeEncode\Decoder\JsonxTypeDecoder; use Chubbyphp\DecodeEncode\Decoder\UrlEncodedTypeDecoder; use Chubbyphp\DecodeEncode\Decoder\XmlTypeDecoder; use Chubbyphp\DecodeEncode\Decoder\YamlTypeDecoder; $decoder = new Decoder([ new JsonTypeDecoder(), new JsonxTypeDecoder(), new UrlEncodedTypeDecoder(), new XmlTypeDecoder(), new YamlTypeDecoder() ]); print_r($decoder->getContentTypes()); //[ // 'application/json', // 'application/jsonx+xml', // 'application/x-www-form-urlencoded', // 'application/xml', // 'application/x-yaml' //] print_r($decoder->decode( '{"name": "php"}', 'application/json' )); // ['name' => 'php']
Type Decoder
Encoder
Encoder
<?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; $encoder = new Encoder([ new JsonTypeEncoder(), new JsonxTypeEncoder(), new UrlEncodedTypeEncoder(), new XmlTypeEncoder(), new YamlTypeEncoder() ]); print_r($encoder->getContentTypes()); //[ // 'application/json', // 'application/jsonx+xml', // 'application/x-www-form-urlencoded', // 'application/xml', // 'application/x-yaml' //] echo $encoder->encode( ['name' => 'php'], 'application/json' ); // '{"name": "php"}'
Type Encoder
ServiceFactory
chubbyphp-laminas-config-factory
Copyright
2023 Dominik Zogg