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

增加 OneBotBuilder #45

Merged
merged 6 commits into from
Feb 12, 2022
Merged

增加 OneBotBuilder #45

merged 6 commits into from
Feb 12, 2022

Conversation

sunxyw
Copy link
Collaborator

@sunxyw sunxyw commented Feb 10, 2022

  • 给 ConfigInterface 加上了 set
  • 增加 OneBotBuilder

例子:
demo.php

@sunxyw sunxyw added area/function 关于功能 kind/feature 这是个功能/特性 labels Feb 10, 2022
@sunxyw sunxyw changed the base branch from master to develop February 10, 2022 14:12
@sunxyw sunxyw requested a review from crazywhalecc February 10, 2022 14:13
@github-actions github-actions bot added the status/wait-for-review 需要Review label Feb 10, 2022
@crazywhalecc
Copy link
Member

crazywhalecc commented Feb 11, 2022

对于开发者引入此库进行编写时,我觉得倒是 OneBotBuilder 也不是不可,但是 OneBotBuilder 后返回的对象却是 OneBot 总感觉哪里不太对劲,OneBot 好像被架空了(因为目前的写法看起来是不允许使用构造函数创建 OneBot)。

按理说 OneBot 对象的作用就是 OneBot 实现的核心类,而如果使用 OneBotBuilder,应该感觉类似于做 HttpFactory 的 createServerRequest($uri, $header, ...) 类似的工厂函数,但直接创建的类也应该是可以使用才对(或者是可被继承的)。

@sunxyw
Copy link
Collaborator Author

sunxyw commented Feb 11, 2022

OneBot 依然是核心类呀,使用 OneBotBuilder 构建 OneBot 和 new OneBot 本质上没有区别,只是中间多了一层转换,用于解析 logger 和 driver,OneBotBuilder::buildFromConfig 和 new OneBot($config) 的作用是完全一样的。


直接创建的类也应该是可以使用才对(或者是可被继承的)。

目前 OneBot 是可以直接使用的呀,如果不喜欢 OneBotBuilder 的话可以直接 new OneBot($config),只是传入的 config 中的 logger 和 driver 必须是实例而已。

@crazywhalecc
Copy link
Member

OneBot 依然是核心类呀,使用 OneBotBuilder 构建 OneBot 和 new OneBot 本质上没有区别,只是中间多了一层转换,用于解析 logger 和 driver,OneBotBuilder::buildFromConfig 和 new OneBot($config) 的作用是完全一样的。

直接创建的类也应该是可以使用才对(或者是可被继承的)。

目前 OneBot 是可以直接使用的呀,如果不喜欢 OneBotBuilder 的话可以直接 new OneBot($config),只是传入的 config 中的 logger 和 driver 必须是实例而已。

但 OneBot 实例的构造函数不应该是 private 呀:

PHP Error:  Call to private OneBot\V12\OneBot::__construct() from invalid context

@sunxyw
Copy link
Collaborator Author

sunxyw commented Feb 11, 2022

阿这,为什么是 private 😨

@sunxyw
Copy link
Collaborator Author

sunxyw commented Feb 11, 2022

知道了,昨晚写嗨了,发现 getInstance 有初始化的功能之后就非常自信地把new给去了。

@crazywhalecc
Copy link
Member

还有驼峰命名是否有问题呢,OneBot 使用的都是下划线,但 Builder 中使用的是驼峰。

@crazywhalecc
Copy link
Member

'selfId' => $this->components['selfId'],

我其实是说的这里的驼峰🤔

@sunxyw
Copy link
Collaborator Author

sunxyw commented Feb 11, 2022

'selfId' => $this->components['selfId'],

我其实是说的这里的驼峰🤔

自动生成的,没留意看 🤣

src/OneBot/V12/OneBot.php Outdated Show resolved Hide resolved
src/OneBot/V12/OneBot.php Show resolved Hide resolved
src/OneBot/V12/OneBotBuilder.php Outdated Show resolved Hide resolved
src/OneBot/V12/OneBotBuilder.php Show resolved Hide resolved
@github-actions github-actions bot added lifecycle/ready-for-merge 请合并此PR and removed status/wait-for-review 需要Review labels Feb 11, 2022
@crazywhalecc crazywhalecc added blocked/require-test 需要进行测试 lifecycle/ready-for-merge 请合并此PR and removed lifecycle/ready-for-merge 请合并此PR blocked/require-test 需要进行测试 labels Feb 11, 2022
@sunxyw sunxyw merged commit 45faf96 into develop Feb 12, 2022
@sunxyw sunxyw deleted the feature/onebot-builder branch February 12, 2022 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/function 关于功能 kind/feature 这是个功能/特性 lifecycle/ready-for-merge 请合并此PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants