-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jrdn hannah
committed
Oct 17, 2016
1 parent
5b1705f
commit be4069f
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
``` |