Skip to content

Commit fa5208c

Browse files
committed
Fixes
1 parent 9d429ca commit fa5208c

File tree

2 files changed

+31
-47
lines changed

2 files changed

+31
-47
lines changed

src/DependencyInjection/CompilerPass/ServiceBuilderPass.php

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/Resources/config/services.yml

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,12 @@
11

2-
services:
3-
cache.doctrine_adapter.abstract.apc:
4-
class: Doctrine\Common\Cache\ApcCache
5-
6-
cache.doctrine_adapter.abstract.array:
7-
class: Doctrine\Common\Cache\ArrayCache
8-
9-
cache.doctrine_adapter.abstract.file_system:
10-
class: Doctrine\Common\Cache\FilesystemCache
11-
12-
cache.doctrine_adapter.abstract.memcache:
13-
class: Doctrine\Common\Cache\MemcacheCache
14-
15-
cache.doctrine_adapter.abstract.memcached:
16-
class: Doctrine\Common\Cache\MemcachedCache
17-
18-
cache.doctrine_adapter.abstract.redis:
19-
class: Doctrine\Common\Cache\RedisCache
20-
21-
cache.doctrine_adapter.abstract.php_file:
22-
class: Doctrine\Common\Cache\PhpFileCache
23-
24-
cache.doctrine_adapter.abstract.win_cache:
25-
class: Doctrine\Common\Cache\WinCacheCache
26-
27-
cache.doctrine_adapter.abstract.xcache:
28-
class: Doctrine\Common\Cache\XcacheCache
29-
30-
cache.doctrine_adapter.zend_data:
31-
class: Doctrine\Common\Cache\ZendDataCache
2+
parameters:
3+
cache.doctrine_adapter.apc.class: Doctrine\Common\Cache\ApcCache
4+
cache.doctrine_adapter.array.class: Doctrine\Common\Cache\ArrayCache
5+
cache.doctrine_adapter.file_system.class: Doctrine\Common\Cache\FilesystemCache
6+
cache.doctrine_adapter.memcache.class: Doctrine\Common\Cache\MemcacheCache
7+
cache.doctrine_adapter.memcached.class: Doctrine\Common\Cache\MemcachedCache
8+
cache.doctrine_adapter.redis.class: Doctrine\Common\Cache\RedisCache
9+
cache.doctrine_adapter.php_file.class: Doctrine\Common\Cache\PhpFileCache
10+
cache.doctrine_adapter.win_cache.class: Doctrine\Common\Cache\WinCacheCache
11+
cache.doctrine_adapter.xcache.class: Doctrine\Common\Cache\XcacheCache
12+
cache.doctrine_adapter.zend_data.class: Doctrine\Common\Cache\ZendDataCache

0 commit comments

Comments
 (0)