From 2f08a7db37db2992b97804e4fe97317a0f112a56 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Wed, 3 Jul 2019 19:33:08 +0800 Subject: [PATCH] New plugin API: `pushMiddleware` --- app/Services/Hook.php | 5 +++++ resources/misc/changelogs/en/4.3.0.md | 1 + resources/misc/changelogs/zh_CN/4.3.0.md | 1 + tests/ServicesTest/HookTest.php | 13 +++++++++++++ 4 files changed, 20 insertions(+) diff --git a/app/Services/Hook.php b/app/Services/Hook.php index 998bdb6c..3cdb24cc 100644 --- a/app/Services/Hook.php +++ b/app/Services/Hook.php @@ -133,4 +133,9 @@ class Hook { Notification::send($users, new Notifications\SiteMessage($title, $content)); } + + public static function pushMiddleware($middleware) + { + app()->make('Illuminate\Contracts\Http\Kernel')->pushMiddleware($middleware); + } } diff --git a/resources/misc/changelogs/en/4.3.0.md b/resources/misc/changelogs/en/4.3.0.md index 2ea3c5a6..5540dafd 100644 --- a/resources/misc/changelogs/en/4.3.0.md +++ b/resources/misc/changelogs/en/4.3.0.md @@ -8,6 +8,7 @@ - New plugin API: [`Hook::addUserBadge`](https://bs-plugin.netlify.com/guide/bootstrap.html#%E6%98%BE%E7%A4%BA%E7%94%A8%E6%88%B7-badge). - New feature: Notifications. - New plugin API: [`Hook::sendNotification`](https://bs-plugin.netlify.com/guide/bootstrap.html#%E5%8F%91%E9%80%81%E9%80%9A%E7%9F%A5) +- New plugin API: [`Hook::pushMiddleware`](https://bs-plugin.netlify.com/guide/bootstrap.html#%E6%B3%A8%E5%86%8C%E4%B8%AD%E9%97%B4%E4%BB%B6) ## Tweaked diff --git a/resources/misc/changelogs/zh_CN/4.3.0.md b/resources/misc/changelogs/zh_CN/4.3.0.md index 0212da88..33e44dd7 100644 --- a/resources/misc/changelogs/zh_CN/4.3.0.md +++ b/resources/misc/changelogs/zh_CN/4.3.0.md @@ -8,6 +8,7 @@ - 新插件 API:[`Hook::addUserBadge`](https://bs-plugin.netlify.com/guide/bootstrap.html#%E6%98%BE%E7%A4%BA%E7%94%A8%E6%88%B7-badge) - 新功能:发送通知。 - 新插件 API:[`Hook::sendNotification`](https://bs-plugin.netlify.com/guide/bootstrap.html#%E5%8F%91%E9%80%81%E9%80%9A%E7%9F%A5) +- 新插件 API:[`Hook::pushMiddleware`](https://bs-plugin.netlify.com/guide/bootstrap.html#%E6%B3%A8%E5%86%8C%E4%B8%AD%E9%97%B4%E4%BB%B6) ## 调整 diff --git a/tests/ServicesTest/HookTest.php b/tests/ServicesTest/HookTest.php index 02fbd91f..e5d16920 100644 --- a/tests/ServicesTest/HookTest.php +++ b/tests/ServicesTest/HookTest.php @@ -103,4 +103,17 @@ class HookTest extends TestCase ->assertSee('1') ->assertSee('Ibara Mayaka'); } + + public function testPushMiddleware() + { + Hook::pushMiddleware(get_class(new class { + public function handle($request, $next) + { + $response = $next($request); + $response->header('X-Middleware-Test', 'value'); + return $response; + } + })); + $this->get('/')->assertHeader('X-Middleware-Test'); + } }