generate-factory-for-class should add logging if LoggerAwareTrait implemented
zippy1981 opened this issue · comments
I propose the following changes to FactoryCreatorCommand.
-
See if the class uses a trait called
LoggerAwareTrait
-
See if that trait has a method called
setLogger()
-
If so, the invoke member of the factory it generate should look something like:
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
return (new IndexController())->setLogger($container->get('log'));
}
You could whitelist a bunch of known PSR7 compatible LoggerAwareTrait's but this is most future proof. You could add a flag to prevent logger injection in the factory if you feel that is a concern.
This should be done explicitly with a delegator factory. Basically what you're proposing is what initializers used to do, but because they ran on every service creation, it's not so great on performance.
This is a userland implementation and I don't see this being implemented in the component .