|
1 |
| -## Data Coder |
| 1 | +# A flexible data coder for encoding and decoding formats like JSON, YAML, and more. |
2 | 2 |
|
3 |
| -### A flexible data coder for encoding and decoding formats like JSON, YAML, and more. |
| 3 | +## Resources |
4 | 4 |
|
5 |
| -[](https://scrutinizer-ci.com/g/sunrise-php/coder/?branch=master) |
6 |
| -[](https://scrutinizer-ci.com/g/sunrise-php/coder/?branch=master) |
7 |
| -[](https://packagist.org/packages/sunrise/coder) |
8 |
| - |
9 |
| -## Installation |
10 |
| - |
11 |
| -```bash |
12 |
| -composer require sunrise/coder |
13 |
| -``` |
14 |
| - |
15 |
| -## How to use |
16 |
| - |
17 |
| -### Quick Start |
18 |
| - |
19 |
| -```php |
20 |
| -use Sunrise\Coder\CodecManager; |
21 |
| -use Sunrise\Coder\Codec\JsonCodec; |
22 |
| -use Sunrise\Coder\Codec\UrlEncodedCodec; |
23 |
| -use Sunrise\Coder\Dictionary\MediaType; |
24 |
| - |
25 |
| -$codecManager = new CodecManager(codecs: [ |
26 |
| - new JsonCodec(), |
27 |
| - new UrlEncodedCodec(), |
28 |
| -]); |
29 |
| - |
30 |
| -// Encoding result: {"foo": "bar"} |
31 |
| -$codecManager->encode(MediaType::JSON, ['foo' => 'bar']); |
32 |
| -// Decoding result: ['foo' => 'bar'] |
33 |
| -$codecManager->decode(MediaType::JSON, '{"foo": "bar"}'); |
34 |
| - |
35 |
| -// Encoding result: foo=bar |
36 |
| -$codecManager->encode(MediaType::UrlEncoded, ['foo' => 'bar']); |
37 |
| -// Decoding result: ['foo' => 'bar'] |
38 |
| -$codecManager->decode(MediaType::UrlEncoded, 'foo=bar'); |
39 |
| -``` |
40 |
| - |
41 |
| -### PHP-DI definitions |
42 |
| - |
43 |
| -```php |
44 |
| -use DI\ContainerBuilder; |
45 |
| -use Sunrise\Coder\CodecManagerInterface; |
46 |
| - |
47 |
| -$containerBuilder = new ContainerBuilder(); |
48 |
| -$containerBuilder->addDefinition(__DIR__ . '/../vendor/sunrise/coder/resources/definitions/coder.php'); |
49 |
| -$containerBuilder->addDefinition(__DIR__ . '/../vendor/sunrise/coder/resources/definitions/codecs/json_codec.php'); |
50 |
| -$containerBuilder->addDefinition(__DIR__ . '/../vendor/sunrise/coder/resources/definitions/codecs/url_encoded_codec.php'); |
51 |
| - |
52 |
| -$container = $containerBuilder->build(); |
53 |
| - |
54 |
| -// See above for usage examples. |
55 |
| -$codecManager = $container->get(CodecManagerInterface::class); |
56 |
| -``` |
57 |
| - |
58 |
| -## Tests |
59 |
| - |
60 |
| -```bash |
61 |
| -composer test |
62 |
| -``` |
| 5 | +- [Documentation](https://dev.sunrise-studio.io/docs/packages/sunrise/coder/) |
0 commit comments