Skip to content

Latest commit

 

History

History
31 lines (20 loc) · 613 Bytes

JsonTypeDecoder.md

File metadata and controls

31 lines (20 loc) · 613 Bytes

JsonTypeDecoder

<?php

use Chubbyphp\DecodeEncode\Decoder\JsonTypeDecoder;

$decoderType = new JsonTypeDecoder();

echo $decoderType->getContentType();
// 'application/json'

print_r($decoderType->decode('{"name": "php"}'));
// ['name' => 'php']

with custom content type

<?php

use Chubbyphp\DecodeEncode\Decoder\JsonTypeDecoder;

$decoderType = new JsonTypeDecoder('application/problem+json');

echo $decoderType->getContentType();
// 'application/problem+json'

print_r($decoderType->decode('{"type": "about:blank", "status": 400}'));
// ['type' => 'about:blank', 'status' => 400]