Skip to content

Commit 24c987e

Browse files
committed
Merge pull request #59 from c960657/custom-cache-driver
Support custom cache drivers in orm.cache.factory
2 parents 84b3f48 + 8ab6bbc commit 24c987e

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

src/Dflydev/Provider/DoctrineOrm/DoctrineOrmServiceProvider.php

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -357,26 +357,12 @@ public function register(Container $container)
357357
});
358358

359359
$container['orm.cache.factory'] = $container->protect(function ($driver, $cacheOptions) use ($container) {
360-
switch ($driver) {
361-
case 'array':
362-
return $container['orm.cache.factory.array']();
363-
case 'apc':
364-
return $container['orm.cache.factory.apc']();
365-
case 'xcache':
366-
return $container['orm.cache.factory.xcache']();
367-
case 'memcache':
368-
return $container['orm.cache.factory.memcache']($cacheOptions);
369-
case 'memcached':
370-
return $container['orm.cache.factory.memcached']($cacheOptions);
371-
case 'filesystem':
372-
return $container['orm.cache.factory.filesystem']($cacheOptions);
373-
case 'redis':
374-
return $container['orm.cache.factory.redis']($cacheOptions);
375-
case 'couchbase':
376-
return $container['orm.cache.factory.couchbase']($cacheOptions);
377-
default:
378-
throw new \RuntimeException("Unsupported cache type '$driver' specified");
360+
$cacheFactoryKey = 'orm.cache.factory.'.$driver;
361+
if (!isset($container[$cacheFactoryKey])) {
362+
throw new \RuntimeException("Factory '$cacheFactoryKey' for cache type '$driver' not defined (is it spelled correctly?)");
379363
}
364+
365+
return $container[$cacheFactoryKey]($cacheOptions);
380366
});
381367

382368
$container['orm.mapping_driver_chain.locator'] = $container->protect(function ($name = null) use ($container) {

tests/Dflydev/Tests/Provider/DoctrineOrm/DoctrineOrmServiceProviderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public function testInvalidCacheTypeNamed()
226226

227227
$this->fail('Expected invalid query cache driver exception');
228228
} catch (\RuntimeException $e) {
229-
$this->assertEquals("Unsupported cache type 'INVALID' specified", $e->getMessage());
229+
$this->assertEquals("Factory 'orm.cache.factory.INVALID' for cache type 'INVALID' not defined (is it spelled correctly?)", $e->getMessage());
230230
}
231231
}
232232

@@ -250,7 +250,7 @@ public function testInvalidCacheTypeDriverAsOption()
250250

251251
$this->fail('Expected invalid query cache driver exception');
252252
} catch (\RuntimeException $e) {
253-
$this->assertEquals("Unsupported cache type 'INVALID' specified", $e->getMessage());
253+
$this->assertEquals("Factory 'orm.cache.factory.INVALID' for cache type 'INVALID' not defined (is it spelled correctly?)", $e->getMessage());
254254
}
255255
}
256256

0 commit comments

Comments
 (0)