function registerUser(UserEntity $user) { if ($this->usernameExists($user['username'])) { throw new Exception("The username is already taken"); } elseif ($this->emailExists($user['email'])) { throw new Exception("The email is already taken"); } $user['created_at'] = new MongoDate(); $user['updated_at'] = new MongoDate(); $userToCommit = $user->toArray(); unset($userToCommit['_id']); $status = $this->_collection->insert($userToCommit, array('safe' => true)); return new UserEntity($userToCommit); }