Skip to content

Commit

Permalink
Add doc block header/example to Mailer.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jun 10, 2015
1 parent 67395d2 commit f513baa
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/Mailer/Mailer.php
Expand Up @@ -18,6 +18,68 @@
use Cake\Mailer\Exception\MissingActionException;
use Cake\Utility\Inflector;

/**
* Mailer base class.
*
* Mailer classes let you encapsulate related Email logic into a reusable
* and testable class.
*
* ## Defining Messages
*
* Mailers make it easy for you to define methods that handle email formatting
* logic. For example:
*
* ```
* class UserMailer extends Mailer
* {
* public function resetPassword($user)
* {
* $this->subject = 'Reset Password';
* $this->to = $user->email;
* $this->set(['token' => $user->token]);
* }
* }
* ```
*
* Is a trivial example but shows how a mailer could be declared.
*
* ## Sending Messages
*
* After you have defined some messages you will want to send them:
*
* ```
* $mailer = new UserMailer();
* $mailer->send('resetPassword', $user);
* ```
*
* ## Event Listener
*
* Mailers can also subscribe to application event allowing you to
* decouple email delivery from your application code. By re-declaring the
* `implementedEvents()` method you can define event handlers that can
* convert events into email. For example, if your application had a user
* registation event:
*
* ```
* public function implementedEvents()
* {
* return [
* 'Model.afterSave' => 'onRegistration',
* ];
* }
*
* public function onRegistration(Event $event, Entity $entity, ArrayObject $options)
* {
* if ($entity->isNew()) {
* $this->send('welcome', [$entity]);
* }
* }
* ```
*
* The onRegistration method converts the application event into a mailer method.
* Our mailer could either be registered in the application bootstrap, or
* in the Table class' initialize() hook.
*/
abstract class Mailer implements ArrayAccess, EventListenerInterface
{
use ModelAwareTrait;
Expand Down

0 comments on commit f513baa

Please sign in to comment.