繁体   English   中英

symfony \\ Component \\ HttpFoundation \\ Session的symfony2升级2.0> 2.3问题

[英]symfony2 upgrade 2.0 > 2.3 issue with Symfony\Component\HttpFoundation\Session

这是我的自定义安全侦听器(来自sym 2.0)

namespace mine\UserBundle\EventListener;

use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\HttpFoundation\Session as Session;


class SecurityListener
{
    protected $security;
    protected $session;

/**
* Constructs a new instance of SecurityListener.
*
* @param SecurityContext $security The security context
* @param Session $session The session
*/
    public function __construct(SecurityContext $security, Session $session)//<-- here
    {
        //You can bring whatever you need here, but for a start this should be useful to you
        $this->security = $security;
        $this->session = $session;
    }

/**
* Invoked after a successful login.
*
* @param InteractiveLoginEvent $event The event
*/
    public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
    {
         //Your logic needs to go here
         //You can addRole 
         //Even persist if you want but bring the right tools to your constructor
         $security = $this->security; 

         if ($security->getToken()->getUser()->hasPlus()) {       
            $security->getToken()->getUser()->addRole('ROLE_PLUSUSER');    
         }

    }
}

我假设某些名称空间或类似的名称在2.0和2.1之间进行了更改(目前我正尝试将其提升到2.3),因为我抛出了此错误:

ContextErrorException:可捕获的致命错误:传递给mine \\ UserBundle \\ EventListener \\ SecurityListener :: __ construct()的参数2必须是Symfony \\ Component \\ HttpFoundation \\ Session的实例,Symfony \\ Component \\ HttpFoundation \\ Session \\ Session的实例已给定

好的,将依赖关系更改为

使用Symfony \\ Component \\ HttpFoundation \\ Session \\ Session;

做到了。 似乎与错误消息所说的完全相反...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM