$builder = new ContainerBuilder();
$definitions = [
ServiceIds::TRANSPORT_SYNC => static function (ContainerInterface $container) {
return new SyncTransport($container->get(ServiceIds::SYNC_BUS));
},
ServiceIds::TRANSPORT_ACTIVITY => new InMemoryTransport(),
ServiceIds::TRANSPORT_WORKFLOW => new InMemoryTransport(),
EventDispatcherInterface::class => new EventDispatcher(),
WorkflowRepositoryInterface::class => new WorkflowRepository(),
ActivityRepositoryInterface::class => new ActivityRepository(),
ServiceIds::SYNC_BUS => factory(
static function (ContainerInterface $container): MessageBus {
return new MessageBus(
[
new HandleMessageMiddleware(
new HandlersLocator(
[
NotifyToMattermostMessage1::class => [new NotifyToMattermostMessageHandler1()],
ActivityMessage::class => [
$container->get(ActivityMessageHandler::class)
],
WorkflowMessage::class => [
new WorkflowMessageHandler(
$container->get(WorkflowRepositoryInterface::class),
$container->get(EventDispatcherInterface::class),
$container->get(ActivityRepositoryInterface::class),
$container->get(ServiceIds::ACTIVITY_BUS),
),
]
]
)
),
]
);
}
),
ServiceIds::WORKFLOW_BUS => factory(
static function (ContainerInterface $container): MessageBus {
return new MessageBus(
[
new SendMessageMiddleware(
new SendersLocator(
[
WorkflowMessage::class => [ServiceIds::TRANSPORT_WORKFLOW]
],
$container
),
$container->get(EventDispatcherInterface::class)
),
new HandleMessageMiddleware(
new HandlersLocator(
[
WorkflowMessage::class => [
new WorkflowMessageHandler(
$container->get(WorkflowRepositoryInterface::class),
$container->get(EventDispatcherInterface::class),
$container->get(ActivityRepositoryInterface::class),
$container->get(ServiceIds::ACTIVITY_BUS),
),
],
]
)
),
]
);
}
),
ServiceIds::ACTIVITY_BUS => factory(
static function (ContainerInterface $container): MessageBus {
return new MessageBus(
[
new SendMessageMiddleware(
new SendersLocator(
[
ActivityMessage::class => [ServiceIds::TRANSPORT_ACTIVITY]
],
$container
),
$container->get(EventDispatcherInterface::class)
),
new HandleMessageMiddleware(
new HandlersLocator(
[
ActivityMessage::class => [
$container->get(ActivityMessageHandler::class)
],
]
)
),
]
);
}
),
ActivityMessageHandler::class => \DI\create(ActivityMessageHandler::class)
->constructor(
get(ActivityRepositoryInterface::class),
get(EventDispatcherInterface::class),
get(ServiceIds::WORKFLOW_BUS),
get(ServiceIds::SYNC_BUS),
)
->lazy(),
WorkflowService::class => factory(
static function (ContainerInterface $container): WorkflowService {
return new WorkflowService(
$container->get(WorkflowRepositoryInterface::class),
$container->get(ServiceIds::WORKFLOW_BUS)
);
}
),
];
$builder->addDefinitions($definitions);
$container = $builder->build();
try {
/*
* This is basically equivalent to $app->run() without sending the response.
* Sending the response is problematic because it tries to send headers.
*/
$app->trigger($app::EVENT_BEFORE_REQUEST);
$response = $app->handleRequest($yiiRequest);
$app->trigger($app::EVENT_AFTER_REQUEST);
$response->send();
} catch (\Exception $e) {
if ($e instanceof HttpException) {
// Don't discard output and pass exception handling to Yii to be able
// to expect error response codes in tests.
$app->errorHandler->discardExistingOutput = false;
$app->errorHandler->handleException($e);
} elseif (!$e instanceof ExitException) {
// for exceptions not related to Http, we pass them to Codeception
throw $e;
}
$response = $app->response;
}