-
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
Showing
6 changed files
with
63 additions
and
18 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
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
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,46 @@ | ||
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(), | ||
]; | ||
} | ||
|
||
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); | ||
``` |
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