Skip to content

Commit 08a06df

Browse files
committed
Merge branch 'master' of github.com:overtrue/laravel-wechat
2 parents 5903772 + 98a337b commit 08a06df

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,7 @@ WECHAT_PAYMENT_SUB_APP_ID
7777
WECHAT_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

src/ServiceProvider.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
66
use EasyWeChat\Foundation\Application;
7+
use Illuminate\Foundation\Application as LaravelApplication;
8+
use Laravel\Lumen\Application as LumenApplication;
79

810
class 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

0 commit comments

Comments
 (0)