summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2018-02-21 13:57:04 +0100
committerGitHub <noreply@github.com>2018-02-21 13:57:04 +0100
commit4b50fe7560444f4c42ba04ea4a034119af907db1 (patch)
tree496b00d577abbb8652f489743753a5598b6d83b9 /lib/private
parent8b44c16ddc8f6b73aaa61d205be956024e6de195 (diff)
parent5825c27a120dbcf9c1fae80393b410c66696f9ed (diff)
downloadnextcloud-server-4b50fe7560444f4c42ba04ea4a034119af907db1.tar.gz
nextcloud-server-4b50fe7560444f4c42ba04ea4a034119af907db1.zip
Merge pull request #8466 from nextcloud/strict_middlewaredipatcher
Make the middlewareDispatcher strict
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/AppFramework/Http/Dispatcher.php3
-rw-r--r--lib/private/AppFramework/Middleware/MiddlewareDispatcher.php21
2 files changed, 11 insertions, 13 deletions
diff --git a/lib/private/AppFramework/Http/Dispatcher.php b/lib/private/AppFramework/Http/Dispatcher.php
index 6219ba47a41..7b9ad015de6 100644
--- a/lib/private/AppFramework/Http/Dispatcher.php
+++ b/lib/private/AppFramework/Http/Dispatcher.php
@@ -105,9 +105,6 @@ class Dispatcher {
} catch(\Exception $exception){
$response = $this->middlewareDispatcher->afterException(
$controller, $methodName, $exception);
- if ($response === null) {
- throw $exception;
- }
}
$response = $this->middlewareDispatcher->afterController(
diff --git a/lib/private/AppFramework/Middleware/MiddlewareDispatcher.php b/lib/private/AppFramework/Middleware/MiddlewareDispatcher.php
index 60d2ae8b5c9..e1262b6c712 100644
--- a/lib/private/AppFramework/Middleware/MiddlewareDispatcher.php
+++ b/lib/private/AppFramework/Middleware/MiddlewareDispatcher.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -30,7 +31,7 @@ namespace OC\AppFramework\Middleware;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Response;
-use OCP\AppFramework\MiddleWare;
+use OCP\AppFramework\Middleware;
/**
* This class is used to store and run all the middleware in correct order
@@ -53,7 +54,7 @@ class MiddlewareDispatcher {
* Constructor
*/
public function __construct(){
- $this->middlewares = array();
+ $this->middlewares = [];
$this->middlewareCounter = 0;
}
@@ -71,7 +72,7 @@ class MiddlewareDispatcher {
* returns an array with all middleware elements
* @return array the middlewares
*/
- public function getMiddlewares(){
+ public function getMiddlewares(): array {
return $this->middlewares;
}
@@ -84,10 +85,10 @@ class MiddlewareDispatcher {
* @param string $methodName the name of the method that will be called on
* the controller
*/
- public function beforeController(Controller $controller, $methodName){
+ public function beforeController(Controller $controller, string $methodName){
// we need to count so that we know which middlewares we have to ask in
// case there is an exception
- $middlewareCount = count($this->middlewares);
+ $middlewareCount = \count($this->middlewares);
for($i = 0; $i < $middlewareCount; $i++){
$this->middlewareCounter++;
$middleware = $this->middlewares[$i];
@@ -111,7 +112,7 @@ class MiddlewareDispatcher {
* exception
* @throws \Exception the passed in exception if it can't handle it
*/
- public function afterException(Controller $controller, $methodName, \Exception $exception){
+ public function afterException(Controller $controller, string $methodName, \Exception $exception): Response {
for($i=$this->middlewareCounter-1; $i>=0; $i--){
$middleware = $this->middlewares[$i];
try {
@@ -134,8 +135,8 @@ class MiddlewareDispatcher {
* @param Response $response the generated response from the controller
* @return Response a Response object
*/
- public function afterController(Controller $controller, $methodName, Response $response){
- for($i=count($this->middlewares)-1; $i>=0; $i--){
+ public function afterController(Controller $controller, string $methodName, Response $response): Response {
+ for($i= \count($this->middlewares)-1; $i>=0; $i--){
$middleware = $this->middlewares[$i];
$response = $middleware->afterController($controller, $methodName, $response);
}
@@ -153,8 +154,8 @@ class MiddlewareDispatcher {
* @param string $output the generated output from a response
* @return string the output that should be printed
*/
- public function beforeOutput(Controller $controller, $methodName, $output){
- for($i=count($this->middlewares)-1; $i>=0; $i--){
+ public function beforeOutput(Controller $controller, string $methodName, string $output): string {
+ for($i= \count($this->middlewares)-1; $i>=0; $i--){
$middleware = $this->middlewares[$i];
$output = $middleware->beforeOutput($controller, $methodName, $output);
}