Value Objects are not persisted on their own; they're typically persisted within an Aggregate. Value Objects shouldn't be persisted as complete records, though that's an option in some cases. Instead, it's best to use Embedded Value or Serialize LOB patterns. Both patterns can be used when persisting your objects with an open source ORM such as Doctrine, or with a bespoke ORM. As Value Objects are small, Embedded Value is usually the best choice because it provides an easy way to query Entities by any of the attributes the Value Object has. However, if querying by those fields isn't important to you, serialize strategies can be very easy to implement.
Consider the following Product
Entity with string id, name
, and price
(Money
Value Objects) attributes. We've intentionally decided to simplify this example, with the id being a string and not a Value Object:
class Product { private $productId; private $name; private $price; public function __construct...