Commit 2457e247 by Alexander Makarov

Fixes #4071: `mail` component renamed to `mailer`, `yii\log\EmailTarget::$mail`…

Fixes #4071: `mail` component renamed to `mailer`, `yii\log\EmailTarget::$mail` renamed to `yii\log\EmailTarget::$mailer`
parent 9f3e7169
......@@ -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
......
......@@ -8,7 +8,7 @@ return [
'password' => '',
'charset' => 'utf8',
],
'mail' => [
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mail',
],
......
......@@ -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)
......
......@@ -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)
......
......@@ -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';
}
}
......@@ -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';
}
}
......@@ -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
......
......@@ -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)
......
......@@ -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';
}
}
......@@ -22,9 +22,9 @@ $this->params['breadcrumbs'][] = $this->title;
<p>
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.
<?php if (Yii::$app->mail->useFileTransport): ?>
<?php if (Yii::$app->mailer->useFileTransport): ?>
Because the application is in development mode, the email is not sent but saved as
a file under <code><?= Yii::getAlias(Yii::$app->mail->fileTransportPath) ?></code>.
a file under <code><?= Yii::getAlias(Yii::$app->mailer->fileTransportPath) ?></code>.
Please configure the <code>useFileTransport</code> property of the <code>mail</code>
application component to be false to enable email sending.
<?php endif; ?>
......
......@@ -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' => [
......
......@@ -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' => [
......
......@@ -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();
```
......
......@@ -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';
};
}
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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.
......@@ -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 <qiang.xue@gmail.com>
* @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);
......
......@@ -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)
......
......@@ -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)
......
......@@ -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();
}
/**
......
......@@ -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 :
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment