Skip to content

Commit bfaac51

Browse files
Merge pull request #36343 from nextcloud/feat/app-framework/middleware-argument-types
feat(app-framework): Add native argument types for middleware
2 parents b6d9e1d + 2c0cfd3 commit bfaac51

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

lib/public/AppFramework/Middleware.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626
namespace OCP\AppFramework;
2727

28+
use Exception;
2829
use OCP\AppFramework\Http\Response;
2930

3031
/**
@@ -45,7 +46,7 @@ abstract class Middleware {
4546
* @return void
4647
* @since 6.0.0
4748
*/
48-
public function beforeController($controller, $methodName) {
49+
public function beforeController(Controller $controller, string $methodName) {
4950
}
5051

5152

@@ -59,12 +60,12 @@ public function beforeController($controller, $methodName) {
5960
* @param Controller $controller the controller that is being called
6061
* @param string $methodName the name of the method that will be called on
6162
* the controller
62-
* @param \Exception $exception the thrown exception
63-
* @throws \Exception the passed in exception if it can't handle it
63+
* @param Exception $exception the thrown exception
64+
* @throws Exception the passed in exception if it can't handle it
6465
* @return Response a Response object in case that the exception was handled
6566
* @since 6.0.0
6667
*/
67-
public function afterException($controller, $methodName, \Exception $exception) {
68+
public function afterException(Controller $controller, string $methodName, Exception $exception) {
6869
throw $exception;
6970
}
7071

@@ -80,7 +81,7 @@ public function afterException($controller, $methodName, \Exception $exception)
8081
* @return Response a Response object
8182
* @since 6.0.0
8283
*/
83-
public function afterController($controller, $methodName, Response $response) {
84+
public function afterController(Controller $controller, string $methodName, Response $response) {
8485
return $response;
8586
}
8687

@@ -96,7 +97,7 @@ public function afterController($controller, $methodName, Response $response) {
9697
* @return string the output that should be printed
9798
* @since 6.0.0
9899
*/
99-
public function beforeOutput($controller, $methodName, $output) {
100+
public function beforeOutput(Controller $controller, string $methodName, string $output) {
100101
return $output;
101102
}
102103
}

tests/lib/AppFramework/Middleware/MiddlewareTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,27 @@ protected function setUp(): void {
7070
}
7171

7272

73-
public function testBeforeController() {
74-
$this->middleware->beforeController($this->controller, null);
73+
public function testBeforeController(): void {
74+
$this->middleware->beforeController($this->controller, '');
7575
$this->assertNull(null);
7676
}
7777

7878

79-
public function testAfterExceptionRaiseAgainWhenUnhandled() {
79+
public function testAfterExceptionRaiseAgainWhenUnhandled(): void {
8080
$this->expectException(\Exception::class);
81-
$this->middleware->afterException($this->controller, null, $this->exception);
81+
$this->middleware->afterException($this->controller, '', $this->exception);
8282
}
8383

8484

85-
public function testAfterControllerReturnResponseWhenUnhandled() {
86-
$response = $this->middleware->afterController($this->controller, null, $this->response);
85+
public function testAfterControllerReturnResponseWhenUnhandled(): void {
86+
$response = $this->middleware->afterController($this->controller, '', $this->response);
8787

8888
$this->assertEquals($this->response, $response);
8989
}
9090

9191

92-
public function testBeforeOutputReturnOutputhenUnhandled() {
93-
$output = $this->middleware->beforeOutput($this->controller, null, 'test');
92+
public function testBeforeOutputReturnOutputhenUnhandled(): void {
93+
$output = $this->middleware->beforeOutput($this->controller, '', 'test');
9494

9595
$this->assertEquals('test', $output);
9696
}

0 commit comments

Comments
 (0)