1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2011-2012 Andreas Heigl<[email protected]> |
4
|
|
|
* |
5
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
6
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
7
|
|
|
* in the Software without restriction, including without limitation the rights |
8
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
9
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
10
|
|
|
* furnished to do so, subject to the following conditions: |
11
|
|
|
* |
12
|
|
|
* The above copyright notice and this permission notice shall be included in |
13
|
|
|
* all copies or substantial portions of the Software. |
14
|
|
|
* |
15
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
16
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
17
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
18
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
19
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
20
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
21
|
|
|
* THE SOFTWARE. |
22
|
|
|
* |
23
|
|
|
* @package HeiglContact |
24
|
|
|
* @author Andreas Heigl<[email protected]> |
25
|
|
|
* @copyright 2011-2012 Andreas Heigl |
26
|
|
|
* @license http://www.opesource.org/licenses/mit-license.php MIT-License |
27
|
|
|
* @version 0.0 |
28
|
|
|
* @since 06.03.2012 |
29
|
|
|
* @link http://github.com/heiglandreas/php.ug |
30
|
|
|
*/ |
31
|
|
|
|
32
|
|
|
namespace Org_Heigl\Contact\Service; |
33
|
|
|
|
34
|
|
|
use Interop\Container\ContainerInterface; |
35
|
|
|
use Traversable; |
36
|
|
|
use Zend\Mail\Transport; |
37
|
|
|
use Zend\ServiceManager\Factory\FactoryInterface; |
38
|
|
|
use Zend\Stdlib\ArrayUtils; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* The Contact-Controller Factory |
42
|
|
|
* |
43
|
|
|
* @author Andreas Heigl<[email protected]> |
44
|
|
|
* @copyright 2011-2012 Andreas Heigl |
45
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT-License |
46
|
|
|
* @version 0.0 |
47
|
|
|
* @since 06.03.2012 |
48
|
|
|
* @link http://github.com/heiglandreas/OrgHeiglContact |
49
|
|
|
*/ |
50
|
|
|
class MailTransportFactory implements FactoryInterface |
51
|
|
|
{ |
52
|
|
|
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
53
|
|
|
{ |
54
|
|
|
$config = $container->get('config'); |
55
|
|
|
if ($config instanceof Traversable) { |
56
|
|
|
$config = ArrayUtils::iteratorToArray($config); |
57
|
|
|
} |
58
|
|
|
$config = $config['OrgHeiglContact']['mail_transport']; |
59
|
|
|
$class = $config['class']; |
60
|
|
|
$options = $config['options']; |
61
|
|
|
|
62
|
|
|
switch ($class) { |
63
|
|
|
case 'Zend\Mail\Transport\Sendmail': |
64
|
|
|
case 'Sendmail': |
65
|
|
|
case 'sendmail'; |
66
|
|
|
$transport = new Transport\Sendmail(); |
67
|
|
|
break; |
68
|
|
|
case 'Zend\Mail\Transport\Smtp'; |
69
|
|
|
case 'Smtp'; |
70
|
|
|
case 'smtp'; |
71
|
|
|
$options = new Transport\SmtpOptions($options); |
72
|
|
|
$transport = new Transport\Smtp($options); |
73
|
|
|
break; |
74
|
|
|
case 'Zend\Mail\Transport\File'; |
75
|
|
|
case 'File'; |
76
|
|
|
case 'file'; |
77
|
|
|
$options = new Transport\FileOptions($options); |
78
|
|
|
$transport = new Transport\File($options); |
79
|
|
|
break; |
80
|
|
|
default: |
81
|
|
|
throw new \DomainException(sprintf( |
82
|
|
|
'Unknown mail transport type provided ("%s")', |
83
|
|
|
$class |
84
|
|
|
)); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return $transport; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|