|
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\Log\Logger; |
|
8
|
|
|
use Yiisoft\Mailer\Composer; |
|
9
|
|
|
use Yiisoft\Mailer\MailerInterface; |
|
10
|
|
|
use Yiisoft\Mailer\MessageFactory; |
|
11
|
|
|
use Yiisoft\Mailer\MessageFactoryInterface; |
|
12
|
|
|
use Yiisoft\Mailer\Tests\TestMailer; |
|
13
|
|
|
use Yiisoft\Mailer\Tests\TestMessage; |
|
14
|
|
|
use Yiisoft\View\Theme; |
|
15
|
|
|
use Yiisoft\View\View; |
|
16
|
|
|
|
|
17
|
|
|
$tempDir = sys_get_temp_dir(); |
|
18
|
|
|
|
|
19
|
|
|
return [ |
|
20
|
|
|
ListenerProviderInterface::class => function () { |
|
21
|
|
|
return new class() implements ListenerProviderInterface { |
|
22
|
|
|
private $listeners = []; |
|
23
|
|
|
|
|
24
|
|
|
public function getListenersForEvent(object $event): iterable |
|
25
|
|
|
{ |
|
26
|
|
|
$eventName = get_class($event); |
|
27
|
|
|
return isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : []; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function attach(callable $callback, string $eventName): void |
|
31
|
|
|
{ |
|
32
|
|
|
$this->listeners[$eventName][] = $callback; |
|
33
|
|
|
} |
|
34
|
|
|
}; |
|
35
|
|
|
}, |
|
36
|
|
|
EventDispatcherInterface::class => Dispatcher::class, |
|
37
|
|
|
LoggerInterface::class => Logger::class, |
|
38
|
|
|
Theme::class => [ |
|
39
|
|
|
'__class' => Theme::class, |
|
40
|
|
|
], |
|
41
|
|
|
View::class => [ |
|
42
|
|
|
'__class' => View::class, |
|
43
|
|
|
'__construct()' => [ |
|
44
|
|
|
'basePath' => $tempDir . DIRECTORY_SEPARATOR . 'views', |
|
45
|
|
|
], |
|
46
|
|
|
], |
|
47
|
|
|
MessageFactoryInterface::class => [ |
|
48
|
|
|
'__class' => MessageFactory::class, |
|
49
|
|
|
'__construct()' => [ |
|
50
|
|
|
'class' => TestMessage::class, |
|
51
|
|
|
], |
|
52
|
|
|
], |
|
53
|
|
|
Composer::class => [ |
|
54
|
|
|
'__class' => Composer::class, |
|
55
|
|
|
'__construct()' => [ |
|
56
|
|
|
'viewPath' => $tempDir . DIRECTORY_SEPARATOR . 'views' |
|
57
|
|
|
], |
|
58
|
|
|
], |
|
59
|
|
|
MailerInterface::class => [ |
|
60
|
|
|
'__class' => TestMailer::class, |
|
61
|
|
|
'__construct()' => [ |
|
62
|
|
|
'path' => $tempDir . DIRECTORY_SEPARATOR . 'mails', |
|
63
|
|
|
], |
|
64
|
|
|
], |
|
65
|
|
|
]; |
|
66
|
|
|
|