File tree Expand file tree Collapse file tree 2 files changed +21
-12
lines changed Expand file tree Collapse file tree 2 files changed +21
-12
lines changed Original file line number Diff line number Diff line change @@ -77,11 +77,7 @@ WECHAT_PAYMENT_SUB_APP_ID
7777WECHAT_PAYMENT_SUB_MERCHANT_ID
7878```
7979
80- 3 . 如果你习惯使用 ` config/wechat.php ` 来配置的话,请记得在 ` bootstrap/app.php ` 中19行以后添加:
81-
82- ``` php
83- $app->configure('wechat');
84- ```
80+ 3 . 如果你习惯使用 ` config/wechat.php ` 来配置的话,将 ` vendor/overtrue/laravel-wechat/src/config.php ` 拷贝到` app/config ` 目录下,并将文件名改成` wechat.php ` 。
8581
8682## 使用
8783
Original file line number Diff line number Diff line change 44
55use Illuminate \Support \ServiceProvider as LaravelServiceProvider ;
66use EasyWeChat \Foundation \Application ;
7+ use Illuminate \Foundation \Application as LaravelApplication ;
8+ use Laravel \Lumen \Application as LumenApplication ;
79
810class ServiceProvider extends LaravelServiceProvider
911{
@@ -21,11 +23,26 @@ class ServiceProvider extends LaravelServiceProvider
2123 */
2224 public function boot ()
2325 {
24- if (function_exists ('config_path ' )) {
26+ $ this ->setupConfig ();
27+ }
28+
29+ /**
30+ * Setup the config.
31+ *
32+ * @return void
33+ */
34+ protected function setupConfig ()
35+ {
36+ $ source = realpath (__DIR__ . '/config.php ' );
37+
38+ if ($ this ->app instanceof LaravelApplication && $ this ->app ->runningInConsole ()) {
2539 $ this ->publishes ([
26- __DIR__ . '/config.php ' => config_path ('wechat.php ' ),
27- ], 'config ' );
40+ $ source => config_path ('wechat.php ' )
41+ ]);
42+ } elseif ($ this ->app instanceof LumenApplication) {
43+ $ this ->app ->configure ('wechat ' );
2844 }
45+ $ this ->mergeConfigFrom ($ source , 'wechat ' );
2946 }
3047
3148 /**
@@ -35,10 +52,6 @@ public function boot()
3552 */
3653 public function register ()
3754 {
38- $ this ->mergeConfigFrom (
39- __DIR__ .'/config.php ' , 'wechat '
40- );
41-
4255 $ this ->app ->singleton (['EasyWeChat \\Foundation \\Application ' => 'wechat ' ], function ($ app ){
4356 $ app = new Application (config ('wechat ' ));
4457
You can’t perform that action at this time.
0 commit comments