25
25
use Symfony \Component \Cache \Adapter \ProxyAdapter ;
26
26
use Symfony \Component \Cache \Adapter \RedisAdapter ;
27
27
use Symfony \Component \DependencyInjection \ChildDefinition ;
28
+ use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
28
29
use Symfony \Component \DependencyInjection \ContainerBuilder ;
29
30
use Symfony \Component \DependencyInjection \Definition ;
30
31
use Symfony \Component \DependencyInjection \Loader \ClosureLoader ;
@@ -589,10 +590,12 @@ public function testValidationService()
589
590
590
591
public function testAnnotations ()
591
592
{
592
- $ container = $ this ->createContainerFromFile ('full ' );
593
+ $ container = $ this ->createContainerFromFile ('full ' , array (), true , false );
594
+ $ container ->addCompilerPass (new TestAnnotationsPass ());
595
+ $ container ->compile ();
593
596
594
597
$ this ->assertEquals ($ container ->getParameter ('kernel.cache_dir ' ).'/annotations ' , $ container ->getDefinition ('annotations.filesystem_cache ' )->getArgument (0 ));
595
- $ this ->assertSame ('annotations.filesystem_cache ' , (string ) $ container ->getDefinition ('annotations.cached_reader ' )->getArgument (1 ));
598
+ $ this ->assertSame ('annotations.filesystem_cache ' , (string ) $ container ->getDefinition ('annotation_reader ' )->getArgument (1 ));
596
599
}
597
600
598
601
public function testFileLinkFormat ()
@@ -1051,10 +1054,10 @@ protected function createContainer(array $data = array())
1051
1054
), $ data )));
1052
1055
}
1053
1056
1054
- protected function createContainerFromFile ($ file , $ data = array (), $ resetCompilerPasses = true )
1057
+ protected function createContainerFromFile ($ file , $ data = array (), $ resetCompilerPasses = true , $ compile = true )
1055
1058
{
1056
1059
$ cacheKey = md5 (get_class ($ this ).$ file .serialize ($ data ));
1057
- if (isset (self ::$ containerCache [$ cacheKey ])) {
1060
+ if ($ compile && isset (self ::$ containerCache [$ cacheKey ])) {
1058
1061
return self ::$ containerCache [$ cacheKey ];
1059
1062
}
1060
1063
$ container<
6D40
/span> = $ this ->createContainer ($ data );
@@ -1065,7 +1068,12 @@ protected function createContainerFromFile($file, $data = array(), $resetCompile
1065
1068
$ container ->getCompilerPassConfig ()->setOptimizationPasses (array ());
1066
1069
$ container ->getCompilerPassConfig ()->setRemovingPasses (array ());
1067
1070
}
1068
- $ container ->getCompilerPassConfig ()->setBeforeRemovingPasses (array (new AddAnnotationsCachedReaderPass (), new AddConstraintValidatorsPass (), new TranslatorPass ('translator.default ' , 'translation.reader ' )));
1071
+ $ container ->getCompilerPassConfig ()->setBeforeRemovingPasses (array (new AddConstraintValidatorsPass (), new TranslatorPass ('translator.default ' , 'translation.reader ' )));
1072
+ $ container ->getCompilerPassConfig ()->setAfterRemovingPasses (array (new AddAnnotationsCachedReaderPass ()));
1073
+
1074
+ if (!$ compile ) {
1075
+ return $ container ;
1076
+ }
1069
1077
$ container ->compile ();
1070
1078
1071
1079
return self ::$ containerCache [$ cacheKey ] = $ container ;
@@ -1158,3 +1166,15 @@ private function assertCachePoolServiceDefinitionIsCreated(ContainerBuilder $con
1158
1166
}
1159
1167
}
1160
1168
}
1169
+
1170
+ /**
1171
+ * Simulates ReplaceAliasByActualDefinitionPass.
1172
+ */
1173
+ class TestAnnotationsPass implements CompilerPassInterface
1174
+ {
1175
+ public function process (ContainerBuilder $ container )
1176
+ {
1177
+ $ container ->setDefinition ('annotation_reader ' , $ container ->getDefinition ('annotations.cached_reader ' ));
1178
+ $ container ->removeDefinition ('annotations.cached_reader ' );
1179
+ }
1180
+ }
0 commit comments