mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-21 15:45:36 +08:00
refactor container injection
This commit is contained in:
@@ -54,11 +54,7 @@ class OnWorkerStart implements SwooleEvent
|
||||
}
|
||||
unset(Context::$context[Coroutine::getCid()]);
|
||||
|
||||
/* @noinspection PhpExpressionResultUnusedInspection */
|
||||
new WorkerContainer();
|
||||
if (Console::getLevel() >= 4) {
|
||||
Console::debug(sprintf('Worker container [id=%d,cid=%d] booted', $worker_id, Coroutine::getCid()));
|
||||
}
|
||||
$this->registerWorkerContainerBindings($server);
|
||||
|
||||
if ($server->taskworker === false) {
|
||||
Framework::saveProcessState(ZM_PROCESS_WORKER, $server->worker_pid, ['worker_id' => $worker_id]);
|
||||
@@ -292,4 +288,24 @@ class OnWorkerStart implements SwooleEvent
|
||||
DB::initTableList($real_conf['dbname']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册进程容器绑定
|
||||
*/
|
||||
private function registerWorkerContainerBindings(Server $server): void
|
||||
{
|
||||
$container = WorkerContainer::getInstance();
|
||||
$container->setLogPrefix("[WorkerContainer#{$server->worker_id}]");
|
||||
// 路径
|
||||
$container->instance('path.working', DataProvider::getWorkingDir());
|
||||
$container->instance('path.source', DataProvider::getSourceRootDir());
|
||||
$container->alias('path.source', 'path.base');
|
||||
$container->instance('path.config', DataProvider::getSourceRootDir() . '/config');
|
||||
$container->instance('path.module_config', ZMConfig::get('global', 'config_dir'));
|
||||
$container->instance('path.data', DataProvider::getDataFolder());
|
||||
$container->instance('path.framework', DataProvider::getFrameworkRootDir());
|
||||
// 基础
|
||||
$container->instance('server', $server);
|
||||
$container->instance('worker_id', $server->worker_id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user