Class yii\debug\panels\MailPanel

Inheritanceyii\debug\panels\MailPanel » yii\debug\Panel » yii\base\Component
Available since extension's version2.0
Source Code https://github.com/yiisoft/yii2-debug/blob/master/src/panels/MailPanel.php

Debugger panel that collects and displays the generated emails.

Public Properties

Hide inherited properties

Property Type Description Defined By
$actions array Array of actions to add to the debug modules default controller. yii\debug\Panel
$data mixed Data associated with panel yii\debug\Panel
$detail string Content that is displayed in debugger detail view. yii\debug\Panel
$error yii\debug\FlattenException|null Error while saving the panel yii\debug\Panel
$id string Panel unique identifier. yii\debug\Panel
$mailPath string Path where all emails will be saved. yii\debug\panels\MailPanel
$messagesFileName array This property is read-only. yii\debug\panels\MailPanel
$module yii\debug\Module yii\debug\Panel
$name string Name of the panel. yii\debug\Panel
$summary string Content that is displayed at debug toolbar. yii\debug\Panel
$tag string Request data set identifier. yii\debug\Panel
$url string URL pointing to panel detail view. yii\debug\Panel

Protected Properties

Hide inherited properties

Property Type Description Defined By

Public Methods

Hide inherited methods

Method Description Defined By
getDetail() yii\debug\panels\MailPanel
getError() yii\debug\Panel
getMessagesFileName() Return array of created email files yii\debug\panels\MailPanel
getName() yii\debug\panels\MailPanel
getSummary() yii\debug\panels\MailPanel
getTraceLine() Returns a trace line yii\debug\Panel
getUrl() yii\debug\Panel
hasError() yii\debug\Panel
init() yii\debug\panels\MailPanel
isEnabled() Checks whether this panel is enabled. yii\debug\Panel
load() Loads data into the panel yii\debug\Panel
save() Save info about messages of current request. Each element is array holding message info, such as: time, reply, bc, cc, from, to and other. yii\debug\panels\MailPanel
setError() yii\debug\Panel

Property Details

Hide inherited properties

$mailPath public property

Path where all emails will be saved. should be an alias.

public string $mailPath '@runtime/debug/mail'
$messagesFileName public property

This property is read-only.

public array $messagesFileName null

Method Details

Hide inherited methods

getDetail() public method

public string getDetail ( )
return string

Content that is displayed in debugger detail view

                public function getDetail()
{
    $searchModel = new Mail();
    $dataProvider = $searchModel->search(Yii::$app->request->get(), $this->data);
    return Yii::$app->view->render('panels/mail/detail', [
        'panel' => $this,
        'dataProvider' => $dataProvider,
        'searchModel' => $searchModel
    ]);
}

            
getError() public method (available since version 2.0.10)
public yii\debug\FlattenException|null getError ( )

                public function getError()
{
    return $this->error;
}

            
getMessagesFileName() public method

Return array of created email files

public array getMessagesFileName ( )

                public function getMessagesFileName()
{
    $names = [];
    foreach ($this->_messages as $message) {
        $names[] = $message['file'];
    }
    return $names;
}

            
getName() public method

public string getName ( )
return string

Name of the panel

                public function getName()
{
    return 'Mail';
}

            
getSummary() public method

public string getSummary ( )
return string

Content that is displayed at debug toolbar

                public function getSummary()
{
    return Yii::$app->view->render('panels/mail/summary', [
        'panel' => $this,
        'mailCount' => count($this->data),
    ]);
}

            
getTraceLine() public method (available since version 2.0.7)

Defined in: yii\debug\Panel::getTraceLine()

Returns a trace line

public string getTraceLine ( $options )
$options array

The array with trace

return string

The trace line

                public function getTraceLine($options)
{
    if (!isset($options['text'])) {
        $options['text'] = "{$options['file']}:{$options['line']}";
    }
    $traceLine = $this->module->traceLine;
    if ($traceLine === false) {
        return $options['text'];
    }
    $options['file'] = str_replace('\\', '/', $options['file']);
    $rawLink = $traceLine instanceof \Closure ? $traceLine($options, $this) : $traceLine;
    return strtr($rawLink, ['{file}' => $options['file'], '{line}' => $options['line'], '{text}' => $options['text']]);
}

            
getUrl() public method
public string getUrl ( $additionalParams null )
$additionalParams null|array

Optional additional parameters to add to the route

return string

URL pointing to panel detail view

                public function getUrl($additionalParams = null)
{
    $route = [
        '/' . $this->module->id . '/default/view',
        'panel' => $this->id,
        'tag' => $this->tag,
    ];
    if (is_array($additionalParams)){
        $route = ArrayHelper::merge($route, $additionalParams);
    }
    return Url::toRoute($route);
}

            
hasError() public method (available since version 2.0.10)
public boolean hasError ( )

                public function hasError()
{
    return $this->error !== null;
}

            
init() public method

public void init ( )

                public function init()
{
    parent::init();
    Event::on('yii\mail\BaseMailer', BaseMailer::EVENT_AFTER_SEND, function ($event) {
        /* @var $message MessageInterface */
        $message = $event->message;
        $messageData = [
            'isSuccessful' => $event->isSuccessful,
            'from' => $this->convertParams($message->getFrom()),
            'to' => $this->convertParams($message->getTo()),
            'reply' => $this->convertParams($message->getReplyTo()),
            'cc' => $this->convertParams($message->getCc()),
            'bcc' => $this->convertParams($message->getBcc()),
            'subject' => $message->getSubject(),
            'charset' => $message->getCharset(),
        ];
        // add more information when message is a SwiftMailer message
        if ($message instanceof \yii\swiftmailer\Message) {
            /* @var $swiftMessage \Swift_Message */
            $swiftMessage = $message->getSwiftMessage();
            $body = $swiftMessage->getBody();
            if (empty($body)) {
                $parts = $swiftMessage->getChildren();
                foreach ($parts as $part) {
                    if (!($part instanceof \Swift_Mime_Attachment)) {
                        /* @var $part \Swift_Mime_MimePart */
                        if ($part->getContentType() === 'text/plain') {
                            $messageData['charset'] = $part->getCharset();
                            $body = $part->getBody();
                            break;
                        }
                    }
                }
            }
            $messageData['body'] = $body;
            $messageData['time'] = $swiftMessage->getDate();
            $messageData['headers'] = $swiftMessage->getHeaders();
        }
        // store message as file
        $fileName = $event->sender->generateMessageFileName();
        $mailPath = Yii::getAlias($this->mailPath);
        FileHelper::createDirectory($mailPath);
        file_put_contents($mailPath . '/' . $fileName, $message->toString());
        $messageData['file'] = $fileName;
        $this->_messages[] = $messageData;
    });
}

            
isEnabled() public method (available since version 2.0.10)

Defined in: yii\debug\Panel::isEnabled()

Checks whether this panel is enabled.

public boolean isEnabled ( )
return boolean

Whether this panel is enabled.

                public function isEnabled()
{
    return true;
}

            
load() public method

Defined in: yii\debug\Panel::load()

Loads data into the panel

public void load ( $data )
$data mixed

                public function load($data)
{
    $this->data = $data;
}

            
save() public method

Save info about messages of current request. Each element is array holding message info, such as: time, reply, bc, cc, from, to and other.

public array save ( )
return array

Messages

                public function save()
{
    return $this->_messages;
}

            
setError() public method (available since version 2.0.10)
public void setError ( yii\debug\FlattenException $error )
$error yii\debug\FlattenException

                public function setError(FlattenException $error)
{
    $this->error = $error;
}