From 32e0ec3e585d516749f9b1a096abb78ca3003d61 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 17 Jan 2017 14:36:44 +0100 Subject: [PATCH] handle optional annotation parameters Signed-off-by: Bjoern Schiessle --- .../Security/SecurityMiddleware.php | 2 +- .../Utility/ControllerMethodReflector.php | 21 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php b/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php index dcfab3544b..edba6a3e75 100644 --- a/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php +++ b/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php @@ -192,7 +192,7 @@ class SecurityMiddleware extends Middleware { } if($this->reflector->hasAnnotation('BruteForceProtection')) { - $action = $this->request->getRequestUri(); + $action = $this->reflector->getAnnotationParameter('BruteForceProtection'); $this->throttler->sleepDelay($this->request->getRemoteAddress(), $action); $this->throttler->registerAttempt($action, $this->request->getRemoteAddress()); } diff --git a/lib/private/AppFramework/Utility/ControllerMethodReflector.php b/lib/private/AppFramework/Utility/ControllerMethodReflector.php index 9f653b0384..034fc3a175 100644 --- a/lib/private/AppFramework/Utility/ControllerMethodReflector.php +++ b/lib/private/AppFramework/Utility/ControllerMethodReflector.php @@ -56,7 +56,9 @@ class ControllerMethodReflector implements IControllerMethodReflector{ // extract everything prefixed by @ and first letter uppercase preg_match_all('/^\h+\*\h+@(?P[A-Z]\w+)(\h+(?P\w+))?$/m', $docs, $matches); - $this->annotations = $matches[1]; + foreach($matches['annotation'] as $key => $annontation) { + $this->annotations[$annontation] = $matches['parameter'][$key]; + } // extract type parameter information preg_match_all('/@param\h+(?P\w+)\h+\$(?P\w+)/', $docs, $matches); @@ -112,7 +114,22 @@ class ControllerMethodReflector implements IControllerMethodReflector{ * @return bool true if the annotation is found */ public function hasAnnotation($name){ - return in_array($name, $this->annotations); + return array_key_exists($name, $this->annotations); + } + + + /** + * Get optional annotation parameter + * @param string $name the name of the annotation + * @return string + */ + public function getAnnotationParameter($name){ + $parameter = ''; + if($this->hasAnnotation($name)) { + $parameter = $this->annotations[$name]; + } + + return $parameter; }