Open juriansluiman opened 10 years ago
Some extra thoughts:
The AbstractPluginManager has $creationOptions (MutableCreationOptionsInterface), so you can use:
$email = $emailManager->get('password-reset', ['subject' => 'new subject']);
$emailService->send();
// Or maybe a bit faster, but not so good for SRP:
$emailManager->send();
Maybe it is better to create a class MailOptions which extend StdLib\AbstractOptions in strict mode. This way it is possible to use the options as an array, but also with getters and setters. So you can choose if you add an array or MailOptions to the send method.
I would not add a send() method to the MailInterface. In the real world I still haven't found a letter which posts itself :) This way there is no dependency to the EmailService. The MailService should be smart enough to handle EmailInterface.
Maybe the MailInterface should look like:
interface EmailInterface
{
/**
* @return MailOptions
*/
public getMailOptions();
/**
* @return \Zend\View\Variables|array|Traversable|null
*/
public getViewVariables();
/**
* @return \Zend\Mail\Message|null
*/
public getDefaultMessage();
}
This way you can work as followed:
What do you think?
From juriansluiman/SlmMail#72:
The idea is to create an email plugin manager which holds "email tasks" for distinct emails. This prevents the caller of
MailService#send()
to have knowledge of the email composition (subject, template and so on) and helps to reuse the email in different parts. An example is the user can request a password-reset email but the admin can trigger one as well.Possible API:
The email task itself:
A concrete class could look like this:
But @veewee I am still not quite happy with this, as you have to know the API from
Soflomo\Mail\Service\MailService
for these email tasks as well. Perhaps we can come up with a better alternative for this. Anyhow, I think the idea is pretty good but it needs some work to finalize.PS. For these kind of features I tend to think about the public API from the users perspective, how we do the internals is most times easier when the API is set.