Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sylvrs/libmarshal
A small marshalling library used to encode/decode data from classes
https://github.com/sylvrs/libmarshal
marshal php unmarshal
Last synced: 2 months ago
JSON representation
A small marshalling library used to encode/decode data from classes
- Host: GitHub
- URL: https://github.com/sylvrs/libmarshal
- Owner: sylvrs
- License: gpl-3.0
- Created: 2022-03-30T21:51:20.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-06-16T03:25:38.000Z (7 months ago)
- Last Synced: 2024-10-10T23:26:20.694Z (3 months ago)
- Topics: marshal, php, unmarshal
- Language: PHP
- Homepage:
- Size: 387 KB
- Stars: 15
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# libMarshal
A small marshalling library used to encode/decode data from classes.## Installation
### Composer
To install this library through composer, run the following command:
```
composer require sylvrs/libmarshal
```
### Virion
The virion for this library can be accessed [here](https://poggit.pmmp.io/ci/sylvrs/libMarshal/libMarshal).## Basic Example
Here is a basic example on how this library is used:
```php
class User {
use MarshalTrait;
public function __construct(
#[Field(name: "first-name")]
public string $firstName,
#[Field(name: "last-name")]
public string $lastName,
public int $age,
public string $email,
#[Exclude]
public string $internalData = "..."
) {}
}// NOTE: This uses promoted properties to make it easier to construct.
// You can learn more about this below.// Marshalling
$user = new User(firstName: "John", lastName: "Doe", age: 30, email: "[email protected]");
$data = $user->marshal(); // ["first-name" => "John", "last-name" => "Doe", "age" => 30, "email" => "[email protected]"]$data["first-name"] = "Jane"; // Changing the first name
$data["email"] = "[email protected]"; // Changing the email// Unmarshalling
$user = User::unmarshal($data); // User(firstName: "Jane", lastName: "Doe", age: 30, email: "[email protected]")
```## Wiki
To learn about how to use the library, please consult the wiki [here](https://github.com/sylvrs/libMarshal/wiki).## Roadmap
At the moment, there are a few improvements that can be/or are being worked on. Here is a list of some of those improvements:
- [ ] Add a limit to recursive objects when marshalling/unmarshalling (50?)
- [X] Cache properties for performance benefits## Issues
Any issues/suggestions can be reported [here](https://github.com/sylvrs/libMarshal/issues).