Skip to content

Commit

Permalink
集成 Laravel
Browse files Browse the repository at this point in the history
  • Loading branch information
pithyone committed Sep 6, 2018
1 parent 163a762 commit 5455827
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 0 deletions.
7 changes: 7 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,12 @@
},
"config": {
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"WeWork\\WeWorkServiceProvider"
]
}
}
}
70 changes: 70 additions & 0 deletions src/WeWorkServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace WeWork;

use Illuminate\Support\ServiceProvider;

class WeWorkServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;

/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
$this->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'];
}
}
59 changes: 59 additions & 0 deletions src/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

return [
/*
|--------------------------------------------------------------------------
| 企业ID
|--------------------------------------------------------------------------
|
| 每个企业都拥有唯一的corpid,获取此信息可在管理后台“我的企业”-“企业信息”下查看“企业ID”(需要有管理员权限)。
|
*/

'corp_id' => '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'),
],
];

0 comments on commit 5455827

Please sign in to comment.