@@ -30,7 +30,7 @@ Require composer autoload file
3030require './vendor/autoload.php';
3131```
3232
33- Extend from ` Gears\value-object \AbstractValueObject ` . Make your class final, value objects should always be final
33+ Extend from ` Gears\ValueObject \AbstractValueObject ` . Make your class final, value objects should always be final
3434
3535Be aware of the protected constructor, you should create a "named constructor" for your value object
3636
@@ -56,7 +56,8 @@ final class CustomStringValueObject extends AbstractValueObject
5656
5757 public function isEqualTo($valueObject): bool
5858 {
59- return \get_class($valueObject) === self::class && $valueObject->getValue() === $this->value;
59+ return \get_class($valueObject) === self::class
60+ && $valueObject->getValue() === $this->value;
6061 }
6162}
6263```
@@ -90,6 +91,18 @@ final class Money extends AbstractValueObject implements \Serializable
9091
9192 // [...]
9293
94+ final public function __serialize(): array
95+ {
96+ return ['value' => $this->value];
97+ }
98+
99+ final public function __unserialize(array $data): void
100+ {
101+ $this->assertImmutable();
102+
103+ $this->value = $data['value'];
104+ }
105+
93106 final public function serialize(): string
94107 {
95108 return serialize([
@@ -101,6 +114,8 @@ final class Money extends AbstractValueObject implements \Serializable
101114
102115 public function unserialize($serialized): void
103116 {
117+ $this->assertImmutable();
118+
104119 list(
105120 $this->value,
106121 $this->precision,
0 commit comments