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 yii\di\Instance; |
12
|
|
|
|
13
|
|
|
return [ |
14
|
|
|
'id' => 'hiapi', |
15
|
|
|
'name' => 'HiAPI', |
16
|
|
|
'basePath' => dirname(__DIR__) . '/src', |
17
|
|
|
|
18
|
|
|
/// aliases must be set before their use |
19
|
|
|
'aliases' => $aliases, |
20
|
|
|
'viewPath' => '@hiapi/views', |
21
|
|
|
'vendorPath' => '@root/vendor', |
22
|
|
|
'runtimePath' => '@root/runtime', |
23
|
|
|
|
24
|
|
|
'logger' => [ |
25
|
|
|
'__class' => \yii\log\Logger::class |
26
|
|
|
], |
27
|
|
|
'components' => [ |
28
|
|
|
'user' => [ |
29
|
|
|
'__class' => \yii\web\User::class, |
30
|
|
|
], |
31
|
|
|
], |
32
|
|
|
'container' => [ |
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
|
|
|
0 => Instance::of('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
|
|
|
Instance::of(\League\Tactician\Handler\CommandNameExtractor\ClassNameExtractor::class), |
52
|
|
|
Instance::of(\hiqdev\yii2\autobus\bus\NearbyHandlerLocator::class), |
53
|
|
|
Instance::of(\League\Tactician\Handler\MethodNameInflector\HandleInflector::class), |
54
|
|
|
], |
55
|
|
|
], |
56
|
|
|
'bus.the-bus' => [ |
57
|
|
|
'__class' => \hiqdev\yii2\autobus\components\TacticianCommandBus::class, |
58
|
|
|
'__construct()' => [ |
59
|
|
|
Instance::of('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
|
|
|
\Psr\Container\ContainerInterface::class => function ($container) { |
101
|
|
|
return new class($container) implements \Psr\Container\ContainerInterface { |
102
|
|
|
/** |
103
|
|
|
* @var \yii\di\Container |
104
|
|
|
*/ |
105
|
|
|
private $yiiContainer; |
106
|
|
|
|
107
|
|
|
public function __construct(\yii\di\Container $yiiContainer) |
108
|
|
|
{ |
109
|
|
|
$this->yiiContainer = $yiiContainer; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function get($id) |
113
|
|
|
{ |
114
|
|
|
return $this->yiiContainer->get($id); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function has($id) |
118
|
|
|
{ |
119
|
|
|
return $this->yiiContainer->has($id); |
120
|
|
|
} |
121
|
|
|
}; |
122
|
|
|
}, |
123
|
|
|
\yii\base\Application::class => function () { |
124
|
|
|
return Yii::$app; |
125
|
|
|
}, |
126
|
|
|
\yii\mail\MailerInterface::class => function () { |
127
|
|
|
return Yii::$app->get('mailer'); |
128
|
|
|
}, |
129
|
|
|
\Psr\Log\LoggerInterface::class => function () { |
130
|
|
|
return Yii::getLogger(); |
131
|
|
|
} |
132
|
|
|
], |
133
|
|
|
], |
134
|
|
|
'params' => $params, |
135
|
|
|
]; |
136
|
|
|
|