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 |
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $name The mailer name |
47
|
|
|
* @param array $mailer The mailer configuration |
48
|
|
|
* @param ContainerBuilder $container The container builder |
49
|
|
|
*/ |
50
|
40 |
|
private function configureMailerManipulator($name, array $mailer, ContainerBuilder $container) |
51
|
|
|
{ |
52
|
40 |
|
if (!empty($mailer['prepend_subject']) || !empty($mailer['prepend_body'])) { |
53
|
40 |
|
$container->setParameter( |
54
|
40 |
|
sprintf('pixelart_swiftmailer_manipulator.mailer.%s.manipulator.prepend_subject', $name), |
55
|
40 |
|
!empty($mailer['prepend_subject']) ? $mailer['prepend_subject'] : null |
56
|
24 |
|
); |
57
|
40 |
|
$container->setParameter( |
58
|
40 |
|
sprintf('pixelart_swiftmailer_manipulator.mailer.%s.manipulator.prepend_body', $name), |
59
|
40 |
|
!empty($mailer['prepend_body']) ? $mailer['prepend_body'] : null |
60
|
24 |
|
); |
61
|
|
|
|
62
|
40 |
|
$definitionDecorator = new DefinitionDecorator( |
63
|
16 |
|
'pixelart_swiftmailer_manipulator.plugin.manipulator.abstract' |
64
|
24 |
|
); |
65
|
|
|
|
66
|
|
|
$container |
67
|
40 |
|
->setDefinition( |
68
|
40 |
|
sprintf('pixelart_swiftmailer_manipulator.mailer.%s.plugin.manipulator', $name), |
69
|
|
|
$definitionDecorator |
70
|
24 |
|
) |
71
|
40 |
|
->addArgument( |
72
|
40 |
|
sprintf('%%pixelart_swiftmailer_manipulator.mailer.%s.manipulator.prepend_subject%%', $name) |
73
|
24 |
|
) |
74
|
40 |
|
->addArgument( |
75
|
40 |
|
sprintf('%%pixelart_swiftmailer_manipulator.mailer.%s.manipulator.prepend_body%%', $name) |
76
|
24 |
|
) |
77
|
|
|
; |
78
|
|
|
|
79
|
|
|
$container |
80
|
40 |
|
->getDefinition(sprintf('pixelart_swiftmailer_manipulator.mailer.%s.plugin.manipulator', $name)) |
81
|
40 |
|
->addTag(sprintf('swiftmailer.%s.plugin', $name)) |
82
|
|
|
; |
83
|
24 |
|
} |
84
|
40 |
|
} |
85
|
|
|
} |
86
|
|
|
|