1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Exchange Rate Bundle, an RunOpenCode project. |
4
|
|
|
* |
5
|
|
|
* (c) 2017 RunOpenCode |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace RunOpenCode\Bundle\ExchangeRate\DependencyInjection\CompilerPass; |
11
|
|
|
|
12
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
14
|
|
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class NotificationsCompilerPass |
18
|
|
|
* |
19
|
|
|
* Compiler pass for notifications |
20
|
|
|
* |
21
|
|
|
* @package RunOpenCode\Bundle\ExchangeRate\DependencyInjection\CompilerPass |
22
|
|
|
*/ |
23
|
|
|
class NotificationsCompilerPass implements CompilerPassInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
5 |
|
public function process(ContainerBuilder $container) |
29
|
|
|
{ |
30
|
5 |
|
if (!$container->hasDefinition('runopencode.exchange_rate.notifications.email')) { |
31
|
1 |
|
return; |
32
|
|
|
} |
33
|
|
|
|
34
|
4 |
|
if (!$container->hasParameter('runopencode.exchange_rate.notifications.email.recipients')) { |
35
|
1 |
|
$container->removeDefinition('runopencode.exchange_rate.notifications.email'); |
36
|
1 |
|
return; |
37
|
|
|
} |
38
|
|
|
|
39
|
3 |
|
if (!$container->hasDefinition('mailer') || !class_exists('\\Symfony\\Bundle\\SwiftmailerBundle\\SwiftmailerBundle')) { |
40
|
1 |
|
throw new RuntimeException('Bundle "symfony/swiftmailer-bundle" is required for email notifications.'); |
41
|
|
|
} |
42
|
|
|
|
43
|
2 |
|
$recipients = $container->getParameter('runopencode.exchange_rate.notifications.email.recipients'); |
44
|
|
|
|
45
|
2 |
|
if (0 === count($recipients)) { |
46
|
1 |
|
throw new RuntimeException('At least one recipient for e-mail notifications must be provided.'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$container |
50
|
1 |
|
->getDefinition('runopencode.exchange_rate.notifications.email') |
51
|
1 |
|
->setArgument(2, $recipients) |
52
|
1 |
|
->addTag('kernel.event_listener', [ 'event' => 'runopencode.exchange_rate.fetch.success' ]) |
53
|
1 |
|
->addTag('kernel.event_listener', [ 'event' => 'runopencode.exchange_rate.fetch.error' ]) |
54
|
|
|
; |
55
|
1 |
|
} |
56
|
|
|
} |
57
|
|
|
|