summaryrefslogtreecommitdiffstats
path: root/lib/private/AppFramework
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2023-01-25 19:26:21 +0100
committerChristoph Wurst <christoph@winzerhof-wurst.at>2023-01-27 09:40:35 +0100
commit20e00cdf17f45f811135fe5fb61c133ce9021144 (patch)
treeb9bb2d0c10ede9f4532bddeebcbdb3c1d5febc98 /lib/private/AppFramework
parentbe1de30a4f6b37da7c710ac55489e4938c4ded91 (diff)
downloadnextcloud-server-20e00cdf17f45f811135fe5fb61c133ce9021144.tar.gz
nextcloud-server-20e00cdf17f45f811135fe5fb61c133ce9021144.zip
feat(app-framework): Add UseSession attribute to replace annotation
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/private/AppFramework')
-rw-r--r--lib/private/AppFramework/Middleware/SessionMiddleware.php34
1 files changed, 30 insertions, 4 deletions
diff --git a/lib/private/AppFramework/Middleware/SessionMiddleware.php b/lib/private/AppFramework/Middleware/SessionMiddleware.php
index af195df0de9..39f85915901 100644
--- a/lib/private/AppFramework/Middleware/SessionMiddleware.php
+++ b/lib/private/AppFramework/Middleware/SessionMiddleware.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -27,9 +30,11 @@ namespace OC\AppFramework\Middleware;
use OC\AppFramework\Utility\ControllerMethodReflector;
use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http\Attribute\UseSession;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Middleware;
use OCP\ISession;
+use ReflectionMethod;
class SessionMiddleware extends Middleware {
/** @var ControllerMethodReflector */
@@ -49,8 +54,18 @@ class SessionMiddleware extends Middleware {
* @param string $methodName
*/
public function beforeController($controller, $methodName) {
- $useSession = $this->reflector->hasAnnotation('UseSession');
- if ($useSession) {
+ /**
+ * Annotation deprecated with Nextcloud 26
+ */
+ $hasAnnotation = $this->reflector->hasAnnotation('UseSession');
+ if ($hasAnnotation) {
+ $this->session->reopen();
+ return;
+ }
+
+ $reflectionMethod = new ReflectionMethod($controller, $methodName);
+ $hasAttribute = !empty($reflectionMethod->getAttributes(UseSession::class));
+ if ($hasAttribute) {
$this->session->reopen();
}
}
@@ -62,10 +77,21 @@ class SessionMiddleware extends Middleware {
* @return Response
*/
public function afterController($controller, $methodName, Response $response) {
- $useSession = $this->reflector->hasAnnotation('UseSession');
- if ($useSession) {
+ /**
+ * Annotation deprecated with Nextcloud 26
+ */
+ $hasAnnotation = $this->reflector->hasAnnotation('UseSession');
+ if ($hasAnnotation) {
$this->session->close();
+ return $response;
}
+
+ $reflectionMethod = new ReflectionMethod($controller, $methodName);
+ $hasAttribute = !empty($reflectionMethod->getAttributes(UseSession::class));
+ if ($hasAttribute) {
+ $this->session->close();
+ }
+
return $response;
}
}