Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

重构配置 #40

Merged
merged 4 commits into from
Feb 5, 2022
Merged

重构配置 #40

merged 4 commits into from
Feb 5, 2022

Conversation

sunxyw
Copy link
Collaborator

@sunxyw sunxyw commented Feb 5, 2022

允许用户直接传入配置数组,不关注配置来源。
根据数组中定义的配置进行初始化。

配置数组样例:

$config = [
    'name' => 'repl',

    'platform' => 'qq',

    'self_id' => 'REPL-1',

    'db' => true,

    'logger' => [
        'class' => \OneBot\Logger\Console\ConsoleLogger::class,
        'level' => 'debug',
    ],

    'driver' => [
        'class' => \OneBot\Driver\SwooleDriver::class,
        'config' => [],
    ],

    'communications' => [
        [
            'type' => 'http',
            'host' => '127.0.0.1',
            'port' => 2345,
            'access_token' => '',
            'event_enabled' => true,
            'event_buffer_size' => 100,
        ],
        [
            'type' => 'webhook',
            'url' => '',
            'access_token' => '',
            'timeout' => 5,
        ],
        [
            'type' => 'websocket_reverse',
            'url' => '',
            'access_token' => '',
            'reconnect_interval' => 5,
        ],
    ],
];

代码:

$ob = new OneBot(new Config($config));
$ob->setActionHandler(ReplAction::class);
$ob->run();

合并后可以移除 hassankhan/config lezhnev74/pasvl 依赖。

BREAKING CHANGE: substantially overhauled existing config
@sunxyw sunxyw requested a review from crazywhalecc February 5, 2022 11:32
@github-actions github-actions bot added the status/wait-for-review 需要Review label Feb 5, 2022
@sunxyw sunxyw added area/dependency 关于依赖 area/function 关于功能 kind/feature 这是个功能/特性 status/wait-for-review 需要Review and removed status/wait-for-review 需要Review labels Feb 5, 2022
Copy link
Member

@crazywhalecc crazywhalecc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目前看起来这样的改动下就是相当于配置文件只要是变成那个数组就好了,无论是用 .php 还是 .json。那这样还有需要使用验证组件的地方吗?

BTW,这样进行配置确实更好,更像个 Library 而不是 Project 了😂

@sunxyw
Copy link
Collaborator Author

sunxyw commented Feb 5, 2022 via email

@github-actions github-actions bot added lifecycle/ready-for-merge 请合并此PR and removed status/wait-for-review 需要Review labels Feb 5, 2022
@sunxyw sunxyw merged commit 2fcdaf8 into develop Feb 5, 2022
@sunxyw sunxyw deleted the feature/refactor-config branch February 5, 2022 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/dependency 关于依赖 area/function 关于功能 kind/feature 这是个功能/特性 lifecycle/ready-for-merge 请合并此PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants