Skip to content

Commit

Permalink
Merge pull request #37 from peiit/master
Browse files Browse the repository at this point in the history
优化lumen配置调用
  • Loading branch information
overtrue authored Jul 25, 2016
2 parents 5085da8 + ffc362d commit 98a337b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@ WECHAT_PAYMENT_SUB_APP_ID
WECHAT_PAYMENT_SUB_MERCHANT_ID
```

3. 如果你习惯使用 `config/wechat.php` 来配置的话,请记得在 `bootstrap/app.php` 中19行以后添加:

```php
$app->configure('wechat');
```
3. 如果你习惯使用 `config/wechat.php` 来配置的话,将 `vendor/overtrue/laravel-wechat/src/config.php` 拷贝到`app/config`目录下,并将文件名改成`wechat.php`

## 使用

Expand Down
27 changes: 20 additions & 7 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
use EasyWeChat\Foundation\Application;
use Illuminate\Foundation\Application as LaravelApplication;
use Laravel\Lumen\Application as LumenApplication;

class ServiceProvider extends LaravelServiceProvider
{
Expand All @@ -21,11 +23,26 @@ class ServiceProvider extends LaravelServiceProvider
*/
public function boot()
{
if (function_exists('config_path')) {
$this->setupConfig();
}

/**
* Setup the config.
*
* @return void
*/
protected function setupConfig()
{
$source = realpath(__DIR__ . '/config.php');

if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) {
$this->publishes([
__DIR__ . '/config.php' => config_path('wechat.php'),
], 'config');
$source => config_path('wechat.php')
]);
} elseif ($this->app instanceof LumenApplication) {
$this->app->configure('wechat');
}
$this->mergeConfigFrom($source, 'wechat');
}

/**
Expand All @@ -35,10 +52,6 @@ public function boot()
*/
public function register()
{
$this->mergeConfigFrom(
__DIR__.'/config.php', 'wechat'
);

$this->app->singleton(['EasyWeChat\\Foundation\\Application' => 'wechat'], function($app){
$app = new Application(config('wechat'));

Expand Down

0 comments on commit 98a337b

Please sign in to comment.