I want to use the current user in the postFlush
method of a Proposals
service, so I've just added SecurityContextInterface $securityContext
as a parameter of the __construct
method and as a property of the Proposals
service class:
use Symfony\Component\Security\Core\SecurityContextInterface;
/**
* @DI\Service("pro.proposals")
* @DI\Tag("doctrine.event_listener", attributes = {"event": "onFlush", "lazy": true})
* @DI\Tag("doctrine.event_listener", attributes = {"event": "postFlush", "lazy": true})
*/
class Proposals
{
private $doctrine;
private $translator;
private $templating;
private $notifications;
private $proposalsWithTypeChanged;
private $securityContext;
/**
* @DI\InjectParams({"notifications" = @DI\Inject("pro.notifications")})
*/
function __construct(Registry $doctrine, TranslatorInterface $translator, Notifications $notifications, Templating $templating, SecurityContextInterface $securityContext)
{
$this->doctrine = $doctrine;
$this->translator = $translator;
$this->templating = $templating;
$this->notifications = $notifications;
$this->securityContext = $securityContext;
}
but this is giving me this error:
ServiceNotFoundException: The service "pro.proposals" has a dependency on a non-existent service "security_context".
I've also tried passing the whole container as suggested on this post, but neither works. Any suggestion?