Download the PHP package wayofdev/laravel-symfony-serializer without Composer
On this page you can find all versions of the php package wayofdev/laravel-symfony-serializer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download wayofdev/laravel-symfony-serializer
More information about wayofdev/laravel-symfony-serializer
Files in wayofdev/laravel-symfony-serializer
Download wayofdev/laravel-symfony-serializer
More information about wayofdev/laravel-symfony-serializer
Files in wayofdev/laravel-symfony-serializer
Vendor wayofdev
Package laravel-symfony-serializer
Short Description π¦ Laravel wrapper around Symfony Serializer.
License MIT
Homepage https://wayof.dev
Package laravel-symfony-serializer
Short Description π¦ Laravel wrapper around Symfony Serializer.
License MIT
Homepage https://wayof.dev
Please rate this library. Is it a good library?
Informations about the package laravel-symfony-serializer
# Laravel Symfony Serializer 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. Detailed documentation on the Symfony Serializer can be found on their [official page](https://symfony.com/doc/current/components/serializer.html).
## ποΈ Table of Contents - [Purpose](#-purpose) - [Installation](#-installation) - [Configuration](#-configuration) - [Configuration Options](#-configuration-options) - [Custom Strategies](#-custom-strategies) - [Usage](#-usage) - [Components](#-components) - [Example DTO](#-example-dto) - [Using `SerializerManager` in your Service Classes](#-using-serializermanager-in-service-classes) - [Using `ResponseFactory` in Laravel Controllers](#-using-responsefactory-in-laravel-controllers) - [Using in Laravel Queues](#-using-in-laravel-queues) - [Security Policy](#-security-policy) - [Want to Contribute?](#-want-to-contribute) - [Contributors](#-contributors) - [Social Links](#-social-links) - [License](#-license) - [Credits and Useful Resources](#-credits-and-useful-resources)
## π€ 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. These include 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 payloads 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.
π If you find this repository useful, please consider giving it a βοΈ. Thank you!
## πΏ Installation Require the package as a dependency: You can publish the config file with:
## π§ Configuration The package configuration file allows you to customize various aspects of the serialization process. Below is the default configuration provided by the package: ### β Configuration Options - **`default`**: Specifies the default serializer format. This can be overridden by setting the `SERIALIZER_DEFAULT_FORMAT` environment variable. The default is `symfony-json`. - **`debug`**: Enables debug mode for `ProblemNormalizer`. This can be set using the `SERIALIZER_DEBUG_MODE` environment variable. It defaults to the `APP_DEBUG` value. - **`normalizerRegistrationStrategy`**: Specifies the strategy class for registering normalizers. The default strategy is [`WayOfDev\Serializer\DefaultNormalizerRegistrationStrategy`](https://github.com/wayofdev/laravel-symfony-serializer/blob/master/src/DefaultNormalizerRegistrationStrategy.php). - **`encoderRegistrationStrategy`**: Specifies the strategy class for registering encoders. The default strategy is [`WayOfDev\Serializer\DefaultEncoderRegistrationStrategy`](https://github.com/wayofdev/laravel-symfony-serializer/blob/master/src/DefaultEncoderRegistrationStrategy.php). - **`metadataLoader`**: Allows registration of a custom metadata loader. By default, `Symfony\Component\Serializer\Mapping\Loader\AttributeLoader` is used. ### β Custom Strategies [Due to Laravel's caching limitations, where configs cannot instantiate objects](https://elliotderhay.com/blog/caching-laravel-configs-that-use-objects), this package uses strategies to register normalizers and encoders. You can create custom normalizer or encoder registration strategies by implementing the respective interfaces. #### Normalizer Registration Strategy To create a custom normalizer registration strategy: 1. Implement the [`NormalizerRegistrationStrategy`](https://github.com/wayofdev/laravel-symfony-serializer/blob/master/src/Contracts/NormalizerRegistrationStrategy.php) interface: 2. Change `serializer.php` config to use your custom strategy: #### Encoder Registration Strategy To create a custom encoder registration strategy: 1. Implement the [`EncoderRegistrationStrategy`](https://github.com/wayofdev/laravel-symfony-serializer/blob/master/src/Contracts/EncoderRegistrationStrategy.php) interface: 2. Change `serializer.php` config to use your custom strategy:
## π» Usage The package provides a list of serializers that can be used to serialize and deserialize objects. The default 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. ### β Components #### SerializerManager The `SerializerManager` handles the different serializers available in this package. It can be used to serialize and deserialize objects. #### ResponseFactory The `ResponseFactory` is used to create responses in Laravel controllers, making it easy to include serialized data in HTTP responses. #### Facades This package includes two Laravel Facades: - `Manager` β To access the underlying `SerializerManager` - `Serializer` β To access the bound and configured original Symfony Serializer instance. ### β Example DTO We will use this example DTO for serialization purposes: ### β Using `SerializerManager` in Service Classes ### β Using `ResponseFactory` in Laravel Controllers Here's an example of how you can use the `ResponseFactory` in a Laravel Controller: **Example Controller:**
### β Using in Laravel Queues To switch from Laravel's default serialization to this implementation in queues, you can override the `__serialize` and `__unserialize` methods in your queue jobs. Hereβs an example:
## π Security Policy This project has a [security policy](.github/SECURITY.md).
## π Want to Contribute? Thank you for considering contributing to the wayofdev community! We welcome all kinds of contributions. If you want to: - π€ [Suggest a feature](https://github.com/wayofdev/laravel-symfony-serializer/issues/new?assignees=&labels=type%3A+enhancement&projects=&template=2-feature-request.yml&title=%5BFeature%5D%3A+) - π [Report an issue](https://github.com/wayofdev/laravel-symfony-serializer/issues/new?assignees=&labels=type%3A+documentation%2Ctype%3A+maintenance&projects=&template=1-bug-report.yml&title=%5BBug%5D%3A+) - π [Improve documentation](https://github.com/wayofdev/laravel-symfony-serializer/issues/new?assignees=&labels=type%3A+documentation%2Ctype%3A+maintenance&projects=&template=4-docs-bug-report.yml&title=%5BDocs%5D%3A+) - π¨βπ» [Contribute to the code](.github/CONTRIBUTING.md) You are more than welcome. Before contributing, please check our [contribution guidelines](.github/CONTRIBUTING.md). [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg?style=for-the-badge)](https://conventionalcommits.org)
## π«‘ Contributors ## π Social Links - **Twitter:** Follow our organization [@wayofdev](https://twitter.com/intent/follow?screen_name=wayofdev) and the author [@wlotyp](https://twitter.com/intent/follow?screen_name=wlotyp). - **Discord:** Join our community on [Discord](https://discord.gg/CE3TcCC5vr).
## π License [![License](https://img.shields.io/github/license/wayofdev/laravel-symfony-serializer?style=for-the-badge&color=blue)](./LICENSE.md)
## 𧱠Credits and Useful Resources This repository is inspired by the following projects: - [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) - [symfony/serializer](https://github.com/symfony/serializer)
All versions of laravel-symfony-serializer with dependencies
PHP Build Version
Package Version
Requires
php Version
^8.2
illuminate/contracts Version ^11.0
illuminate/http Version ^11.0
illuminate/support Version ^11.0
ramsey/uuid Version ^4.7
symfony/property-access Version ^7.1
symfony/property-info Version ^7.1
symfony/serializer Version ^7.1
illuminate/contracts Version ^11.0
illuminate/http Version ^11.0
illuminate/support Version ^11.0
ramsey/uuid Version ^4.7
symfony/property-access Version ^7.1
symfony/property-info Version ^7.1
symfony/serializer Version ^7.1
The package wayofdev/laravel-symfony-serializer contains the following files
Loading the files please wait ....