Commit 0dfc8b1f by Qiang Xue

refactored BaseMailer about message file name generation.

parent 370b0564
......@@ -297,14 +297,22 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
if ($this->fileTransportCallback !== null) {
$file = $path . '/' . call_user_func($this->fileTransportCallback, $this, $message);
} else {
$time = microtime(true);
$file = $path . '/' . date('Ymd-His-', $time) . sprintf('%04d', (int)(($time - (int)$time) * 10000)) . '-' . sprintf('%04d', mt_rand(0, 10000)) . '.eml';
$file = $this->generateMessageFileName();
}
file_put_contents($file, $message->toString());
return true;
}
/**
* @return string the file name for saving the message when [[useFileTransport]] is true.
*/
public function generateMessageFileName()
{
$time = microtime(true);
return date('Ymd-His-', $time) . sprintf('%04d', (int)(($time - (int)$time) * 10000)) . '-' . sprintf('%04d', mt_rand(0, 10000)) . '.eml';
}
/**
* Finds the view file corresponding to the specified relative view name.
* This method will return the view file by prefixing the view name with [[viewPath]].
* @param string $view a relative view name. The name does NOT start with a slash.
......
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