Symfony2 обновление 2.0 > 2.3 проблема с 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: Catchable Fatal Error: Аргумент 2, переданный в mine\UserBundle\EventListener\SecurityListener::__construct(), должен быть экземпляром Symfony\Component\HttpFoundation\Session, экземпляром Symfony\Component\HttpFoundation\Session \ Session

1 ответ

Решение

Хорошо, изменение зависимости на

использовать Symfony\Component\HttpFoundation\Session\Session;

сделал трюк. Выглядело совершенно противоположно тому, что говорилось в сообщении об ошибке...

Другие вопросы по тегам