1111
1212namespace Cache \CacheBundle \DependencyInjection ;
1313
14+ use Cache \Bridge \DoctrineCacheBridge ;
1415use Symfony \Component \Config \FileLocator ;
1516use Symfony \Component \DependencyInjection \ContainerBuilder ;
1617use Symfony \Component \DependencyInjection \Loader ;
@@ -36,12 +37,29 @@ public function load(array $configs, ContainerBuilder $container)
3637 $ loader = new Loader \YamlFileLoader ($ container , new FileLocator (__DIR__ .'/../Resources/config ' ));
3738
3839 // Make sure config values are in the parameters
39- foreach (['router ' , 'session ' , 'doctrine ' , 'logging ' ] as $ section ) {
40+ foreach (['router ' , 'session ' , 'doctrine ' , 'logging ' , ' annotation ' , ' serializer ' ] as $ section ) {
4041 if ($ config [$ section ]['enabled ' ]) {
4142 $ container ->setParameter ('cache. ' .$ section , $ config [$ section ]);
4243 }
4344 }
4445
46+ if ($ config ['annotation ' ]['enabled ' ]) {
47+ $ this ->verifyDoctrineBridgeExists ('annotation ' );
48+ $ container ->register ('cache.service.annotation ' , DoctrineCacheBridge::class)
49+ ->setFactory ('Cache\CacheBundle\Factory\AnnotationFactory::get ' )
50+ ->addArgument (new Reference ($ config ['annotation ' ]['service_id ' ]))
51+ ->addArgument ($ config ['annotation ' ]);
52+ }
53+
54+ if ($ config ['serializer ' ]['enabled ' ]) {
55+ $ this ->verifyDoctrineBridgeExists ('serializer ' );
56+ $ container ->register ('cache.service.serializer ' , DoctrineCacheBridge::class)
57+ ->setFactory ('Cache\CacheBundle\Factory\SerializerFactory::get ' )
58+ ->addArgument (new Reference ($ config ['serializer ' ]['service_id ' ]))
59+ ->addArgument ($ config ['serializer ' ]);
60+ }
61+
62+
4563 if ($ config ['router ' ]['enabled ' ]) {
4664 $ loader ->load ('router.yml ' );
4765 $ container ->getDefinition ('cache.router ' )
@@ -76,6 +94,22 @@ protected function findServiceIds(array $config, array &$serviceIds)
7694 }
7795 }
7896
97+ /**
98+ * Make sure the DoctrineBridge is installed
99+ *
100+ * @param string $name
101+ * @throws \Exception
102+ */
103+ private function verifyDoctrineBridgeExists ($ name )
104+ {
105+ if (!class_exists ('Cache\Bridge\DoctrineCacheBridge ' )) {
106+ throw new \Exception (sprintf (
107+ 'You need the DoctrineBridge to be able to use "%s". Please run "composer require cache/psr-6-doctrine-bridge" to install the missing dependency. ' ,
108+ $ name
109+ ));
110+ }
111+ }
112+
79113 /**
80114 * @return string
81115 */
0 commit comments