|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* HiAPI Yii2 base project for building API |
|
4
|
|
|
* |
|
5
|
|
|
* @link https://github.com/hiqdev/hiapi |
|
6
|
|
|
* @package hiapi |
|
7
|
|
|
* @license BSD-3-Clause |
|
8
|
|
|
* @copyright Copyright (c) 2017, HiQDev (http://hiqdev.com/) |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
use hiqdev\yii\compat\yii; |
|
12
|
|
|
|
|
13
|
|
|
$app = [ |
|
14
|
|
|
'id' => 'hiapi', |
|
15
|
|
|
'name' => 'HiAPI', |
|
16
|
|
|
'basePath' => dirname(__DIR__) . '/src', |
|
17
|
|
|
'viewPath' => '@hiapi/views', |
|
18
|
|
|
]; |
|
19
|
|
|
|
|
20
|
|
|
$components = [ |
|
21
|
|
|
(yii::is3() ? 'logger' : 'log') => [ |
|
22
|
|
|
'targets' => [ |
|
23
|
|
|
[ |
|
24
|
|
|
'__class' => \yii\log\FileTarget::class, |
|
25
|
|
|
'logFile' => '@runtime/error.log', |
|
26
|
|
|
'levels' => [\Psr\Log\LogLevel::ERROR], |
|
27
|
|
|
'logVars' => [], |
|
28
|
|
|
], |
|
29
|
|
|
], |
|
30
|
|
|
], |
|
31
|
|
|
]; |
|
32
|
|
|
|
|
33
|
|
|
$singletons = [ |
|
34
|
|
|
\yii\web\User::class => [ |
|
35
|
|
|
'identityClass' => \hiapi\models\HiamUserIdentity::class, |
|
36
|
|
|
'enableSession' => false, |
|
37
|
|
|
], |
|
38
|
|
|
/// BUS |
|
39
|
|
|
\hiapi\bus\ApiCommandsBusInterface::class => [ |
|
40
|
|
|
'__class' => \hiapi\bus\ApiCommandsBus::class, |
|
41
|
|
|
'__construct()' => [ |
|
42
|
|
|
yii::referenceTo('bus.the-bus'), |
|
43
|
|
|
], |
|
44
|
|
|
], |
|
45
|
|
|
'bus.per-command-middleware' => [ |
|
46
|
|
|
'__class' => \hiapi\middlewares\PerCommandMiddleware::class, |
|
47
|
|
|
], |
|
48
|
|
|
'bus.default-command-handler' => [ |
|
49
|
|
|
'__class' => \League\Tactician\Handler\CommandHandlerMiddleware::class, |
|
50
|
|
|
'__construct()' => [ |
|
51
|
|
|
yii::referenceTo(\League\Tactician\Handler\CommandNameExtractor\ClassNameExtractor::class), |
|
52
|
|
|
yii::referenceTo(\hiqdev\yii2\autobus\bus\NearbyHandlerLocator::class), |
|
53
|
|
|
yii::referenceTo(\League\Tactician\Handler\MethodNameInflector\HandleInflector::class), |
|
54
|
|
|
], |
|
55
|
|
|
], |
|
56
|
|
|
'bus.the-bus' => [ |
|
57
|
|
|
'__class' => \hiqdev\yii2\autobus\components\TacticianCommandBus::class, |
|
58
|
|
|
'__construct()' => [ |
|
59
|
|
|
yii::referenceTo('bus.default-command-handler'), |
|
60
|
|
|
], |
|
61
|
|
|
'middlewares' => [ |
|
62
|
|
|
'bus.responder-middleware', |
|
63
|
|
|
'bus.handle-exceptions-middleware', |
|
64
|
|
|
'bus.loader-middleware', |
|
65
|
|
|
\hiqdev\yii2\autobus\bus\ValidateMiddleware::class, |
|
66
|
|
|
\hiapi\middlewares\EventEmitterMiddleware::class, |
|
67
|
|
|
'bus.per-command-middleware', |
|
68
|
|
|
], |
|
69
|
|
|
], |
|
70
|
|
|
/// Bus accessories |
|
71
|
|
|
\League\Tactician\Handler\CommandNameExtractor\CommandNameExtractor::class => \League\Tactician\Handler\CommandNameExtractor\ClassNameExtractor::class, |
|
72
|
|
|
\League\Tactician\Handler\Locator\HandlerLocator::class => \hiqdev\yii2\autobus\bus\NearbyHandlerLocator::class, |
|
73
|
|
|
\League\Tactician\Handler\MethodNameInflector\MethodNameInflector::class => \League\Tactician\Handler\MethodNameInflector\HandleInflector::class, |
|
74
|
|
|
/// Event |
|
75
|
|
|
\hiapi\event\EventStorageInterface::class => \hiapi\event\EventStorage::class, |
|
76
|
|
|
\League\Event\EmitterInterface::class => [ |
|
77
|
|
|
'__class' => \hiapi\event\ConfigurableEmitter::class, |
|
78
|
|
|
'listeners' => array_filter([ |
|
79
|
|
|
YII_ENV === 'dev' |
|
80
|
|
|
? ['event' => '*', 'listener' => \hiapi\event\listener\LogEventsListener::class] |
|
81
|
|
|
: null, |
|
82
|
|
|
]), |
|
83
|
|
|
], |
|
84
|
|
|
|
|
85
|
|
|
/// Queue |
|
86
|
|
|
\PhpAmqpLib\Connection\AMQPStreamConnection::class => [ |
|
87
|
|
|
'__class' => \PhpAmqpLib\Connection\AMQPLazyConnection::class, |
|
88
|
|
|
'__construct()' => [ |
|
89
|
|
|
$params['amqp.host'], |
|
90
|
|
|
$params['amqp.port'], |
|
91
|
|
|
$params['amqp.user'], |
|
92
|
|
|
$params['amqp.password'], |
|
93
|
|
|
], |
|
94
|
|
|
], |
|
95
|
|
|
|
|
96
|
|
|
/// General |
|
97
|
|
|
\yii\di\Container::class => function ($container) { |
|
98
|
|
|
return $container; |
|
99
|
|
|
}, |
|
100
|
|
|
\yii\mail\MailerInterface::class => function () { |
|
101
|
|
|
return \hiqdev\yii\compat\yii::getApp()->get('mailer'); |
|
102
|
|
|
}, |
|
103
|
|
|
]; |
|
104
|
|
|
|
|
105
|
|
|
return yii::is3() ? array_merge([ |
|
106
|
|
|
'aliases' => $aliases, |
|
107
|
|
|
'app' => $app, |
|
108
|
|
|
], $components, $singletons) : array_merge([ |
|
109
|
|
|
'bootstrap' => ['log'], |
|
110
|
|
|
'aliases' => $aliases, |
|
111
|
|
|
'components' => $components, |
|
112
|
|
|
'container' => [ |
|
113
|
|
|
'singletons' => $singletons, |
|
114
|
|
|
], |
|
115
|
|
|
'params' => $params, |
|
116
|
|
|
'vendorPath' => '@root/vendor', |
|
117
|
|
|
'runtimePath' => '@root/runtime', |
|
118
|
|
|
], $app); |
|
119
|
|
|
|