Completed
Push — master ( cc7816...e04f3c )
by Pavel
01:48
created

src/DI/MailingExtension.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @copyright   Copyright (c) 2015 ublaboo <[email protected]>
7
 * @author      Pavel Janda <[email protected]>
8
 * @package     Ublaboo
9
 */
10
11
namespace Ublaboo\Mailing\DI;
12
13
use Nette\DI\CompilerExtension;
14
use Nette\DI\Helpers;
15
use Ublaboo\Mailing\MailFactory;
16
use Ublaboo\Mailing\MailLogger;
17
18
class MailingExtension extends CompilerExtension
19
{
20
21
	public const CONFIG_LOG  = 'log';
22
	public const CONFIG_SEND = 'send';
23
	public const CONFIG_BOTH = 'both';
24
25
	/**
26
	 * @var array
27
	 */
28
	private $defaults = [
29
		'do' => self::CONFIG_BOTH,
30
		'logDirectory' => '%appDir%/../log/mails',
31
		'mailImagesBasePath' => '%wwwDir%',
32
		'mails' => [],
33
	];
34
35
36
	public function loadConfiguration(): void
37
	{
38
		$config = $this->expandConfigParams();
39
40
		$builder = $this->getContainerBuilder();
41
42
		$builder->addDefinition($this->prefix('mailLogger'))
0 ignored issues
show
Deprecated Code introduced by Scrutinizer Auto-Fixer
The method Nette\DI\ServiceDefinition::setClass() has been deprecated.

This method has been deprecated.

Loading history...
43
			->setClass(MailLogger::class)
44
			->setArguments([$config['logDirectory']]);
45
46
		$builder->addDefinition($this->prefix('mailFactory'))
0 ignored issues
show
Deprecated Code introduced by Scrutinizer Auto-Fixer
The method Nette\DI\ServiceDefinition::setClass() has been deprecated.

This method has been deprecated.

Loading history...
47
			->setClass(MailFactory::class)
48
			->setArguments([$config['do'], $config['mailImagesBasePath'], $config['mails']]);
49
	}
50
51
52
	private function expandConfigParams(): array
53
	{
54
		$config = $this->validateConfig($this->defaults, $this->config);
55
56
		$config['logDirectory'] = Helpers::expand(
57
			$config['logDirectory'],
58
			$this->getContainerBuilder()->parameters
59
		);
60
61
		$config['mailImagesBasePath'] = Helpers::expand(
62
			$config['mailImagesBasePath'],
63
			$this->getContainerBuilder()->parameters
64
		);
65
66
		return $config;
67
	}
68
}
69