Closed
Description
Q | A |
---|---|
Bug report? | no |
Feature request? | yes |
BC Break report? | no |
RFC? | yes |
Symfony version | 3.4 |
I'd like to reintroduce the removed closure proxy type, in a simplified manner, to provide laziness without injecting a container.
A callable
type; it came to mind facing the following use case, which imo. ideally i'd write as;
My\CachePoolManager:
arguments: [!callable memory_cache_factory] # proposed feature used here
memory_cache_factory:
class: Symfony\Component\Cache\Adapter\ArrayAdapter
arguments: [0, false]
shared: false # plays well with this feature :)
public: false
namespace My;
final class CachePoolManager {
private $cacheFactory;
private static $pools = [];
public function __construct(callable $cacheFactory) {
$this->cacheFactory = $cacheFactory;
}
public function getForKey(string $key): \Psr\Cache\CacheItemPoolInterface {
return self::$pools[$key] ?? (self::$pools[$key] = ($this->cacheFactory)());
}
5E4E
}
Note this becomes close related to service_locator
s, but i cannot create services per $key
as these are runtime related.
The "workaround" would be to inject a service locator containing the memory_cache_factory
creating a dependency between class and service id ($this->container->get('memory_cache_factory')
; which in turn can be injected as well making things look weird.
This keeps everything at the config level.
Thoughts?