Skip to content

Commit

Permalink
[Serialization] Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jrdn hannah committed Oct 17, 2016
1 parent 5b1705f commit be4069f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ $ composer require smoothphp/crqs-es-framework
## Usage

* [Command Bus](src/CommandBus/readme.md)
* [Serialization](src/Serialization/README.md)

## Change log

Expand Down
38 changes: 38 additions & 0 deletions src/Serialization/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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
<?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(),
]
}
}

$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);
```

0 comments on commit be4069f

Please sign in to comment.