New plugin API: pushMiddleware

This commit is contained in:
Pig Fang 2019-07-03 19:33:08 +08:00
parent a94b526179
commit 2f08a7db37
4 changed files with 20 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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

View File

@ -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)
## 调整

View File

@ -103,4 +103,17 @@ class HookTest extends TestCase
->assertSee('<span class="label label-warning notifications-counter">1</span>')
->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');
}
}