Completed
Push — develop ( 6bec98...3062c0 )
by Carsten
12s
created

FileTransport::send()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 13
nc 2
nop 1
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2017 Cross Solution <http://cross-solution.de>
8
 */
9
10
namespace Core\Mail;
11
12
use Zend\Mail\Transport\File as BaseFileTransport;
13
use Zend\Mail\Transport\Exception\RuntimeException;
14
15
/**
16
 * A class to handle mail transport during tests
17
 *
18
 * @package Core\Mail
19
 * @author Anthonius Munthi <[email protected]>
20
 * @since 0.30.1
21
 */
22
class FileTransport extends BaseFileTransport
23
{
24
    /**
25
     * Saves e-mail message to a file
26
     *
27
     * @param \Zend\Mail\Message $message
28
     * @throws RuntimeException on not writable target directory or
29
     * on file_put_contents() failure
30
     */
31
    public function send(\Zend\Mail\Message $message)
32
    {
33
        $options  = $this->options;
34
        $filename = call_user_func($options->getCallback(), $this);
35
        $file     = $options->getPath() . DIRECTORY_SEPARATOR . $filename;
36
37
38
        $contents = $message->toString();
39
        $umask = umask();
40
        umask(022);
41
        if (false === file_put_contents($file, $contents, LOCK_EX)) {
42
            throw new RuntimeException(sprintf(
43
                'Unable to write mail to file (directory "%s")',
44
                $options->getPath()
45
            ));
46
        }
47
        umask($umask);
48
        $this->lastFile = $file;
49
    }
50
}
51