I am using the PHP-DI 5 dependency injection container and I have already read the documentation about the definitions caching. Though I am still not sure in this regard... So I would like to ask you:
1) If I directly set an object as an entry value in the container, will the entry be cached?
$builder = new ContainerBuilder();
$builder->setDefinitionCache(new ApcCache());
$container = $builder->build();
$response = new Response();
// Will this entry be cached?
$container->set(ResponseInterface::class, $response);
2) Now let's say the object is already defined in the container, in a definitions file:
return [
'response' => function () {
return new Response();
},
];
If I perform the following:
$builder = new ContainerBuilder();
$builder->setDefinitionCache(new ApcCache());
$container = $builder->build();
// Will this entry be cached?
$container->set(ResponseInterface::class, DI\get('response'));
- will the entry be cached, or
- will an error be raised, or
- will the entry be "silently" not cached?
Thank you very much.