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.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-symfony-serializer


WayOfDev Logo

Build
Build Status

Project
Total Downloads Latest Stable Version Commits since latest release PHP Version Require

Quality
Codecov Mutation testing badge

Community
Discord Follow on Twitter (X)


# 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

Contributors Badge

## 🌐 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
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package wayofdev/laravel-symfony-serializer contains the following files

Loading the files please wait ....