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

使用Composer实现类似观察者模式的插件机制。 #719

Closed
wants to merge 5 commits into from
Closed

使用Composer实现类似观察者模式的插件机制。 #719

wants to merge 5 commits into from

Conversation

xutl
Copy link
Contributor

@xutl xutl commented Jun 3, 2017

在命名空间 EasyWeChat\Foundation下增加 BootstrapInterface 接口,实现 bootstrap($app),方法,在程序初始化阶段,提供了一个注入点,使第三方插件,或者是消息处理程序能自动注射到应用程序实例中,从而自动响应微信回调等各种接口的消息。
示例插件在 https://github.com/xutl/wechat-test
其中关键点 composer.json 文件的 type 标记包类型为 wechat-extension,此时 https://github.com/xutl/wechat-composer插件会自动在 vendor\overtrue\extensions.php生成一个数组,标记该插件的基本信息。并且在'composer.json' 的

"extra": {
    "bootstrap": "xutl\\test\\Bootstrap"
  }

标记在程序启动阶段注入以上类的实例,从而实现了插件机制。
其中'xutl/wechat-composer',移植自 自yii2的 composer插件,版权归原作者所有,开源协议是 BSD-3-Clause.
如需使用需要在配置中增加一个vendor设置。

include __DIR__ . '/vendor/autoload.php'; // 引入 composer 入口文件
use EasyWeChat\Foundation\Application;
$options = [
    'vendor' => __DIR__ . '/vendor',
   // ...
];
$app = new Application($options);

如果不增加 vendor字段设置,将不生效。

@overtrue
Copy link
Collaborator

overtrue commented Jun 3, 2017

感谢!这个 feature 不打算在 3.0 加入了,而且这个设计感觉还需要优化一下,等我 4.0 的时候搞定吧。

@overtrue overtrue added this to the 4.0 milestone Jun 3, 2017
@xutl
Copy link
Contributor Author

xutl commented Jun 9, 2017

@overtrue 给我拉倒开发群里呗

@overtrue
Copy link
Collaborator

overtrue commented Jun 9, 2017

@xutl 319502940

@overtrue
Copy link
Collaborator

overtrue commented Dec 8, 2017

Added at commit #1027

@overtrue overtrue closed this Dec 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants