9
9
10
10
namespace Webfactory \HttpCacheBundle \NotModified ;
11
11
12
- use Doctrine \Common \Annotations \Reader ;
13
12
use ReflectionMethod ;
14
13
use SplObjectStorage ;
15
14
use Symfony \Component \DependencyInjection \ContainerInterface ;
16
15
use Symfony \Component \HttpFoundation \Response ;
17
16
use Symfony \Component \HttpKernel \Event \ControllerEvent ;
18
17
use Symfony \Component \HttpKernel \Event \ResponseEvent ;
19
- use Webfactory \HttpCacheBundle \NotModified ;
18
+ use Webfactory \HttpCacheBundle \NotModified \ Attribute \ ReplaceWithNotModifiedResponse ;
20
19
21
20
/**
22
21
* Symfony EventListener for adding a "last modified" header to the response on the one hand. On the other hand, it
25
24
*/
26
25
final class EventListener
27
26
{
28
- /** @var Reader */
29
- private $ reader ;
30
-
31
27
/** @var ContainerInterface */
32
28
private $ container ;
33
29
@@ -44,9 +40,8 @@ final class EventListener
44
40
*/
45
41
private $ debug ;
46
42
47
- public function __construct (Reader $ reader , ContainerInterface $ container , bool $ debug = false )
43
+ public function __construct (ContainerInterface $ container , bool $ debug = false )
48
44
{
49
- $ this ->reader = $ reader ;
50
45
$ this ->container = $ container ;
51
46
$ this ->lastModified = new SplObjectStorage ();
52
47
$ this ->debug = $ debug ;
@@ -107,7 +102,7 @@ public function onKernelResponse(ResponseEvent $event)
107
102
/**
108
103
* @param $controllerCallable callable PHP callback pointing to the method to reflect on.
109
104
*
110
- * @return ReplaceWithNotModifiedResponse|null The annotation, if found. Null otherwise.
105
+ * @return ? ReplaceWithNotModifiedResponse The annotation, if found. Null otherwise.
111
106
*/
112
107
private function findAnnotation (callable $ controllerCallable )
113
108
{
@@ -118,25 +113,8 @@ private function findAnnotation(callable $controllerCallable)
118
113
[$ class , $ methodName ] = $ controllerCallable ;
119
114
$ method = new ReflectionMethod ($ class , $ methodName );
120
115
121
- if (PHP_MAJOR_VERSION >= 8 ) {
122
- $ attributes = $ method ->getAttributes (NotModified \Attribute \ReplaceWithNotModifiedResponse::class);
123
-
124
- if ($ attributes ) {
125
- return $ attributes [0 ]->newInstance ();
126
- }
127
- }
128
-
129
- /** @var ReplaceWithNotModifiedResponse|null $annotation */
130
- $ annotation = $ this ->reader ->getMethodAnnotation ($ method , NotModified \Annotation \ReplaceWithNotModifiedResponse::class);
131
-
132
- if ($ annotation ) {
133
- trigger_deprecation (
134
- 'webfactory/http-cache-bundle ' ,
135
- '1.4.0 ' ,
136
- 'Configuring webfactory/http-cache-bundle with annotations is deprecated, use attributes instead. '
137
- );
138
- }
116
+ $ attributes = $ method ->getAttributes (ReplaceWithNotModifiedResponse::class);
139
117
140
- return $ annotation ;
118
+ return $ attributes ? $ attributes [ 0 ]-> newInstance () : null ;
141
119
}
142
120
}
0 commit comments