Download the PHP package spiral/marshaller without Composer
On this page you can find all versions of the php package spiral/marshaller. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download spiral/marshaller
More information about spiral/marshaller
Files in spiral/marshaller
Package marshaller
Short Description Marshaller package
License MIT
Homepage https://github.com/spiral/marshaller
Informations about the package marshaller
Marshaller
Introduction
The Marshaller package is a PHP tool that helps you convert PHP objects into simple arrays and vice versa. It allows you to marshal objects into array representations for serialization, storage, and transportation, and unmarshal arrays back into objects.
This package provides easy-to-use methods for converting objects to arrays and restoring objects from arrays. It supports handling nested objects and complex data structures.
Requirements
Make sure that your server is configured with following PHP version and extensions:
- PHP 8.1+
Installation
You can install the package via composer:
Usage
Note Here, the low-level usage of the package will be covered. Marshaller Bridge is a ready-made integration for the Spiral Framework.
Converting objects to arrays
For example, we have a User class that has simple string properties, an Address property, a Status enum, a UUID, and an array of Address objects, and we need to serialize it:
User
Using attributes, we specify which private and protected properties to serialize and configure additional Marshaller parameters (for example, what type of array elements should be).
Note Specifying the
Marshal
attribute is optional for public properties unless the property requires additional Marshaller configuration.
Address
Status
To serialize a User object, we need to create a Marshaller
object and call the marshal method
and pass the User object into it.
Converting arrays to objects
To unserialize an array, we need to create a Marshaller
object and call the unmarshal method
and pass the array with data and object to populate into it.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
License
The MIT License (MIT). Please see License File for more information.
All versions of marshaller with dependencies
nesbot/carbon Version ^2.68.0
google/protobuf Version ^3.23
spiral/attributes Version ^2.8 || ^3.0