Completed
Push — master ( 9a185e...8c03fb )
by Tim
10s
created

SendmailTransportMailerFactory::factory()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 24
rs 8.9713
c 1
b 0
f 0
cc 2
eloc 9
nc 2
nop 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Utils\SwiftMailer\SendmailTransportMailerFactory
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Utils\SwiftMailer;
22
23
use TechDivision\Import\Utils\SwiftMailerKeys;
24
use TechDivision\Import\Configuration\SwiftMailerConfigurationInterface;
25
26
/**
27
 * Factory implementation for a swift mailer with a simple sendmail transport.
28
 *
29
 * @author    Tim Wagner <[email protected]>
30
 * @copyright 2016 TechDivision GmbH <[email protected]>
31
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
 * @link      https://github.com/techdivision/import
33
 * @link      http://www.techdivision.com
34
 */
35
class SendmailTransportMailerFactory
36
{
37
38
    /**
39
     * Creates a new swift mailer instance based on the passed configuration.
40
     *
41
     * @param \TechDivision\Import\Configuration\SwiftMailerConfigurationInterface $swiftMailerConfiguration The mailer configuration
42
     *
43
     * @return \Swift_Mailer The mailer instance
44
     */
45
    public static function factory(SwiftMailerConfigurationInterface $swiftMailerConfiguration)
46
    {
47
48
        // load the transport configuration
49
        $transportConfiguration = $swiftMailerConfiguration->getTransport();
50
51
        // load the transport factory
52
        $transportFactory = $transportConfiguration->getTransportFactory();
53
54
        // initialize and load the sendmail command parameter
55
        $command = '/usr/sbin/sendmail -bs';
56
        if ($transportConfiguration->hasParam(SwiftMailerKeys::COMMAND)) {
57
            $command = $transportConfiguration->getParam(SwiftMailerKeys::COMMAND);
58
        }
59
60
        // initialize and create the mailer transport instance
61
        $transport = $transportFactory::newInstance($command);
62
63
        // load the mailer factory
64
        $mailerFactory = $swiftMailerConfiguration->getMailerFactory();
65
66
        // initialize, create and return the swift mailer instance
67
        return $mailerFactory::newInstance($transport);
68
    }
69
}
70