1: <?php
2:
3: namespace Charcoal\Email\ServiceProvider;
4:
5: use \Pimple\Container;
6: use \Pimple\ServiceProviderInterface;
7:
8:
9: use \PHPMailer\PHPMailer\PHPMailer;
10:
11: use \Charcoal\Email\Email;
12: use \Charcoal\Email\EmailInterface;
13: use \Charcoal\Email\EmailConfig;
14:
15: use \Charcoal\Factory\GenericFactory;
16:
17: 18: 19: 20: 21: 22: 23: 24: 25: 26:
27: class EmailServiceProvider implements ServiceProviderInterface
28: {
29: 30: 31: 32:
33: public function register(Container $container)
34: {
35: 36: 37: 38:
39: $container['email/config'] = function (Container $container) {
40: $appConfig = $container['config'];
41: $emailConfig = new EmailConfig($appConfig['email']);
42: return $emailConfig;
43: };
44:
45: 46: 47: 48:
49: $container['email/view'] = function (Container $container) {
50: return $container['view'];
51: };
52:
53: 54: 55:
56: $container['email/factory'] = function(Container $container) {
57: return new GenericFactory([
58: 'map' => [
59: 'email' => Email::class
60: ],
61: 'base_class' => EmailInterface::class,
62: 'default_class' => Email::class,
63: 'arguments' => [[
64: 'logger' => $container['logger'],
65: 'config' => $container['email/config'],
66: 'view' => $container['email/view'],
67: 'template_factory' => $container['template/factory'],
68: 'queue_item_factory' => $container['model/factory'],
69: 'log_factory' => $container['model/factory']
70: ]]
71: ]);
72: };
73:
74: 75: 76: 77:
78: $container['email'] = $container->factory(function (Container $container) {
79: return $container['email/factory']->create('email');
80: });
81: }
82: }
83: