11<?php
2+
3+ declare (strict_types=1 );
4+
25/**
36 * @copyright Copyright (c) 2016, ownCloud, Inc.
47 *
2730
2831use OC \AppFramework \Utility \ControllerMethodReflector ;
2932use OCP \AppFramework \Controller ;
33+ use OCP \AppFramework \Http \Attribute \UseSession ;
3034use OCP \AppFramework \Http \Response ;
3135use OCP \AppFramework \Middleware ;
3236use OCP \ISession ;
37+ use ReflectionMethod ;
3338
3439class SessionMiddleware extends Middleware {
3540 /** @var ControllerMethodReflector */
@@ -49,8 +54,18 @@ public function __construct(ControllerMethodReflector $reflector,
4954 * @param string $methodName
5055 */
5156 public function beforeController ($ controller , $ methodName ) {
52- $ useSession = $ this ->reflector ->hasAnnotation ('UseSession ' );
53- if ($ useSession ) {
57+ /**
58+ * Annotation deprecated with Nextcloud 26
59+ */
60+ $ hasAnnotation = $ this ->reflector ->hasAnnotation ('UseSession ' );
61+ if ($ hasAnnotation ) {
62+ $ this ->session ->reopen ();
63+ return ;
64+ }
65+
66+ $ reflectionMethod = new ReflectionMethod ($ controller , $ methodName );
67+ $ hasAttribute = !empty ($ reflectionMethod ->getAttributes (UseSession::class));
68+ if ($ hasAttribute ) {
5469 $ this ->session ->reopen ();
5570 }
5671 }
@@ -62,10 +77,21 @@ public function beforeController($controller, $methodName) {
6277 * @return Response
6378 */
6479 public function afterController ($ controller , $ methodName , Response $ response ) {
65- $ useSession = $ this ->reflector ->hasAnnotation ('UseSession ' );
66- if ($ useSession ) {
80+ /**
81+ * Annotation deprecated with Nextcloud 26
82+ */
83+ $ hasAnnotation = $ this ->reflector ->hasAnnotation ('UseSession ' );
84+ if ($ hasAnnotation ) {
6785 $ this ->session ->close ();
86+ return $ response ;
6887 }
88+
89+ $ reflectionMethod = new ReflectionMethod ($ controller , $ methodName );
90+ $ hasAttribute = !empty ($ reflectionMethod ->getAttributes (UseSession::class));
91+ if ($ hasAttribute ) {
92+ $ this ->session ->close ();
93+ }
94+
6995 return $ response ;
7096 }
7197}
0 commit comments