15
15
class CacheCompilerPass implements CompilerPassInterface
16
16
{
17
17
/**
18
- * You can modify the container here before it is dumped to PHP code.
19
- *
20
- * @param ContainerBuilder $container
21
- *
22
- * @api
18
+ * @inheritDoc
23
19
*/
24
20
public function process (ContainerBuilder $ container )
25
21
{
@@ -32,18 +28,22 @@ public function process(ContainerBuilder $container)
32
28
)
33
29
);
34
30
35
-
36
- $ this ->proxyServicesToBeCached ($ container );
31
+ $ this ->analyzeServicesTobeCached ($ container );
37
32
}
38
33
39
34
/**
40
- * @param ContainerBuilder $container
41
- * @return array
35
+ * @param ContainerBuilder $container
36
+ *
37
+ * @return void
42
38
*/
43
- protected function proxyServicesToBeCached (ContainerBuilder $ container )
39
+ protected function analyzeServicesTobeCached (ContainerBuilder $ container )
44
40
{
45
41
$ annotationReader = new AnnotationReader ();
46
- $ servicesToBeCached = [];
42
+ $ annotationReaderReference = new Reference ("annotation_reader " );
43
+ $ proxyWarmup = $ container ->getDefinition ('emag.cache.warmup ' );
44
+ $ cacheProxyFactory = new Reference ('emag.cache.proxy.factory ' );
45
+ $ cacheServiceReference = new Reference ($ container ->getParameter ('emag.cache.service ' ));
46
+
47
47
foreach ($ container ->getDefinitions () as $ serviceId => $ definition ) {
48
48
if (!class_exists ($ definition ->getClass ()) || $ this ->isFromIgnoredNamespace ($ container , $ definition ->getClass ())) {
49
49
continue ;
@@ -66,24 +66,24 @@ protected function proxyServicesToBeCached(ContainerBuilder $container)
66
66
}
67
67
68
68
$ wrapper = new Definition ($ definition ->getClass ());
69
- $ wrapper ->setFactory ([new Reference ('emag.cache.proxy.factory ' ), 'generate ' ]);
70
- $ wrapper ->setTags ($ definition ->getTags ());
71
- $ wrapper ->setArguments ([$ definition ->getClass (), $ definition ->getArguments ()]);
72
- $ wrapper ->setMethodCalls ($ definition ->getMethodCalls ());
73
- $ wrapper ->setProperties ($ definition ->getProperties ());
74
- $ wrapper ->setProperties ($ definition ->getProperties ());
75
- $ wrapper ->addMethodCall ('setReaderForCacheMethod ' , [new Reference ("annotation_reader " )]);
76
- $ wrapper ->addMethodCall ('setCacheServiceForMethod ' , [new Reference ($ container ->getParameter ('cache.service ' ))]);
77
- $ container ->getDefinition ('emag.cache.warmup ' )->addMethodCall ('addClassToGenerate ' , [$ definition ->getClass ()]);
69
+ $ wrapper
70
+ ->setFactory ([$ cacheProxyFactory , 'generate ' ])
71
+ ->setTags ($ definition ->getTags ())
72
+ ->setArguments ([$ definition ->getClass (), $ definition ->getArguments ()])
73
+ ->setMethodCalls ($ definition ->getMethodCalls ())
74
+ ->setProperties ($ definition ->getProperties ())
75
+ ->setProperties ($ definition ->getProperties ())
76
+ ->addMethodCall ('setReaderForCacheMethod ' , [$ annotationReaderReference ])
77
+ ->addMethodCall ('setCacheServiceForMethod ' , [$ cacheServiceReference ])
78
+ ;
78
79
80
+ $ proxyWarmup ->addMethodCall ('addClassToGenerate ' , [$ definition ->getClass ()]);
79
81
80
82
$ container ->setDefinition ($ serviceId , $ wrapper );
81
83
break ;
82
84
}
83
85
}
84
86
}
85
-
86
- return $ servicesToBeCached ;
87
87
}
88
88
89
89
/**
0 commit comments