1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Psr\EventDispatcher\EventDispatcherInterface; |
4
|
|
|
use Psr\EventDispatcher\ListenerProviderInterface; |
5
|
|
|
use Psr\Log\LoggerInterface; |
6
|
|
|
use Yiisoft\EventDispatcher\Dispatcher\Dispatcher; |
7
|
|
|
use Yiisoft\EventDispatcher\Provider\Provider; |
8
|
|
|
use Yiisoft\Factory\Definitions\Reference; |
9
|
|
|
use Yiisoft\Log\Logger; |
10
|
|
|
use Yiisoft\Mailer\Composer; |
11
|
|
|
use Yiisoft\Mailer\MailerInterface; |
12
|
|
|
use Yiisoft\Mailer\MessageFactory; |
13
|
|
|
use Yiisoft\Mailer\MessageFactoryInterface; |
14
|
|
|
use Yiisoft\Mailer\Tests\TestMailer; |
15
|
|
|
use Yiisoft\Mailer\Tests\TestMessage; |
16
|
|
|
use Yiisoft\View\Theme; |
17
|
|
|
use Yiisoft\View\View; |
18
|
|
|
|
19
|
|
|
$tempDir = sys_get_temp_dir(); |
20
|
|
|
|
21
|
|
|
return [ |
22
|
|
|
ListenerProviderInterface::class => function () { |
23
|
|
|
return new class () implements ListenerProviderInterface { |
24
|
|
|
private $listeners = []; |
25
|
|
|
|
26
|
|
|
public function getListenersForEvent(object $event): iterable |
27
|
|
|
{ |
28
|
|
|
$eventName = get_class($event); |
29
|
|
|
return isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : []; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function attach(callable $callback, string $eventName): void |
33
|
|
|
{ |
34
|
|
|
$this->listeners[$eventName][] = $callback; |
35
|
|
|
} |
36
|
|
|
}; |
37
|
|
|
}, |
38
|
|
|
EventDispatcherInterface::class => Dispatcher::class, |
39
|
|
|
LoggerInterface::class => [ |
40
|
|
|
'__class' => Logger::class, |
41
|
|
|
'__construct()' => [ |
42
|
|
|
'targets' => [], |
43
|
|
|
], |
44
|
|
|
], |
45
|
|
|
Theme::class => [ |
46
|
|
|
'__class' => Theme::class, |
47
|
|
|
], |
48
|
|
|
View::class => [ |
49
|
|
|
'__class' => View::class, |
50
|
|
|
'__construct()' => [ |
51
|
|
|
'basePath' => $tempDir . DIRECTORY_SEPARATOR . 'views', |
52
|
|
|
'theme' => Reference::to(Theme::class), |
53
|
|
|
'eventDispatcher' => Reference::to(EventDispatcherInterface::class), |
54
|
|
|
'logger' => Reference::to(LoggerInterface::class) |
55
|
|
|
], |
56
|
|
|
], |
57
|
|
|
MessageFactoryInterface::class => [ |
58
|
|
|
'__class' => MessageFactory::class, |
59
|
|
|
'__construct()' => [ |
60
|
|
|
'class' => TestMessage::class, |
61
|
|
|
], |
62
|
|
|
], |
63
|
|
|
Composer::class => [ |
64
|
|
|
'__class' => Composer::class, |
65
|
|
|
'__construct()' => [ |
66
|
|
|
'view' => Reference::to(View::class), |
67
|
|
|
'viewPath' => $tempDir . DIRECTORY_SEPARATOR . 'views' |
68
|
|
|
], |
69
|
|
|
], |
70
|
|
|
MailerInterface::class => [ |
71
|
|
|
'__class' => TestMailer::class, |
72
|
|
|
'__construct()' => [ |
73
|
|
|
'messageFactory' => Reference::to(MessageFactoryInterface::class), |
74
|
|
|
'composer' => Reference::to(Composer::class), |
75
|
|
|
'eventDispatcher' => Reference::to(EventDispatcherInterface::class), |
76
|
|
|
'logger' => Reference::to(LoggerInterface::class), |
77
|
|
|
'path' => $tempDir . DIRECTORY_SEPARATOR . 'mails', |
78
|
|
|
], |
79
|
|
|
], |
80
|
|
|
]; |
81
|
|
|
|