Closed and1truong closed 9 years ago
@andytruong Huh. That worked before? :) It seems like with the old switch statement (prior to #59) this would have thrown an exception since driver would have been an object instance instead of a string to switch on. Can you help me better understand what is going on? I'm all about not breaking BC. :)
@simensen, v2.0 I can do this (http://git.io/vZsNE), you can see the Travis status, but now when I run composer update, the test case now longer passed:
$c['orm.default_cache'] = function (Container $c) {
return $c['my_default_cache_service'];
};
$c->register(new DoctrineOrmServiceProvider(), [
'orm.proxies_dir' => $c['app.root'] . '/files/proxies',
'orm.em.options' => [ /* … */],
]);
@andytruong The reason that Travis is not complaining is that your definition of $c['orm.default_cache']
is overwritten when you call $c->register(new DoctrineOrmServiceProvider(), ...) a few lines further down, i.e. your FileSystem cache was not used by Doctrine at all.
The overwriting was a bug that was fixed in 2.0.1 (see PR #44). Now your value is no longer being overwritten, so you get an error because you have assigned orm.default_cache to an invalid value (only strings and arrays are supported).
Anyway, to get the requested behaviour you can override e.g. orm.cache.locator.
@c960657 how about if I inject cache object this way: https://github.com/dflydev/dflydev-doctrine-orm-service-provider/pull/62/files#diff-366af7c996f772b76e1dfe497be1e44aR262
@andytruong That wont work, I'm afraid.
@c960657 Why the test case passed?
@andytruong Which test case?
The Travis tests for atsilex pass with Doctrine ORM Service Provider 2.0.0 because your orm.default_cache callback was never invoked.
The Travis tests for this PR pass because you have not only added a test but also changed the behaviour of the service provider. That change is not necessary - to achieve the requested behaviour, you should override e.g. orm.cache.locator instead.
I think I have to copy the test case here so you can read it more clearly:
public function testCacheInjection() {
$container = $this->createMockDefaultApp();
$container->register(new DoctrineOrmServiceProvider, array('orm.default_cache' => new VoidCache()));
/** @var EntityManager $em */
$em = $container['orm.em'];
$this->assertInstanceOf('Doctrine\Common\Cache\VoidCache', $em->getConfiguration()->getHydrationCacheImpl());
}
If not invoked, why it's instance of VoidCache?
withdraw.
I was able to inject cache object to this service provider, but I can't now. Can you provide BC?
In my application, I want use single chain cache object for all service providers instead of create a lot of cache objects.
Thanks