mirror of
https://github.com/nextcloud/server.git
synced 2026-04-21 14:23:17 -04:00
feat(app-framework): Add native argument types for middleware
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
parent
b6d9e1d1cc
commit
2c0cfd3772
2 changed files with 15 additions and 14 deletions
|
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
namespace OCP\AppFramework;
|
||||
|
||||
use Exception;
|
||||
use OCP\AppFramework\Http\Response;
|
||||
|
||||
/**
|
||||
|
|
@ -45,7 +46,7 @@ abstract class Middleware {
|
|||
* @return void
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public function beforeController($controller, $methodName) {
|
||||
public function beforeController(Controller $controller, string $methodName) {
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -59,12 +60,12 @@ abstract class Middleware {
|
|||
* @param Controller $controller the controller that is being called
|
||||
* @param string $methodName the name of the method that will be called on
|
||||
* the controller
|
||||
* @param \Exception $exception the thrown exception
|
||||
* @throws \Exception the passed in exception if it can't handle it
|
||||
* @param Exception $exception the thrown exception
|
||||
* @throws Exception the passed in exception if it can't handle it
|
||||
* @return Response a Response object in case that the exception was handled
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public function afterException($controller, $methodName, \Exception $exception) {
|
||||
public function afterException(Controller $controller, string $methodName, Exception $exception) {
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
|
|
@ -80,7 +81,7 @@ abstract class Middleware {
|
|||
* @return Response a Response object
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public function afterController($controller, $methodName, Response $response) {
|
||||
public function afterController(Controller $controller, string $methodName, Response $response) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +97,7 @@ abstract class Middleware {
|
|||
* @return string the output that should be printed
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public function beforeOutput($controller, $methodName, $output) {
|
||||
public function beforeOutput(Controller $controller, string $methodName, string $output) {
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,27 +70,27 @@ class MiddlewareTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
|
||||
public function testBeforeController() {
|
||||
$this->middleware->beforeController($this->controller, null);
|
||||
public function testBeforeController(): void {
|
||||
$this->middleware->beforeController($this->controller, '');
|
||||
$this->assertNull(null);
|
||||
}
|
||||
|
||||
|
||||
public function testAfterExceptionRaiseAgainWhenUnhandled() {
|
||||
public function testAfterExceptionRaiseAgainWhenUnhandled(): void {
|
||||
$this->expectException(\Exception::class);
|
||||
$this->middleware->afterException($this->controller, null, $this->exception);
|
||||
$this->middleware->afterException($this->controller, '', $this->exception);
|
||||
}
|
||||
|
||||
|
||||
public function testAfterControllerReturnResponseWhenUnhandled() {
|
||||
$response = $this->middleware->afterController($this->controller, null, $this->response);
|
||||
public function testAfterControllerReturnResponseWhenUnhandled(): void {
|
||||
$response = $this->middleware->afterController($this->controller, '', $this->response);
|
||||
|
||||
$this->assertEquals($this->response, $response);
|
||||
}
|
||||
|
||||
|
||||
public function testBeforeOutputReturnOutputhenUnhandled() {
|
||||
$output = $this->middleware->beforeOutput($this->controller, null, 'test');
|
||||
public function testBeforeOutputReturnOutputhenUnhandled(): void {
|
||||
$output = $this->middleware->beforeOutput($this->controller, '', 'test');
|
||||
|
||||
$this->assertEquals('test', $output);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue