diff options
author | Morris Jobke <hey@morrisjobke.de> | 2017-08-01 14:28:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-01 14:28:16 +0200 |
commit | 6010c4f267f6b59e0dfd620dc928227f75dae9d1 (patch) | |
tree | e6ee00826da6450dcc12f6346ed2b158f7b8f240 /lib | |
parent | 050fa633800ed6fd922732b8461cf12b380818a1 (diff) | |
parent | f71dc7523f7625da4c47ec9d5b116d20f71dba33 (diff) | |
download | nextcloud-server-6010c4f267f6b59e0dfd620dc928227f75dae9d1.tar.gz nextcloud-server-6010c4f267f6b59e0dfd620dc928227f75dae9d1.zip |
Merge pull request #5877 from nextcloud/typehint_middleware
Prop argument type for Middleware
Diffstat (limited to 'lib')
7 files changed, 30 insertions, 27 deletions
diff --git a/lib/private/AppFramework/Middleware/OCSMiddleware.php b/lib/private/AppFramework/Middleware/OCSMiddleware.php index 0fc7bb0f0ec..50ee40b7b4a 100644 --- a/lib/private/AppFramework/Middleware/OCSMiddleware.php +++ b/lib/private/AppFramework/Middleware/OCSMiddleware.php @@ -52,10 +52,10 @@ class OCSMiddleware extends Middleware { } /** - * @param \OCP\AppFramework\Controller $controller + * @param Controller $controller * @param string $methodName */ - public function beforeController($controller, $methodName) { + public function beforeController(Controller $controller, $methodName) { if ($controller instanceof OCSController) { if (substr_compare($this->request->getScriptName(), '/ocs/v2.php', -strlen('/ocs/v2.php')) === 0) { $this->ocsVersion = 2; @@ -67,13 +67,13 @@ class OCSMiddleware extends Middleware { } /** - * @param \OCP\AppFramework\Controller $controller + * @param Controller $controller * @param string $methodName * @param \Exception $exception * @throws \Exception * @return BaseResponse */ - public function afterException($controller, $methodName, \Exception $exception) { + public function afterException(Controller $controller, $methodName, \Exception $exception) { if ($controller instanceof OCSController && $exception instanceof OCSException) { $code = $exception->getCode(); if ($code === 0) { @@ -87,12 +87,12 @@ class OCSMiddleware extends Middleware { } /** - * @param \OCP\AppFramework\Controller $controller + * @param Controller $controller * @param string $methodName * @param Response $response * @return \OCP\AppFramework\Http\Response */ - public function afterController($controller, $methodName, Response $response) { + public function afterController(Controller $controller, $methodName, Response $response) { /* * If a different middleware has detected that a request unauthorized or forbidden * we need to catch the response and convert it to a proper OCS response. @@ -120,7 +120,7 @@ class OCSMiddleware extends Middleware { * @param string $message * @return V1Response|V2Response */ - private function buildNewResponse($controller, $code, $message) { + private function buildNewResponse(Controller $controller, $code, $message) { $format = $this->getFormat($controller); $data = new DataResponse(); @@ -135,10 +135,10 @@ class OCSMiddleware extends Middleware { } /** - * @param \OCP\AppFramework\Controller $controller + * @param Controller $controller * @return string */ - private function getFormat($controller) { + private function getFormat(Controller $controller) { // get format from the url format or request format parameter $format = $this->request->getParam('format'); diff --git a/lib/private/AppFramework/Middleware/Security/BruteForceMiddleware.php b/lib/private/AppFramework/Middleware/Security/BruteForceMiddleware.php index b361f453bdb..78c86442b52 100644 --- a/lib/private/AppFramework/Middleware/Security/BruteForceMiddleware.php +++ b/lib/private/AppFramework/Middleware/Security/BruteForceMiddleware.php @@ -23,6 +23,7 @@ namespace OC\AppFramework\Middleware\Security; use OC\AppFramework\Utility\ControllerMethodReflector; use OC\Security\Bruteforce\Throttler; +use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Middleware; use OCP\IRequest; @@ -58,7 +59,7 @@ class BruteForceMiddleware extends Middleware { /** * {@inheritDoc} */ - public function beforeController($controller, $methodName) { + public function beforeController(Controller $controller, $methodName) { parent::beforeController($controller, $methodName); if($this->reflector->hasAnnotation('BruteForceProtection')) { @@ -70,7 +71,7 @@ class BruteForceMiddleware extends Middleware { /** * {@inheritDoc} */ - public function afterController($controller, $methodName, Response $response) { + public function afterController(Controller $controller, $methodName, Response $response) { if($this->reflector->hasAnnotation('BruteForceProtection') && $response->isThrottled()) { $action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action'); $ip = $this->request->getRemoteAddress(); diff --git a/lib/private/AppFramework/Middleware/Security/CORSMiddleware.php b/lib/private/AppFramework/Middleware/Security/CORSMiddleware.php index 4b50b0d20b3..77ad7430599 100644 --- a/lib/private/AppFramework/Middleware/Security/CORSMiddleware.php +++ b/lib/private/AppFramework/Middleware/Security/CORSMiddleware.php @@ -80,7 +80,7 @@ class CORSMiddleware extends Middleware { * @throws SecurityException * @since 6.0.0 */ - public function beforeController($controller, $methodName){ + public function beforeController(Controller $controller, $methodName){ // ensure that @CORS annotated API routes are not used in conjunction // with session authentication since this enables CSRF attack vectors if ($this->reflector->hasAnnotation('CORS') && @@ -110,7 +110,7 @@ class CORSMiddleware extends Middleware { * @return Response a Response object * @throws SecurityException */ - public function afterController($controller, $methodName, Response $response){ + public function afterController(Controller $controller, $methodName, Response $response){ // only react if its a CORS request and if the request sends origin and if(isset($this->request->server['HTTP_ORIGIN']) && @@ -143,7 +143,7 @@ class CORSMiddleware extends Middleware { * @throws \Exception the passed in exception if it can't handle it * @return Response a Response object or null in case that the exception could not be handled */ - public function afterException($controller, $methodName, \Exception $exception){ + public function afterException(Controller $controller, $methodName, \Exception $exception){ if($exception instanceof SecurityException){ $response = new JSONResponse(['message' => $exception->getMessage()]); if($exception->getCode() !== 0) { diff --git a/lib/private/AppFramework/Middleware/Security/RateLimitingMiddleware.php b/lib/private/AppFramework/Middleware/Security/RateLimitingMiddleware.php index e9fcc1fdea5..c73b31a6177 100644 --- a/lib/private/AppFramework/Middleware/Security/RateLimitingMiddleware.php +++ b/lib/private/AppFramework/Middleware/Security/RateLimitingMiddleware.php @@ -24,6 +24,7 @@ namespace OC\AppFramework\Middleware\Security; use OC\AppFramework\Utility\ControllerMethodReflector; use OC\Security\RateLimiting\Exception\RateLimitExceededException; use OC\Security\RateLimiting\Limiter; +use OCP\AppFramework\Controller; use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Middleware; @@ -76,7 +77,7 @@ class RateLimitingMiddleware extends Middleware { * {@inheritDoc} * @throws RateLimitExceededException */ - public function beforeController($controller, $methodName) { + public function beforeController(Controller $controller, $methodName) { parent::beforeController($controller, $methodName); $anonLimit = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'limit'); @@ -104,7 +105,7 @@ class RateLimitingMiddleware extends Middleware { /** * {@inheritDoc} */ - public function afterException($controller, $methodName, \Exception $exception) { + public function afterException(Controller $controller, $methodName, \Exception $exception) { if($exception instanceof RateLimitExceededException) { if (stripos($this->request->getHeader('Accept'),'html') === false) { $response = new JSONResponse( diff --git a/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php b/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php index 4e41c946432..becbd7b9ca2 100644 --- a/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php +++ b/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php @@ -136,7 +136,7 @@ class SecurityMiddleware extends Middleware { * @param string $methodName the name of the method * @throws SecurityException when a security check fails */ - public function beforeController($controller, $methodName) { + public function beforeController(Controller $controller, $methodName) { // this will set the current navigation entry of the app, use this only // for normal HTML requests and not for AJAX requests @@ -205,7 +205,7 @@ class SecurityMiddleware extends Middleware { * @param Response $response * @return Response */ - public function afterController($controller, $methodName, Response $response) { + public function afterController(Controller $controller, $methodName, Response $response) { $policy = !is_null($response->getContentSecurityPolicy()) ? $response->getContentSecurityPolicy() : new ContentSecurityPolicy(); if (get_class($policy) === EmptyContentSecurityPolicy::class) { @@ -234,7 +234,7 @@ class SecurityMiddleware extends Middleware { * @throws \Exception the passed in exception if it can't handle it * @return Response a Response object or null in case that the exception could not be handled */ - public function afterException($controller, $methodName, \Exception $exception) { + public function afterException(Controller $controller, $methodName, \Exception $exception) { if($exception instanceof SecurityException) { if($exception instanceof StrictCookieMissingException) { return new RedirectResponse(\OC::$WEBROOT); diff --git a/lib/private/AppFramework/Middleware/SessionMiddleware.php b/lib/private/AppFramework/Middleware/SessionMiddleware.php index c5fefa77fc4..f2545653e8f 100644 --- a/lib/private/AppFramework/Middleware/SessionMiddleware.php +++ b/lib/private/AppFramework/Middleware/SessionMiddleware.php @@ -24,6 +24,7 @@ namespace OC\AppFramework\Middleware; use OC\AppFramework\Utility\ControllerMethodReflector; +use OCP\AppFramework\Controller; use OCP\IRequest; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Middleware; @@ -55,10 +56,10 @@ class SessionMiddleware extends Middleware { } /** - * @param \OCP\AppFramework\Controller $controller + * @param Controller $controller * @param string $methodName */ - public function beforeController($controller, $methodName) { + public function beforeController(Controller $controller, $methodName) { $useSession = $this->reflector->hasAnnotation('UseSession'); if (!$useSession) { $this->session->close(); @@ -66,12 +67,12 @@ class SessionMiddleware extends Middleware { } /** - * @param \OCP\AppFramework\Controller $controller + * @param Controller $controller * @param string $methodName * @param Response $response * @return Response */ - public function afterController($controller, $methodName, Response $response){ + public function afterController(Controller $controller, $methodName, Response $response){ $useSession = $this->reflector->hasAnnotation('UseSession'); if ($useSession) { $this->session->close(); diff --git a/lib/public/AppFramework/Middleware.php b/lib/public/AppFramework/Middleware.php index 677e5c2e7ee..fbd75981b59 100644 --- a/lib/public/AppFramework/Middleware.php +++ b/lib/public/AppFramework/Middleware.php @@ -52,7 +52,7 @@ abstract class Middleware { * the controller * @since 6.0.0 */ - public function beforeController($controller, $methodName){ + public function beforeController(Controller $controller, $methodName){ } @@ -72,7 +72,7 @@ abstract class Middleware { * @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, $methodName, \Exception $exception){ throw $exception; } @@ -88,7 +88,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, $methodName, Response $response){ return $response; } @@ -104,7 +104,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, $methodName, $output){ return $output; } |