For example if I have a constant, like generated password size, then where should I put that constant if the random password generator is implemented in the infrastructure? I guess this should be a domain service, but I guess I cannot put the constant in the service interface. Or can I?
I ended up with this:
namespace Example\domain;
interface iRandomPasswordService {
const RANDOM_PASSWORD_SIZE = 6;
public function getPassword();
}
namespace Example\infrastructure;
use Example\domain\iRandomPasswordService;
use Example\domain\Password;
use JUserHelper;
class RandomPasswordService implements iRandomPasswordService {
public function getPassword(){
$randomPassword = JUserHelper::genRandomPassword(self::RANDOM_PASSWORD_SIZE);
return new Password($randomPassword);
}
}
I hate PHP and Joomla too, don't mention it. I am waiting for an approval or a better idea. 🙂
Best Answer
I think there are two acceptable places storing the length for generated passwords could occur at, which one is better depends on how much you control of password generation/authentication service and your actual app.
I would prefer option 1 unless I couldn't modify the generation service itself because it keeps all user authentication concerns within the service you chose to manage them.