@@ -40,29 +40,30 @@ public function process(ContainerBuilder $container)
4040 $ providers = $ container ->getParameter ('cache_adapter_doctrine.providers ' );
4141
4242 foreach ($ providers as $ name => $ provider ) {
43- $ typeServiceId = 'cache.doctrine_adapter.abstract. ' .$ provider ['type ' ];
44- if (!$ container ->hasDefinition ($ typeServiceId )) {
43+ $ typeServiceId = sprintf ('cache.doctrine_adapter.abstract.%s ' , $ provider ['type ' ]);
44+ $ classParameter = sprintf ('cache.doctrine_adapter.%s.class ' ,$ provider ['type ' ]);
45+ if (!$ container ->hasParameter ($ classParameter )) {
4546 throw new InvalidConfigurationException (
4647 sprintf (
47- '`%s` is not a valid cache type. If you are using a custom type, make sure to add your service. ' ,
48- $ provider ['type ' ]
48+ '"%s" is not a valid cache type. We cannot find a container parameter named "%s" with a class namespace as value. Make sure to add that or use any built in services ' ,
49+ $ provider ['type ' ],
50+ $ classParameter
4951 )
5052 );
5153 }
54+ $ class = $ container ->getParameter ($ classParameter );
5255
53- $ this ->prepareDoctrineCacheClass ($ container , $ typeServiceId , $ name , $ provider );
56+ $ this ->createDoctrineCacheDefinition ($ container , $ typeServiceId, $ class , $ name , $ provider );
5457 $ this ->createPsr7CompliantService ($ container , $ typeServiceId , $ name );
5558 }
5659 }
5760
5861 /**
59- * Make sure to create a PRS-6 service that wrapps the doctrine service.
62+ * Make sure to create a PRS-6 service that wraps the doctrine service.
6063 *
61- * @param string $typeId
64+ * @param ContainerBuilder $container
65+ * @param string $typeServiceId
6266 * @param string $name
63- * @param array $provider
64- *
65- * @return Definition
6667 */
6768 private function createPsr7CompliantService (ContainerBuilder $ container , $ typeServiceId , $ name )
6869 {
@@ -80,16 +81,18 @@ private function createPsr7CompliantService(ContainerBuilder $container, $typeSe
8081 /**
8182 * We need to prepare the doctrine cache providers.
8283 *
83- * @param Definition $service
84- * @param string $name
85- * @param array $provider
84+ * @param ContainerBuilder $container
85+ * @param string $typeServiceId
86+ * @param string $class
87+ * @param string $name
88+ * @param array $provider
8689 */
87- private function prepareDoctrineCacheClass (ContainerBuilder $ container , $ typeServiceId , $ name , array $ provider )
90+ private function createDoctrineCacheDefinition (ContainerBuilder $ container , $ typeServiceId, $ class , $ name , array $ provider )
8891 {
8992 $ namespace = is_null ($ provider ['namespace ' ]) ? $ name : $ provider ['namespace ' ];
9093
91- // Modify the core doctrine cache class
92- $ definition = $ container -> getDefinition ( $ typeServiceId );
94+ // Create a service for the requested doctrine cache
95+ $ definition = new Definition ( $ class );
9396 $ definition ->addMethodCall ('setNamespace ' , [$ namespace ])
9497 ->setPublic (false );
9598
@@ -127,7 +130,7 @@ private function prepareDoctrineCacheClass(ContainerBuilder $container, $typeSer
127130 break ;
128131 }
129132
130- // TODO is this line needed?
133+ // Add the definition to the container
131134 $ container ->setDefinition ($ typeServiceId , $ definition );
132135 }
133136
0 commit comments