Skip to content

SmoothPhp/Serialization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Serialization

The Smooth PHP CQRS ES framework comes with a simple serializer, designed to get you started as quickly as possible. Usage of the serializer will allow you to quick convert complex DTO's to simple associative arrays.

Examples

<?php
namespace App;
use SmoothPhp\Contracts\Serialization\Serializable;

class MyDTO implements Serializable {
	public function __construct(Id $id, DateTime $creationDate) {
		$this->id = $id;
		$this-creationDate = $creationDate;
	}

	// getters

	public function serialize()
	{
		return [
			'id'   => (string) $this->id,
			'date' => $this->creationDate->serialize(),
		];
	}

	public static function deserialize(array $data)
	{
		return new static(
			new Id($data['id']),
			DateTime::deserialize($data['date'])
		);
	}
}

$dto = new App\MyDTO(new App\Id(uuid()), App\DateTime::now());

$serializer = new \SmoothPhp\Serialization\ObjectSelfSerializer;

// Store in database, job queue, etc
$serialized = $serializer->serialize($dto);

// Use in app
$object = $serializer->deserialize($serialized);

About

[READ ONLY] Smooth PHP CQRS/ES Serialization

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages