From e902d1f4a0ef547c17031cfd9228605a815c7d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=80=99=E5=AD=A6=E6=9D=B0?= Date: Mon, 19 Mar 2018 11:15:37 +0800 Subject: [PATCH] config --- README.md | 20 +++++++++++++++++++- src/PdAuth/PdAuthServiceProvider.php | 13 +++++++++++++ src/config/pdauth.php | 7 +++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/config/pdauth.php diff --git a/README.md b/README.md index 23286de..15faeb0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # Auth 系统 PHP Client -## 如何使用 > 该项目使用 composer 来完成加载,需要对项目的 ``` composer.json ``` 中增加如下配置手动制定仓库的地址(因为仓库为公司内部私有的,不对外开放) @@ -16,5 +15,24 @@ ``` +执行 +```bash +composer require arch/php-auth-client +``` +### 代码中启用 + +注册中间件 +```PHP +$app->routeMiddleware([ + 'auth' => PdAuth\Middleware\Authenticate::class, +]); +``` +注册 +```PHP +$app->register(PdAuth\PdAuthServiceProvider::class); +``` + +### 配置 + diff --git a/src/PdAuth/PdAuthServiceProvider.php b/src/PdAuth/PdAuthServiceProvider.php index dfbb79f..35166ef 100644 --- a/src/PdAuth/PdAuthServiceProvider.php +++ b/src/PdAuth/PdAuthServiceProvider.php @@ -40,6 +40,19 @@ class PdAuthServiceProvider extends ServiceProvider }); } + protected function setupConfig() + { + $source = realpath(__DIR__ . '/../config.php'); + + if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) { + $this->publishes([$source => config_path('pdauth.php')], 'pdauth'); + } elseif ($this->app instanceof LumenApplication) { + $this->app->configure('pdauth'); + } + + $this->mergeConfigFrom($source, 'pdauth'); + } + public function register() { $this->app->singleton('pd.auth', function () { diff --git a/src/config/pdauth.php b/src/config/pdauth.php new file mode 100644 index 0000000..8ed7d3e --- /dev/null +++ b/src/config/pdauth.php @@ -0,0 +1,7 @@ + env('PDAUTH_APP_ID', '100002'), + 'secret' => env('PDAUTH_SECRET', '123456'), + 'host' => env('PDAUTH_HOST', 'http://auth.dev.haowumc.com'), +]; \ No newline at end of file