diff --git a/composer.json b/composer.json index e13a51d..00bed12 100644 --- a/composer.json +++ b/composer.json @@ -33,5 +33,12 @@ }, "config": { "sort-packages": true + }, + "extra": { + "laravel": { + "providers": [ + "WeWork\\WeWorkServiceProvider" + ] + } } } diff --git a/src/WeWorkServiceProvider.php b/src/WeWorkServiceProvider.php new file mode 100644 index 0000000..4136036 --- /dev/null +++ b/src/WeWorkServiceProvider.php @@ -0,0 +1,70 @@ +publishes( + [ + __DIR__.'/config.php' => config_path('wework.php'), + ] + ); + } + + /** + * Register services. + * + * @return void + */ + public function register() + { + $this->app->singleton( + 'wework', + function ($app, $parameters) { + $wework = array_merge($app['config']['wework'], $parameters); + + $config = array_merge( + $wework['agents'][$wework['default']], + [ + 'corp_id' => $wework['corp_id'], + 'logging' => [ + 'path' => $wework['log']['file'], + 'level' => $wework['log']['level'], + ], + 'cache' => [ + 'path' => $app['config']['cache.stores.file.path'], + ], + ] + ); + + return new App($config); + } + ); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return ['wework']; + } +} diff --git a/src/config.php b/src/config.php new file mode 100644 index 0000000..04fea1d --- /dev/null +++ b/src/config.php @@ -0,0 +1,59 @@ + 'xxxxxxxxxxxxxxxxx', + + /* + |-------------------------------------------------------------------------- + | 默认应用 + |-------------------------------------------------------------------------- + | + | 定义默认使用的应用。 + | + */ + + 'default' => 'contacts', + + /* + |-------------------------------------------------------------------------- + | 应用列表 + |-------------------------------------------------------------------------- + | + | 定义应用列表,如果某个应用的某些配置用不到或者不存在,可以不定义。 + | + */ + + 'agents' => [ + 'contacts' => [ + 'agent_id' => 0, + 'secret' => 'xxxxxxxxxxxxxxxxx', + 'token' => 'xxxxxxxxxxxxxxxxx', + 'aes_key' => 'xxxxxxxxxxxxxxxxx', + ], + + //... + ], + + /* + |-------------------------------------------------------------------------- + | 日志 + |-------------------------------------------------------------------------- + | + | 定义日志级别和存储位置。 + | + */ + + 'log' => [ + 'level' => env('WEWORK_LOG_LEVEL', 'debug'), + 'file' => storage_path('logs/wework.log'), + ], +];