Passed
Push — develop ( 6283c8...f1d504 )
by Daniel
08:54
created

MailTransportFactory::__invoke()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 42
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 42
ccs 0
cts 26
cp 0
rs 8.8497
c 0
b 0
f 0
cc 6
nc 8
nop 3
crap 42
1
<?php
2
/**
3
 * ZfMailer
4
 *
5
 * @author     Daniel Wolkenhauer <[email protected]>
6
 * @copyright  Copyright (c) 1997-2019 Daniel Wolkenhauer
7
 * @link       http://dw-labs.de/zfmailer
8
 * @version    0.1.0
9
 */
10
11
namespace ZfMailer\Service;
12
13
use Traversable;
14
use Zend\Mail\Transport;
15
use Interop\Container\ContainerInterface;
16
use Interop\Container\Exception\ContainerException;
17
use Zend\ServiceManager\Factory\FactoryInterface;
18
use Zend\ServiceManager\ServiceLocatorInterface;
19
use Zend\Stdlib\ArrayUtils;
20
21
/**
22
* Mailer Factory
23
* Initilisiert den Transport-Service
24
* 
25
* @package ZfMailer
26
* @subpackage Service
27
*/
28
class MailTransportFactory implements FactoryInterface
29
{
30
31
  public function __invoke(ContainerInterface $serviceManager, $requestedName, array $options = null)
32
  {
33
34
    $options = $serviceManager->get('ZfMailerOptions');
35
36
    $smartHost = $options->getSmartHost();
37
    $ssl = null;
38
39
    switch ($smartHost['server_port']) {
40
      case '25':
41
        $ssl = null;
42
        break;
43
      case '465':
44
        $ssl = 'ssl';
45
        break;
46
      case '587':
47
        $ssl = 'tls';
48
        break;
49
      
50
      default:
51
        $ssl = null;
52
        break;
53
    }
54
55
    $smtpOptions = array(
56
      'host'             => $smartHost['server_name'],
57
      'port'             => $smartHost['server_port'],
58
      'connectionClass'  => 'login',
59
      'connectionConfig' => array(
60
        'username' => $smartHost['username'],
61
        'password' => $smartHost['password'],
62
      ),
63
    );
64
65
    if (isset($ssl) && !empty($ssl)) {
66
      $smtpOptions['connectionConfig']['ssl'] = $ssl;
67
    }
68
69
    $transportOptions = new Transport\SmtpOptions($smtpOptions);
70
    $transport = new Transport\Smtp($transportOptions);
71
72
    return $transport;
73
74
    
75
76
  }
77
78
  /**
79
   * Create Service Factory
80
   *
81
   * @todo #ZFMAIL-1 - Konfiguration für SSL verbesern
82
   * @param ServiceLocatorInterface $serviceLocator
83
   */
84 4
  public function createService(ServiceLocatorInterface $serviceLocator)
85
  {
86
87
    // $options = $serviceLocator->get('ZfMailerOptions');
88
89
    // $smartHost = $options->getSmartHost();
90
    // $ssl = null;
91
92
    // switch ($smartHost['server_port']) {
93
    //   case '25':
94
    //     $ssl = null;
95
    //     break;
96
    //   case '465':
97
    //     $ssl = 'ssl';
98
    //     break;
99
    //   case '587':
100
    //     $ssl = 'tls';
101
    //     break;
102
      
103
    //   default:
104
    //     $ssl = null;
105
    //     break;
106
    // }
107
108
    // $smtpOptions = array(
109
    //   'host'             => $smartHost['server_name'],
110
    //   'port'             => $smartHost['server_port'],
111
    //   'connectionClass'  => 'login',
112
    //   'connectionConfig' => array(
113
    //     'username' => $smartHost['username'],
114
    //     'password' => $smartHost['password'],
115
    //   ),
116
    // );
117
118
    // if (isset($ssl) && !empty($ssl)) {
119
    //   $smtpOptions['connectionConfig']['ssl'] = $ssl;
120
    // }
121
122
    // $transportOptions = new Transport\SmtpOptions($smtpOptions);
123
    // $transport = new Transport\Smtp($transportOptions);
124
125
    // return $transport;
126 4
    return $this->__invoke($serviceLocator, null);
127
128
  }
129
130
}
131