forked from yiisoft/demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.php
80 lines (70 loc) · 2.84 KB
/
web.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
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
<?php
use App\Blog\Comment\CommentRepository;
use App\Blog\Comment\CommentService;
use App\Blog\Entity\Comment;
use App\Contact\ContactMailer;
use App\Factory\MiddlewareDispatcherFactory;
use App\Factory\ViewFactory;
use Cycle\ORM\ORMInterface;
use Nyholm\Psr7\Factory\Psr17Factory;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ServerRequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\UploadedFileFactoryInterface;
use Psr\Http\Message\UriFactoryInterface;
use Yiisoft\Auth\IdentityRepositoryInterface;
use Yiisoft\Mailer\MailerInterface;
use Yiisoft\View\WebView;
use Yiisoft\Yii\Web\Data\DataResponseFactory;
use Yiisoft\Yii\Web\Data\DataResponseFactoryInterface;
use Yiisoft\Yii\Web\Data\DataResponseFormatterInterface;
use Yiisoft\Yii\Web\Data\Formatter\HtmlDataResponseFormatter;
use Yiisoft\Yii\Web\MiddlewareDispatcher;
use Yiisoft\Yii\Web\Session\Session;
use Yiisoft\Yii\Web\Session\SessionInterface;
/**
* @var array $params
*/
return [
// PSR-17 factories:
RequestFactoryInterface::class => Psr17Factory::class,
ServerRequestFactoryInterface::class => Psr17Factory::class,
ResponseFactoryInterface::class => Psr17Factory::class,
StreamFactoryInterface::class => Psr17Factory::class,
UriFactoryInterface::class => Psr17Factory::class,
UploadedFileFactoryInterface::class => Psr17Factory::class,
DataResponseFormatterInterface::class => HtmlDataResponseFormatter::class,
DataResponseFactoryInterface::class => DataResponseFactory::class,
MiddlewareDispatcher::class => new MiddlewareDispatcherFactory(),
SessionInterface::class => [
'__class' => Session::class,
'__construct()' => [
$params['session']['options'] ?? [],
$params['session']['handler'] ?? null,
],
],
// here you can configure custom prefix of the web path
// \Yiisoft\Yii\Web\Middleware\SubFolder::class => [
// 'prefix' => '',
// ],
// View:
WebView::class => new ViewFactory(),
// User:
IdentityRepositoryInterface::class => static function (ContainerInterface $container) {
return $container->get(\Cycle\ORM\ORMInterface::class)->getRepository(\App\Entity\User::class);
},
// contact form mailer
ContactMailer::class => static function (ContainerInterface $container) use ($params) {
$mailer = $container->get(MailerInterface::class);
return new ContactMailer($mailer, $params['supportEmail']);
},
CommentService::class => static function (ContainerInterface $container) {
/**
* @var CommentRepository $repository
*/
$repository = $container->get(ORMInterface::class)->getRepository(Comment::class);
return new CommentService($repository);
},
];