Skip to content

Commit 5d01852

Browse files
authored
Merge pull request #4 from wayofdev/docs/readme
2 parents fe4a70c + ed9fe32 commit 5d01852

File tree

2 files changed

+87
-29
lines changed

2 files changed

+87
-29
lines changed

README.md

+63-11
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,65 @@
1717
<a href="https://packagist.org/packages/wayofdev/laravel-symfony-serializer"><img src="https://img.shields.io/packagist/l/wayofdev/laravel-symfony-serializer?style=flat-square&color=blue" alt="Software License"/></a>
1818
<a href="https://packagist.org/packages/wayofdev/laravel-symfony-serializer"><img alt="Commits since latest release" src="https://img.shields.io/github/commits-since/wayofdev/laravel-symfony-serializer/latest?style=flat-square"></a>
1919
</div>
20-
2120
<br>
2221

23-
# Laravel Package Template
22+
# Laravel Symfony Serializer
2423

25-
This is minimal Laravel template which is used by other PHP projects in wayofdev organization.
24+
## 📄 About
2625

27-
If you **like/use** this package, please consider **starring** it. Thanks!
26+
This package integrates the Symfony Serializer component into Laravel, providing a powerful tool for serializing and deserializing objects into various formats such as JSON, XML, CSV, and YAML.
2827

29-
![Screenshot](assets/screenshot.png)
28+
Detailed documentation on the Symfony serializer can be found on their [official page](https://symfony.com/doc/current/components/serializer.html).
3029

31-
## 💿 Installation
30+
### → Purpose
31+
32+
This package brings the power of the Symfony Serializer component to Laravel. While Laravel does not have a built-in serializer and typically relies on array or JSON transformations, this package provides more advanced serialization capabilities. This includes object normalization, handling of circular references, property grouping, and format-specific encoders.
33+
34+
If you are building a REST API, working with queues, or have complex serialization needs, this package will be especially useful. It allows you to use objects as payload instead of simple arrays, and supports various formats such as JSON, XML, CSV, and YAML. This documentation will guide you through the installation process and provide examples of how to use the package to serialize and deserialize your objects.
3235

33-
### → Using composer
36+
<br>
37+
38+
🙏 If you find this repository useful, please consider giving it a ⭐️. Thank you!
39+
40+
<br>
41+
42+
## 💿 Installation
3443

3544
Require as dependency:
3645

3746
```bash
3847
$ composer req wayofdev/laravel-symfony-serializer
3948
```
4049

50+
You can publish the config file with:
51+
52+
```bash
53+
$ php artisan vendor:publish \
54+
--provider="WayOfDev\Serializer\Bridge\Laravel\Providers\SerializerServiceProvider" \
55+
--tag="config"
56+
```
57+
58+
<br>
59+
60+
## 💻 Usage
61+
62+
The package provides a list of serializers that can be used to serialize and deserialize objects.
63+
64+
The serializers available in this package are: `symfony-json`, `symfony-csv`, `symfony-xml`, `symfony-yaml`.
65+
66+
> **Warning**
67+
> The `yaml` encoder requires the `symfony/yaml` package and is disabled when the package is not installed.
68+
> Install the `symfony/yaml` package and the encoder will be automatically enabled.
69+
70+
@todo ...
71+
4172
<br>
4273

4374
## 🧪 Running Tests
4475

4576
### → PHPUnit tests
4677

47-
To run tests, run the following command:
78+
To run phpunit and pest tests, run the following command:
4879

4980
```bash
5081
$ make test
@@ -55,15 +86,15 @@ $ make test
5586
Code quality using PHPStan:
5687

5788
```bash
58-
$ make stan
89+
$ make lint-stan
5990
```
6091

6192
### → Coding Standards Fixing
6293

6394
Fix code using The PHP Coding Standards Fixer (PHP CS Fixer) to follow our standards:
6495

6596
```bash
66-
$ make cs-fix
97+
$ make lint-php
6798
```
6899

69100
<br>
@@ -76,6 +107,27 @@ $ make cs-fix
76107

77108
## 🙆🏼‍♂️ Author Information
78109

79-
Created in **2022** by [lotyp / wayofdev](https://github.com/wayofdev)
110+
Created in **2023** by [lotyp / wayofdev](https://github.com/wayofdev)
80111

81112
<br>
113+
114+
## 🙌 Want to Contribute?
115+
116+
Thank you for considering contributing to the wayofdev community! We are open to all kinds of contributions. If you want to:
117+
118+
- 🤔 Suggest a feature
119+
- 🐛 Report an issue
120+
- 📖 Improve documentation
121+
- 👨‍💻 Contribute to the code
122+
123+
<br>
124+
125+
## 🧱 Credits and Useful Resources
126+
127+
This repository is based on code from following repositories:
128+
129+
* [spiral/serializer](https://github.com/spiral/serializer)
130+
* [spiral-packages/symfony-serializer](https://github.com/spiral-packages/symfony-serializer)
131+
* [jeromegamez/ramsey-uuid-normalizer](https://github.com/jeromegamez/ramsey-uuid-normalizer)
132+
* [wayofdev/laravel-jms-serializer](https://github.com/wayofdev/laravel-jms-serializer)
133+

config/serializer.php

+24-18
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,48 @@
77

88
return [
99
/*
10-
* Name (format) of the default serializer that will be registered in SerializerManager.
10+
* The 'default' key specifies the name (format) of the default serializer
11+
* that will be registered in SerializerManager. This can be overridden
12+
* by setting the SERIALIZER_DEFAULT_FORMAT environment variable.
1113
*/
12-
'default' => 'json',
14+
'default' => env('SERIALIZER_DEFAULT_FORMAT', 'json'),
1315

1416
/*
15-
* Supported serializers: json, csv, xml, yaml
16-
* Set serializer to false to disable it.
17+
* The 'serializers' key lists the supported serializers: json, csv, xml, yaml.
18+
* Set a serializer to "false" to disable it. This can be overridden by setting
19+
* the corresponding SERIALIZER_USE_* environment variable.
1720
*/
1821
'serializers' => [
19-
'json' => true,
20-
'csv' => false,
21-
'xml' => false,
22-
'yaml' => false,
22+
'json' => env('SERIALIZER_USE_JSON', true),
23+
'csv' => env('SERIALIZER_USE_CSV', false),
24+
'xml' => env('SERIALIZER_USE_XML', false),
25+
'yaml' => env('SERIALIZER_USE_YAML', false),
2326
],
2427

2528
/*
26-
* Register your custom normalizers here.
27-
* Default normalizers are registered in src/NormalizersRegistry.php
29+
* The 'normalizers' key allows you to register your custom normalizers.
30+
* Default normalizers are registered in src/NormalizersRegistry.php.
31+
* Uncomment the line below and replace with your custom normalizer if needed
32+
* to merge with default ones.
2833
*/
2934
'normalizers' => [
3035
// Symfony\Component\Messenger\Transport\Serialization\Normalizer\FlattenExceptionNormalizer
3136
],
3237

3338
/*
34-
* Register your custom encoders here.
35-
* Default encoders are registered in src/EncodersRegistry.php
36-
*
37-
* Default encoders are:
38-
* - Symfony\Component\Serializer\Encoder\JsonEncoder
39-
* - Symfony\Component\Serializer\Encoder\CsvEncoder
40-
* - Symfony\Component\Serializer\Encoder\XmlEncoder
41-
* - Symfony\Component\Serializer\Encoder\YamlEncoder
39+
* The 'encoders' key allows you to register your custom encoders.
40+
* Default encoders are registered in src/EncodersRegistry.php.
41+
* Default encoders include JsonEncoder, CsvEncoder, XmlEncoder, and YamlEncoder.
42+
* Uncomment the line below and replace with your custom encoder if needed.
4243
*/
4344
'encoders' => [
4445
// Symfony\Component\Serializer\Encoder\JsonEncoder
4546
],
4647

48+
/*
49+
* The 'metadata_loader' key specifies the loader for class metadata.
50+
* The default loader uses Doctrine annotations. If you want to use a different
51+
* metadata format (e.g., YAML, XML), you can replace this with a different loader.
52+
*/
4753
'metadata_loader' => new AnnotationLoader(new AnnotationReader()),
4854
];

0 commit comments

Comments
 (0)