From ed9fe320bd481c0d922638650b0b199118ae9ec4 Mon Sep 17 00:00:00 2001 From: lotyp Date: Sun, 11 Jun 2023 15:25:04 +0300 Subject: [PATCH] docs: change readme --- README.md | 74 ++++++++++++++++++++++++++++++++++++------- config/serializer.php | 42 +++++++++++++----------- 2 files changed, 87 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index e9d26da..ff3f168 100644 --- a/README.md +++ b/README.md @@ -17,20 +17,29 @@ Software License Commits since latest release -
-# Laravel Package Template +# Laravel Symfony Serializer -This is minimal Laravel template which is used by other PHP projects in wayofdev organization. +## ๐Ÿ“„ About -If you **like/use** this package, please consider **starring** it. Thanks! +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. -![Screenshot](assets/screenshot.png) +Detailed documentation on the Symfony serializer can be found on their [official page](https://symfony.com/doc/current/components/serializer.html). -## ๐Ÿ’ฟ Installation +### โ†’ Purpose + +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. + +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. -### โ†’ Using composer +
+ +๐Ÿ™ If you find this repository useful, please consider giving it a โญ๏ธ. Thank you! + +
+ +## ๐Ÿ’ฟ Installation Require as dependency: @@ -38,13 +47,35 @@ Require as dependency: $ composer req wayofdev/laravel-symfony-serializer ``` +You can publish the config file with: + +```bash +$ php artisan vendor:publish \ + --provider="WayOfDev\Serializer\Bridge\Laravel\Providers\SerializerServiceProvider" \ + --tag="config" +``` + +
+ +## ๐Ÿ’ป Usage + +The package provides a list of serializers that can be used to serialize and deserialize objects. + +The serializers available in this package are: `symfony-json`, `symfony-csv`, `symfony-xml`, `symfony-yaml`. + +> **Warning** +> The `yaml` encoder requires the `symfony/yaml` package and is disabled when the package is not installed. +> Install the `symfony/yaml` package and the encoder will be automatically enabled. + +@todo ... +
## ๐Ÿงช Running Tests ### โ†’ PHPUnit tests -To run tests, run the following command: +To run phpunit and pest tests, run the following command: ```bash $ make test @@ -55,7 +86,7 @@ $ make test Code quality using PHPStan: ```bash -$ make stan +$ make lint-stan ``` ### โ†’ Coding Standards Fixing @@ -63,7 +94,7 @@ $ make stan Fix code using The PHP Coding Standards Fixer (PHP CS Fixer) to follow our standards: ```bash -$ make cs-fix +$ make lint-php ```
@@ -76,6 +107,27 @@ $ make cs-fix ## ๐Ÿ™†๐Ÿผโ€โ™‚๏ธ Author Information -Created in **2022** by [lotyp / wayofdev](https://github.com/wayofdev) +Created in **2023** by [lotyp / wayofdev](https://github.com/wayofdev)
+ +## ๐Ÿ™Œ Want to Contribute? + +Thank you for considering contributing to the wayofdev community! We are open to all kinds of contributions. If you want to: + +- ๐Ÿค” Suggest a feature +- ๐Ÿ› Report an issue +- ๐Ÿ“– Improve documentation +- ๐Ÿ‘จโ€๐Ÿ’ป Contribute to the code + +
+ +## ๐Ÿงฑ Credits and Useful Resources + +This repository is based on code from following repositories: + +* [spiral/serializer](https://github.com/spiral/serializer) +* [spiral-packages/symfony-serializer](https://github.com/spiral-packages/symfony-serializer) +* [jeromegamez/ramsey-uuid-normalizer](https://github.com/jeromegamez/ramsey-uuid-normalizer) +* [wayofdev/laravel-jms-serializer](https://github.com/wayofdev/laravel-jms-serializer) + diff --git a/config/serializer.php b/config/serializer.php index ff852db..fb8de96 100644 --- a/config/serializer.php +++ b/config/serializer.php @@ -7,42 +7,48 @@ return [ /* - * Name (format) of the default serializer that will be registered in SerializerManager. + * The 'default' key specifies the name (format) of the default serializer + * that will be registered in SerializerManager. This can be overridden + * by setting the SERIALIZER_DEFAULT_FORMAT environment variable. */ - 'default' => 'json', + 'default' => env('SERIALIZER_DEFAULT_FORMAT', 'json'), /* - * Supported serializers: json, csv, xml, yaml - * Set serializer to false to disable it. + * The 'serializers' key lists the supported serializers: json, csv, xml, yaml. + * Set a serializer to "false" to disable it. This can be overridden by setting + * the corresponding SERIALIZER_USE_* environment variable. */ 'serializers' => [ - 'json' => true, - 'csv' => false, - 'xml' => false, - 'yaml' => false, + 'json' => env('SERIALIZER_USE_JSON', true), + 'csv' => env('SERIALIZER_USE_CSV', false), + 'xml' => env('SERIALIZER_USE_XML', false), + 'yaml' => env('SERIALIZER_USE_YAML', false), ], /* - * Register your custom normalizers here. - * Default normalizers are registered in src/NormalizersRegistry.php + * The 'normalizers' key allows you to register your custom normalizers. + * Default normalizers are registered in src/NormalizersRegistry.php. + * Uncomment the line below and replace with your custom normalizer if needed + * to merge with default ones. */ 'normalizers' => [ // Symfony\Component\Messenger\Transport\Serialization\Normalizer\FlattenExceptionNormalizer ], /* - * Register your custom encoders here. - * Default encoders are registered in src/EncodersRegistry.php - * - * Default encoders are: - * - Symfony\Component\Serializer\Encoder\JsonEncoder - * - Symfony\Component\Serializer\Encoder\CsvEncoder - * - Symfony\Component\Serializer\Encoder\XmlEncoder - * - Symfony\Component\Serializer\Encoder\YamlEncoder + * The 'encoders' key allows you to register your custom encoders. + * Default encoders are registered in src/EncodersRegistry.php. + * Default encoders include JsonEncoder, CsvEncoder, XmlEncoder, and YamlEncoder. + * Uncomment the line below and replace with your custom encoder if needed. */ 'encoders' => [ // Symfony\Component\Serializer\Encoder\JsonEncoder ], + /* + * The 'metadata_loader' key specifies the loader for class metadata. + * The default loader uses Doctrine annotations. If you want to use a different + * metadata format (e.g., YAML, XML), you can replace this with a different loader. + */ 'metadata_loader' => new AnnotationLoader(new AnnotationReader()), ];