|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the pixelart Swiftmailer manipulator bundle. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) pixelart GmbH |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Pixelart\Bundle\SwiftmailerManipulatorBundle\DependencyInjection; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Config\FileLocator; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\DefinitionDecorator; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
|
19
|
|
|
|
|
20
|
|
|
class PixelartSwiftmailerManipulatorExtension extends Extension |
|
21
|
|
|
{ |
|
22
|
50 |
|
public function load(array $configs, ContainerBuilder $container) |
|
23
|
|
|
{ |
|
24
|
50 |
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
25
|
50 |
|
$loader->load('services.xml'); |
|
26
|
|
|
|
|
27
|
50 |
|
$configuration = $this->getConfiguration($configs, $container); |
|
28
|
50 |
|
$config = $this->processConfiguration($configuration, $configs); |
|
29
|
|
|
|
|
30
|
50 |
|
foreach ($config['mailers'] as $name => $mailer) { |
|
31
|
40 |
|
$this->configureMailer($name, $mailer, $container); |
|
32
|
30 |
|
} |
|
33
|
50 |
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param string $name The mailer name |
|
37
|
|
|
* @param array $mailer The mailer configuration |
|
38
|
|
|
* @param ContainerBuilder $container The container builder |
|
39
|
|
|
*/ |
|
40
|
40 |
|
private function configureMailer($name, array $mailer, ContainerBuilder $container) |
|
41
|
|
|
{ |
|
42
|
40 |
|
$this->configureMailerManipulator($name, $mailer, $container); |
|
43
|
40 |
|
$this->configureMailerFromAddress($name, $mailer, $container); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param string $name The mailer name |
|
48
|
|
|
* @param array $mailer The mailer configuration |
|
49
|
|
|
* @param ContainerBuilder $container The container builder |
|
50
|
40 |
|
*/ |
|
51
|
|
|
private function configureMailerManipulator($name, array $mailer, ContainerBuilder $container) |
|
52
|
40 |
|
{ |
|
53
|
40 |
|
if (!empty($mailer['prepend_subject']) || !empty($mailer['prepend_body'])) { |
|
54
|
40 |
|
$container->setParameter( |
|
55
|
40 |
|
sprintf('pixelart_swiftmailer_manipulator.mailer.%s.manipulator.prepend_subject', $name), |
|
56
|
24 |
|
!empty($mailer['prepend_subject']) ? $mailer['prepend_subject'] : null |
|
57
|
40 |
|
); |
|
58
|
40 |
|
$container->setParameter( |
|
59
|
40 |
|
sprintf('pixelart_swiftmailer_manipulator.mailer.%s.manipulator.prepend_body', $name), |
|
60
|
24 |
|
!empty($mailer['prepend_body']) ? $mailer['prepend_body'] : null |
|
61
|
|
|
); |
|
62
|
40 |
|
|
|
63
|
16 |
|
$definitionDecorator = new DefinitionDecorator( |
|
64
|
24 |
|
'pixelart_swiftmailer_manipulator.plugin.manipulator.abstract' |
|
65
|
|
|
); |
|
66
|
|
|
|
|
67
|
40 |
|
$container |
|
68
|
40 |
|
->setDefinition( |
|
69
|
|
|
sprintf('pixelart_swiftmailer_manipulator.mailer.%s.plugin.manipulator', $name), |
|
70
|
24 |
|
$definitionDecorator |
|
71
|
40 |
|
) |
|
72
|
40 |
|
->addArgument( |
|
73
|
24 |
|
sprintf('%%pixelart_swiftmailer_manipulator.mailer.%s.manipulator.prepend_subject%%', $name) |
|
74
|
40 |
|
) |
|
75
|
40 |
|
->addArgument( |
|
76
|
24 |
|
sprintf('%%pixelart_swiftmailer_manipulator.mailer.%s.manipulator.prepend_body%%', $name) |
|
77
|
|
|
) |
|
78
|
|
|
; |
|
79
|
|
|
|
|
80
|
40 |
|
$container |
|
81
|
40 |
|
->getDefinition(sprintf('pixelart_swiftmailer_manipulator.mailer.%s.plugin.manipulator', $name)) |
|
82
|
|
|
->addTag(sprintf('swiftmailer.%s.plugin', $name)) |
|
83
|
24 |
|
; |
|
84
|
40 |
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param string $name The mailer name |
|
89
|
|
|
* @param array $mailer The mailer configuration |
|
90
|
|
|
* @param ContainerBuilder $container The container builder |
|
91
|
|
|
*/ |
|
92
|
|
|
private function configureMailerFromAddress($name, array $mailer, ContainerBuilder $container) |
|
93
|
|
|
{ |
|
94
|
|
|
if (!empty($mailer['from_address'])) { |
|
95
|
|
|
$container->setParameter( |
|
96
|
|
|
sprintf('pixelart_swiftmailer_manipulator.mailer.%s.impersonate.from_address', $name), |
|
97
|
|
|
!empty($mailer['from_address']) ? $mailer['from_address'] : null |
|
98
|
|
|
); |
|
99
|
|
|
|
|
100
|
|
|
$definitionDecorator = new DefinitionDecorator( |
|
101
|
|
|
'pixelart_swiftmailer_manipulator.plugin.impersonate.abstract' |
|
102
|
|
|
); |
|
103
|
|
|
|
|
104
|
|
|
$container |
|
105
|
|
|
->setDefinition( |
|
106
|
|
|
sprintf('pixelart_swiftmailer_manipulator.mailer.%s.plugin.impersonate', $name), |
|
107
|
|
|
$definitionDecorator |
|
108
|
|
|
) |
|
109
|
|
|
->addArgument( |
|
110
|
|
|
sprintf('%%pixelart_swiftmailer_manipulator.mailer.%s.impersonate.from_address%%', $name) |
|
111
|
|
|
) |
|
112
|
|
|
; |
|
113
|
|
|
|
|
114
|
|
|
$container |
|
115
|
|
|
->getDefinition(sprintf('pixelart_swiftmailer_manipulator.mailer.%s.plugin.impersonate', $name)) |
|
116
|
|
|
->addTag(sprintf('swiftmailer.%s.plugin', $name)) |
|
117
|
|
|
; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|