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