1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
<?php
namespace FluentMail\App\Services\Mailer;
use FluentMail\App\Models\Logger; use FluentMail\App\Models\Settings; use FluentMail\Includes\Support\Arr; use FluentMail\Includes\Core\Application; use FluentMail\Includes\Support\ValidationException; use FluentMail\App\Services\Mailer\Providers\Factory;
class Manager { protected $app = null;
protected static $config = [];
protected static $settings = []; protected static $resolved = []; protected static $wpConfigSettings = [];
public function __construct(?Application $app = null) { $this->app = $app ?: fluentMail();
$this->initialize(); }
protected function initialize() { $this->loadConfigAndSettings();
$this->app->addCustomFilter('active_driver', [$this, 'activeDriver']); }
protected function loadConfigAndSettings() { static::$config = require(__DIR__ . '/Providers/config.php');
static::$settings = (new Settings)->getSettings();
$this->mergeConfigAndSettings(); }
protected function mergeConfigAndSettings() { $databaseSettings = $this->getSettings();
Arr::set(static::$config, 'mappings', Arr::get($databaseSettings, 'mappings')); Arr::set(static::$config, 'connections', Arr::get($databaseSettings, 'connections'));
if (isset($databaseSettings['misc'])) { Arr::set(static::$config, "misc", array_merge( static::$config['misc'], $databaseSettings['misc'] )); }
foreach (static::$config['providers'] as $key => $provider) { try { $optionKey = "providers.{$key}.options";
$options = array_merge( $provider['options'], Arr::get($databaseSettings, $optionKey, []) ); Arr::set(static::$config, $optionKey, $options);
} catch (ValidationException $e) { continue; } } }
public function getMailerConfigAndSettings() { return static::$config; }
public function getConfig($key = null, $default = null) { return $key ? Arr::get(static::$config, $key, $default) : static::$config; }
public function getSettings($key = null, $default = null) { return $key ? Arr::get(static::$settings, $key, $default) : static::$settings; }
public function getWPConfig($key = null, $default = null) { return $key ? Arr::get( static::$wpConfigSettings, $key, $default ) : static::$wpConfigSettings; }
public function activeDriver($phpMailer) { return fluentMailgetConnection($phpMailer->From); } }
|