Skip to content

Commit

Permalink
Merge pull request #59 from c960657/custom-cache-driver
Browse files Browse the repository at this point in the history
Support custom cache drivers in orm.cache.factory
  • Loading branch information
simensen committed Sep 7, 2015
2 parents 84b3f48 + 8ab6bbc commit 24c987e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
24 changes: 5 additions & 19 deletions src/Dflydev/Provider/DoctrineOrm/DoctrineOrmServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,26 +357,12 @@ public function register(Container $container)
});

$container['orm.cache.factory'] = $container->protect(function ($driver, $cacheOptions) use ($container) {
switch ($driver) {
case 'array':
return $container['orm.cache.factory.array']();
case 'apc':
return $container['orm.cache.factory.apc']();
case 'xcache':
return $container['orm.cache.factory.xcache']();
case 'memcache':
return $container['orm.cache.factory.memcache']($cacheOptions);
case 'memcached':
return $container['orm.cache.factory.memcached']($cacheOptions);
case 'filesystem':
return $container['orm.cache.factory.filesystem']($cacheOptions);
case 'redis':
return $container['orm.cache.factory.redis']($cacheOptions);
case 'couchbase':
return $container['orm.cache.factory.couchbase']($cacheOptions);
default:
throw new \RuntimeException("Unsupported cache type '$driver' specified");
$cacheFactoryKey = 'orm.cache.factory.'.$driver;
if (!isset($container[$cacheFactoryKey])) {
throw new \RuntimeException("Factory '$cacheFactoryKey' for cache type '$driver' not defined (is it spelled correctly?)");
}

return $container[$cacheFactoryKey]($cacheOptions);
});

$container['orm.mapping_driver_chain.locator'] = $container->protect(function ($name = null) use ($container) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public function testInvalidCacheTypeNamed()

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

Expand All @@ -250,7 +250,7 @@ public function testInvalidCacheTypeDriverAsOption()

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

Expand Down

0 comments on commit 24c987e

Please sign in to comment.