소스 검색

Strip securityContext injection

Turns out $event->getData() works for listeners as well, not just
dispatchers. With that in mind, this ditches a bunch of cruft.
Dave Shoreman 11 년 전
부모
커밋
233bc964a0
1개의 변경된 파일4개의 추가작업 그리고 14개의 파일을 삭제
  1. 4 14
      src/Packagist/WebBundle/Form/Type/ProfileFormType.php

+ 4 - 14
src/Packagist/WebBundle/Form/Type/ProfileFormType.php

@@ -25,26 +25,16 @@ use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;
  */
 class ProfileFormType extends BaseType
 {
-    private $securityContext;
-
-    public function __construct($class, SecurityContext $securityContext)
-    {
-        parent::__construct($class);
-
-        $this->securityContext = $securityContext;
-    }
-
     public function buildForm(FormBuilderInterface $builder, array $options)
     {
         $builder->add('username', null, array('label' => 'form.username', 'translation_domain' => 'FOSUserBundle'))
                 ->add('email', 'email', array('label' => 'form.email', 'translation_domain' => 'FOSUserBundle'));
 
-        $user = $this->securityContext->getToken()->getUser();
-
-        $builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event) use ($user)
+        $builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event)
         {
-            if ( ! $user->getGithubId())
-            {
+            if ( ! ($user = $event->getData())) return;
+
+            if ( ! $user->getGithubId()) {
                 $this->addPasswordField($event);
             }
         });