Retrieve current user in Symfony app while respecting LoD
1
I'm having some issues understanding how the Law of Demeter should be applied in some cases with Symfony's DI system. I have some factory that requires to access current logged in user in the application. To do that I need to require @security.token_storage to inject it as a constructor argument. But in my factory, to access the user I will need to do : $tokenStorage->getToken()->getUser(), and worst, if I want to access some property of my user, I will need to dive one level deeper. How would you fix this issue according to the law of demeter ? Here is a sample of my code : class SomeFactory { /** * @var User */ private $currentUser; /** * @param TokenStorageInterface $tokenStorage */ public function __construct(TokenStorageInterface $tokenSt...