I already asked a question about this answer on another topic, but I kind of got very interested to learn from it, so I have another doubt now. In particular, I was looking at the authenticate method, and the data mapper fetch method. I also found this answer as extremely helpful on this topic where the fetch method is kind of explained, but it is skipped the part where I am in doubt. The user tereško that answers this questions, on couple of occasions suggests that the methods in the data mapper should not be fetchById, fetchByUsername, etc., but rather one fetch method. My question is how am I going to fetch something specific as the methods I wrote, having only the domain object at hand?
For example, if I have a register service method where I need to check and possibly store username, password and email, I would need to fetch by username to check whether the user already exists, and after that to fetch by email to check whether that email is in the database already. So, how do I know in the fetch method what to do if I only have:
$mapper->fetch($object);
Do I possibly set fetch options on the domain object?
$account->setFetchOptions(['username']);
And then in the fetch method I would check and fetch. Does this makes sense? If someone has another idea, share it.