symfony - Symfony2 - Custom arguments to postFlush method using annotations -
i want use current user in postflush
method of proposals
service, i've added securitycontextinterface $securitycontext
parameter of __construct
method , property of 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 giving me error:
servicenotfoundexception: service "pro.proposals" has dependency on non-existent service "security_context".
i've tried passing whole container suggested on this post, neither works. suggestion?
replace
/** * @di\injectparams({"notifications" = @di\inject("pro.notifications")}) */
with
/** * @di\injectparams( { * "notifications" = @di\inject("pro.notifications"), * "securitycontext" = @di\inject("security.context") * } ) */
i think diextrabundle tried guess service name based on argument's name. must specify service id explicitly instead.
if security context relies on doctrine, can still inject container stated in other post, example:
/** * @di\service("pro.proposals") */ class test { /** * @var securitycontextinterface */ protected $securitycontext; /** * @di\injectparams({"container" = @di\inject("service_container")}) */ function __construct( containerinterface $container ) { $this->securitycontext = $container->get( 'security.context' ); } }
Comments
Post a Comment