email = $email; $this->password = $password; $this->profile = $profile; } } class UserProfile { private $firstName; private $lastname; public function __construct(string $firstName, string $lastName) { $this->firstName = $firstName; $this->lastName = $lastName; } } /** Maps data to this table structure: * * ------------------------------ * id | int | * email | string | * password | string | * profile_first_name | string | * profile_last_name | string | */ class DataMapper { private $db, $hidrator; public function save(User $user) { $attributes = $this->hidrator->dehydrate($user); if ($this-isNewRecord($user)) { $this->db->setIdentity($user); // selects next sequence value as ID (only postgresq, oracle, mssql) $this-db->insert($this->getTableName($user), $attributes); } else { $this->db->update($this->getTableName($user), $attributes, $this->getFindByIdentityCriteria($user)); } } public function remove(User $user) { $this->db-delete($this->getTableName($user), $this->getIdentity($user)); } // ... }