-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcontainer.php
43 lines (37 loc) · 1022 Bytes
/
container.php
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
<?php
/**
* Returns a Psr\Container\ContainerInterface implementation
*
* For this, I am using `zendframework/zend-servicemanager`
* But, you can use any PSR-11 Container compatible implementation
*/
use App\Handler\SendForgotPasswordEmailHandler;
use App\Handler\SendImportantEmailHandler;
use App\Mailer;
use Zend\ServiceManager\Factory\InvokableFactory;
use Zend\ServiceManager\ServiceManager;
$container = new ServiceManager;
$invokableFactory = new InvokableFactory();
$container->setFactory(
Mailer::class,
function() {
return new Mailer();
}
);
$container->setFactory(
SendForgotPasswordEmailHandler::class,
function() use ($container) {
return new SendForgotPasswordEmailHandler(
$container->get(Mailer::class)
);
}
);
$container->setFactory(
SendImportantEmailHandler::class,
function() use ($container) {
return new SendImportantEmailHandler(
$container->get(Mailer::class)
);
}
);
return $container;