diff --git a/apps/advanced/environments/dev/common/config/main-local.php b/apps/advanced/environments/dev/common/config/main-local.php index d488438..43db30e 100644 --- a/apps/advanced/environments/dev/common/config/main-local.php +++ b/apps/advanced/environments/dev/common/config/main-local.php @@ -8,7 +8,7 @@ return [ 'password' => '', 'charset' => 'utf8', ], - 'mail' => [ + 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', 'viewPath' => '@common/mail', // send all mails to a file by default. You have to set diff --git a/apps/advanced/environments/prod/common/config/main-local.php b/apps/advanced/environments/prod/common/config/main-local.php index 0d5eed3..84c4d9f 100644 --- a/apps/advanced/environments/prod/common/config/main-local.php +++ b/apps/advanced/environments/prod/common/config/main-local.php @@ -8,7 +8,7 @@ return [ 'password' => '', 'charset' => 'utf8', ], - 'mail' => [ + 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', 'viewPath' => '@common/mail', ], diff --git a/apps/advanced/frontend/models/ContactForm.php b/apps/advanced/frontend/models/ContactForm.php index 1ad19ca..613abb5 100644 --- a/apps/advanced/frontend/models/ContactForm.php +++ b/apps/advanced/frontend/models/ContactForm.php @@ -49,7 +49,7 @@ class ContactForm extends Model */ public function sendEmail($email) { - return Yii::$app->mail->compose() + return Yii::$app->mailer->compose() ->setTo($email) ->setFrom([$this->email => $this->name]) ->setSubject($this->subject) diff --git a/apps/advanced/frontend/models/PasswordResetRequestForm.php b/apps/advanced/frontend/models/PasswordResetRequestForm.php index 81c656c..b89b7bc 100644 --- a/apps/advanced/frontend/models/PasswordResetRequestForm.php +++ b/apps/advanced/frontend/models/PasswordResetRequestForm.php @@ -44,7 +44,7 @@ class PasswordResetRequestForm extends Model if ($user) { $user->generatePasswordResetToken(); if ($user->save()) { - return \Yii::$app->mail->compose('passwordResetToken', ['user' => $user]) + return \Yii::$app->mailer->compose('passwordResetToken', ['user' => $user]) ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot']) ->setTo($this->email) ->setSubject('Password reset for ' . \Yii::$app->name) diff --git a/apps/advanced/frontend/tests/unit/models/ContactFormTest.php b/apps/advanced/frontend/tests/unit/models/ContactFormTest.php index 6086cb9..a30824e 100644 --- a/apps/advanced/frontend/tests/unit/models/ContactFormTest.php +++ b/apps/advanced/frontend/tests/unit/models/ContactFormTest.php @@ -14,7 +14,7 @@ class ContactFormTest extends TestCase protected function setUp() { parent::setUp(); - Yii::$app->mail->fileTransportCallback = function ($mailer, $message) { + Yii::$app->mailer->fileTransportCallback = function ($mailer, $message) { return 'testing_message.eml'; }; } @@ -54,6 +54,6 @@ class ContactFormTest extends TestCase private function getMessageFile() { - return Yii::getAlias(Yii::$app->mail->fileTransportPath) . '/testing_message.eml'; + return Yii::getAlias(Yii::$app->mailer->fileTransportPath) . '/testing_message.eml'; } } diff --git a/apps/advanced/frontend/tests/unit/models/PasswordResetRequestFormTest.php b/apps/advanced/frontend/tests/unit/models/PasswordResetRequestFormTest.php index de5d004..c83d3e4 100644 --- a/apps/advanced/frontend/tests/unit/models/PasswordResetRequestFormTest.php +++ b/apps/advanced/frontend/tests/unit/models/PasswordResetRequestFormTest.php @@ -17,7 +17,7 @@ class PasswordResetRequestFormTest extends DbTestCase { parent::setUp(); - Yii::$app->mail->fileTransportCallback = function ($mailer, $message) { + Yii::$app->mailer->fileTransportCallback = function ($mailer, $message) { return 'testing_message.eml'; }; } @@ -82,7 +82,7 @@ class PasswordResetRequestFormTest extends DbTestCase private function getMessageFile() { - return Yii::getAlias(Yii::$app->mail->fileTransportPath) . '/testing_message.eml'; + return Yii::getAlias(Yii::$app->mailer->fileTransportPath) . '/testing_message.eml'; } } diff --git a/apps/basic/config/web.php b/apps/basic/config/web.php index 7fee63a..7939bb3 100644 --- a/apps/basic/config/web.php +++ b/apps/basic/config/web.php @@ -17,7 +17,7 @@ $config = [ 'errorHandler' => [ 'errorAction' => 'site/error', ], - 'mail' => [ + 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', // send all mails to a file by default. You have to set // 'useFileTransport' to false and configure a transport diff --git a/apps/basic/models/ContactForm.php b/apps/basic/models/ContactForm.php index 29a5dd9..d4052ee 100644 --- a/apps/basic/models/ContactForm.php +++ b/apps/basic/models/ContactForm.php @@ -49,7 +49,7 @@ class ContactForm extends Model public function contact($email) { if ($this->validate()) { - Yii::$app->mail->compose() + Yii::$app->mailer->compose() ->setTo($email) ->setFrom([$this->email => $this->name]) ->setSubject($this->subject) diff --git a/apps/basic/tests/unit/models/ContactFormTest.php b/apps/basic/tests/unit/models/ContactFormTest.php index fe214fa..6e69cec 100644 --- a/apps/basic/tests/unit/models/ContactFormTest.php +++ b/apps/basic/tests/unit/models/ContactFormTest.php @@ -13,7 +13,7 @@ class ContactFormTest extends TestCase protected function setUp() { parent::setUp(); - Yii::$app->mail->fileTransportCallback = function ($mailer, $message) { + Yii::$app->mailer->fileTransportCallback = function ($mailer, $message) { return 'testing_message.eml'; }; } @@ -54,7 +54,7 @@ class ContactFormTest extends TestCase private function getMessageFile() { - return Yii::getAlias(Yii::$app->mail->fileTransportPath) . '/testing_message.eml'; + return Yii::getAlias(Yii::$app->mailer->fileTransportPath) . '/testing_message.eml'; } } diff --git a/apps/basic/views/site/contact.php b/apps/basic/views/site/contact.php index eeb6f51..fad2d7c 100644 --- a/apps/basic/views/site/contact.php +++ b/apps/basic/views/site/contact.php @@ -22,9 +22,9 @@ $this->params['breadcrumbs'][] = $this->title;

Note that if you turn on the Yii debugger, you should be able to view the mail message on the mail panel of the debugger. - mail->useFileTransport): ?> + mailer->useFileTransport): ?> Because the application is in development mode, the email is not sent but saved as - a file under mail->fileTransportPath) ?>. + a file under mailer->fileTransportPath) ?>. Please configure the useFileTransport property of the mail application component to be false to enable email sending. diff --git a/docs/guide-ru/concept-configurations.md b/docs/guide-ru/concept-configurations.md index bb0cce2..1b755c9 100644 --- a/docs/guide-ru/concept-configurations.md +++ b/docs/guide-ru/concept-configurations.md @@ -107,7 +107,7 @@ $config = [ 'cache' => [ 'class' => 'yii\caching\FileCache', ], - 'mail' => [ + 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', ], 'log' => [ @@ -191,7 +191,7 @@ return [ 'cache' => [ 'class' => 'yii\caching\FileCache', ], - 'mail' => [ + 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', ], 'log' => [ diff --git a/docs/guide/concept-configurations.md b/docs/guide/concept-configurations.md index 5d44310..410372b 100644 --- a/docs/guide/concept-configurations.md +++ b/docs/guide/concept-configurations.md @@ -102,7 +102,7 @@ $config = [ 'cache' => [ 'class' => 'yii\caching\FileCache', ], - 'mail' => [ + 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', ], 'log' => [ @@ -184,7 +184,7 @@ return [ 'cache' => [ 'class' => 'yii\caching\FileCache', ], - 'mail' => [ + 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', ], 'log' => [ diff --git a/docs/guide/tutorial-mailing.md b/docs/guide/tutorial-mailing.md index 8271cc7..1169716 100644 --- a/docs/guide/tutorial-mailing.md +++ b/docs/guide/tutorial-mailing.md @@ -21,7 +21,7 @@ In general your application configuration should look like: return [ //.... 'components' => [ - 'mail' => [ + 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', ], ], @@ -32,10 +32,10 @@ return [ Basic usage ----------- -Once 'mail' component is configured, you can use the following code to send an email message: +Once 'mailer' component is configured, you can use the following code to send an email message: ```php -Yii::$app->mail->compose() +Yii::$app->mailer->compose() ->setFrom('from@domain.com') ->setTo('to@domain.com') ->setSubject('Message subject') @@ -48,7 +48,7 @@ In above example method `compose()` creates an instance of the mail message, whi You may put more complex logic in this process if needed: ```php -$message = Yii::$app->mail->compose(); +$message = Yii::$app->mailer->compose(); if (Yii::$app->user->isGuest) { $message->setFrom('from@domain.com') } else { @@ -60,7 +60,7 @@ $message->setTo(Yii::$app->params['adminEmail']) ->send(); ``` -> Note: each 'mail' extension comes in 2 major classes: 'Mailer' and 'Message'. 'Mailer' always knows +> Note: each 'mailer' extension comes in 2 major classes: 'Mailer' and 'Message'. 'Mailer' always knows the class name and specific of the 'Message'. Do not attempt ot instantiate 'Message' object directly - always use `compose()` method for it. @@ -69,11 +69,11 @@ You may also send several messages at once: ```php $messages = []; foreach ($users as $user) { - $messages[] = Yii::$app->mail->compose() + $messages[] = Yii::$app->mailer->compose() // ... ->setTo($user->email); } -Yii::$app->mail->sendMultiple($messages); +Yii::$app->mailer->sendMultiple($messages); ``` Some particular mail extensions may benefit from this approach, using single network message etc. @@ -104,7 +104,7 @@ use yii\helpers\Url; In order to compose message content via view file simply pass view name to the `compose()` method: ```php -Yii::$app->mail->compose('home-link') // message body becomes a view rendering result here +Yii::$app->mailer->compose('home-link') // message body becomes a view rendering result here ->setFrom('from@domain.com') ->setTo('to@domain.com') ->setSubject('Message subject') @@ -114,7 +114,7 @@ Yii::$app->mail->compose('home-link') // message body becomes a view rendering r You may pass additional view parameters to `compose()` method, which will be available inside the view files: ```php -Yii::$app->mail->compose('greetings', [ +Yii::$app->mailer->compose('greetings', [ 'user' => Yii::$app->user->identity, 'advertisement' => $adContent, ]); @@ -123,7 +123,7 @@ Yii::$app->mail->compose('greetings', [ You can specify different view files for HTML and plain text message contents: ```php -Yii::$app->mail->compose([ +Yii::$app->mailer->compose([ 'html' => 'contact-html', 'text' => 'contact-text', ]); @@ -172,7 +172,7 @@ File attachment You can add attachments to message using methods `attach()` and `attachContent()`: ```php -$message = Yii::$app->mail->compose(); +$message = Yii::$app->mailer->compose(); // Attach file from local file system: $message->attach('/path/to/source/file.pdf'); @@ -190,7 +190,7 @@ which should be then used at 'img' tag. This method is easy to use when composing message content via view file: ```php -Yii::$app->mail->compose('embed-email', ['imageFileName' => '/path/to/image.jpg']) +Yii::$app->mailer->compose('embed-email', ['imageFileName' => '/path/to/image.jpg']) // ... ->send(); ``` diff --git a/extensions/codeception/README.md b/extensions/codeception/README.md index 42e9de9..0543201 100644 --- a/extensions/codeception/README.md +++ b/extensions/codeception/README.md @@ -165,7 +165,7 @@ class MailTest extends TestCase // don't forget to call parent method that will setup Yii application parent::setUp(); - Yii::$app->mail->fileTransportCallback = function ($mailer, $message) { + Yii::$app->mailer->fileTransportCallback = function ($mailer, $message) { return 'testing_message.eml'; }; } diff --git a/extensions/swiftmailer/Mailer.php b/extensions/swiftmailer/Mailer.php index 73f8ed5..3368971 100644 --- a/extensions/swiftmailer/Mailer.php +++ b/extensions/swiftmailer/Mailer.php @@ -19,7 +19,7 @@ use yii\mail\BaseMailer; * ~~~ * 'components' => [ * ... - * 'mail' => [ + * 'mailer' => [ * 'class' => 'yii\swiftmailer\Mailer', * 'transport' => [ * 'class' => 'Swift_SmtpTransport', @@ -57,7 +57,7 @@ use yii\mail\BaseMailer; * To send an email, you may use the following code: * * ~~~ - * Yii::$app->mail->compose('contact/html', ['contactForm' => $form]) + * Yii::$app->mailer->compose('contact/html', ['contactForm' => $form]) * ->setFrom('from@domain.com') * ->setTo($form->email) * ->setSubject($form->subject) diff --git a/extensions/swiftmailer/README.md b/extensions/swiftmailer/README.md index fa987c8..cf1ca61 100644 --- a/extensions/swiftmailer/README.md +++ b/extensions/swiftmailer/README.md @@ -9,7 +9,7 @@ To use this extension, simply add the following code in your application config return [ //.... 'components' => [ - 'mail' => [ + 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', ], ], @@ -19,7 +19,7 @@ return [ You can then send an email as follows: ```php -Yii::$app->mail->compose('contact/html') +Yii::$app->mailer->compose('contact/html') ->setFrom('from@domain.com') ->setTo($form->email) ->setSubject($form->subject) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 0891d0c..c981407 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -144,6 +144,7 @@ Yii Framework 2 Change Log - Chg #3897: Raised visibility of `yii\web\View::registerAssetFiles()` to protected (samdark) - Chg #3899: Moved `MailEvent` class to `yii\mail` namespace (cebe) - Chg #3956: Flash messages set via `Yii::$app->session->setFlash()` will be removed only if they are accessed (qiangxue) +- Chg #4071: `mail` component renamed to `mailer`, `yii\log\EmailTarget::$mail` renamed to `yii\log\EmailTarget::$mailer` (samdark) - Chg: Replaced `clearAll()` and `clearAllAssignments()` in `yii\rbac\ManagerInterface` with `removeAll()`, `removeAllRoles()`, `removeAllPermissions()`, `removeAllRules()` and `removeAllAssignments()` (qiangxue) - Chg: Added `$user` as the first parameter of `yii\rbac\Rule::execute()` (qiangxue) - Chg: `yii\grid\DataColumn::getDataCellValue()` visibility is now `public` to allow accessing the value from a GridView directly (cebe) diff --git a/framework/UPGRADE.md b/framework/UPGRADE.md index 8101163..83fc0fc 100644 --- a/framework/UPGRADE.md +++ b/framework/UPGRADE.md @@ -69,3 +69,6 @@ Upgrade from Yii 2.0 Beta * If you are developing RESTful APIs and using an authentication method such as `yii\filters\auth\HttpBasicAuth`, you should explicitly configure `yii\web\User::enableSession` in the application configuration to be false to avoid starting a session when authentication is performed. Previously this was done automatically by authentication method. + +* `mail` component was renamed to `mailer`, `yii\log\EmailTarget::$mail` was renamed to `yii\log\EmailTarget::$mailer`. + Please update all references in the code and config files. diff --git a/framework/log/EmailTarget.php b/framework/log/EmailTarget.php index cf343ee..d9e61f9 100644 --- a/framework/log/EmailTarget.php +++ b/framework/log/EmailTarget.php @@ -24,7 +24,7 @@ use yii\mail\MailerInterface; * 'targets' => [ * [ * 'class' => 'yii\log\EmailTarget', - * 'mail' =>'mail', + * 'mailer' =>'mailer', * 'levels' => ['error', 'warning'], * 'message' => [ * 'from' => ['log@example.com'], @@ -37,7 +37,7 @@ use yii\mail\MailerInterface; * ], * ``` * - * In the above `mail` is ID of the component that sends email and should be already configured. + * In the above `mailer` is ID of the component that sends email and should be already configured. * * @author Qiang Xue * @since 2.0 @@ -54,7 +54,7 @@ class EmailTarget extends Target * After the EmailTarget object is created, if you want to change this property, you should only assign it * with a mailer object. */ - public $mail = 'mail'; + public $mailer = 'mailer'; /** @@ -66,7 +66,7 @@ class EmailTarget extends Target if (empty($this->message['to'])) { throw new InvalidConfigException('The "to" option must be set for EmailTarget::message.'); } - $this->mail = Instance::ensure($this->mail, 'yii\mail\MailerInterface'); + $this->mailer = Instance::ensure($this->mailer, 'yii\mail\MailerInterface'); } /** @@ -81,7 +81,7 @@ class EmailTarget extends Target } $messages = array_map([$this, 'formatMessage'], $this->messages); $body = wordwrap(implode("\n", $messages), 70); - $this->composeMessage($body)->send($this->mail); + $this->composeMessage($body)->send($this->mailer); } /** @@ -91,7 +91,7 @@ class EmailTarget extends Target */ protected function composeMessage($body) { - $message = $this->mail->compose(); + $message = $this->mailer->compose(); Yii::configure($message, $this->message); $message->setTextBody($body); diff --git a/framework/mail/MailerInterface.php b/framework/mail/MailerInterface.php index f2f9948..22231c0 100644 --- a/framework/mail/MailerInterface.php +++ b/framework/mail/MailerInterface.php @@ -14,7 +14,7 @@ namespace yii\mail; * also support composition of the message body through the view rendering mechanism. For example, * * ~~~ - * Yii::$app->mail->compose('contact/html', ['contactForm' => $form]) + * Yii::$app->mailer->compose('contact/html', ['contactForm' => $form]) * ->setFrom('from@domain.com') * ->setTo($form->email) * ->setSubject($form->subject) diff --git a/framework/mail/MessageInterface.php b/framework/mail/MessageInterface.php index 9364588..aef63de 100644 --- a/framework/mail/MessageInterface.php +++ b/framework/mail/MessageInterface.php @@ -16,7 +16,7 @@ namespace yii\mail; * Messages are sent by a [[\yii\mail\MailerInterface|mailer]], like the following, * * ~~~ - * Yii::$app->mail->compose() + * Yii::$app->mailer->compose() * ->setFrom('from@domain.com') * ->setTo($form->email) * ->setSubject($form->subject) diff --git a/tests/unit/extensions/swiftmailer/MessageTest.php b/tests/unit/extensions/swiftmailer/MessageTest.php index f92e08c..a0c88de 100644 --- a/tests/unit/extensions/swiftmailer/MessageTest.php +++ b/tests/unit/extensions/swiftmailer/MessageTest.php @@ -26,7 +26,7 @@ class MessageTest extends VendorTestCase { $this->mockApplication([ 'components' => [ - 'mail' => $this->createTestEmailComponent() + 'mailer' => $this->createTestEmailComponent() ] ]); $filePath = $this->getTestFilePath(); @@ -68,7 +68,7 @@ class MessageTest extends VendorTestCase */ protected function createTestMessage() { - return Yii::$app->get('mail')->compose(); + return Yii::$app->get('mailer')->compose(); } /** diff --git a/tests/unit/framework/mail/BaseMessageTest.php b/tests/unit/framework/mail/BaseMessageTest.php index 7a52b42..539b730 100644 --- a/tests/unit/framework/mail/BaseMessageTest.php +++ b/tests/unit/framework/mail/BaseMessageTest.php @@ -16,7 +16,7 @@ class BaseMessageTest extends TestCase { $this->mockApplication([ 'components' => [ - 'mail' => $this->createTestEmailComponent() + 'mailer' => $this->createTestEmailComponent() ] ]); } @@ -36,7 +36,7 @@ class BaseMessageTest extends TestCase */ protected function getMailer() { - return Yii::$app->get('mail'); + return Yii::$app->get('mailer'); } // Tests :