title: Symfony2, ERROR: Cannot validate values of type "string" automatically. Please provide a constraint
body: <p><strong>Symfony 2 ERROR: Cannot validate values of type "string" automatically. Please provide a constraint.</strong> </p>
  
  <p>I do not understand what constraint and where i have to provide?</p>
  
  <p>I am following example from book "Extending Symfony 2", chapter 4. I try to make custom annotation "ValidateUser" and use it on the Entity User property $phone. I also have "ValidUserListenerCustom" registered as a service, which redirects response of controller action  join4Action. This action is annotated with said custom annotation "@ValidateUser("join_event")". This action should add User to the Event only if User has mobile number in his profile.</p>
  
  <p>C:\Bitnami\wampstack-5.5.30-0\sym_prog\star\src\Yoda\UserBundle\Entity\User.php</p>
  
  <pre><code>/**
   * @ORM\Column(type="string", length=255, name="phone")
   * @Assert\NotBlank(groups={"join_event"})
  */
  protected $phone;
  </code></pre>
  
  <p>C:\Bitnami\wampstack-5.5.30-0\sym_prog\star\src\Yoda\UserBundle\Security\ValidUserListenerCustom.php</p>
  
  <pre><code>&lt;?php
  
  namespace Yoda\UserBundle\Security;
  
  use Doctrine\Common\Annotations\Reader;
  use Symfony\Bundle\FrameworkBundle\Routing\Router;
  use Symfony\Component\HttpFoundation\RedirectResponse;
  use Symfony\Component\HttpFoundation\Session\Session;
  use Symfony\Component\Security\Core\SecurityContext;
  use Symfony\Component\DependencyInjection\Container;
  use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
  
  
  class ValidUserListenerCustom
  {
      private $reader;
      private $annotation_name = 'Yoda\UserBundle\Security\Annotation\ValidateUser';
  
      private $router;
      private $session;
      private $sc;
      private $container;
  
      public function __construct(Reader $reader, Router $rou, Session $session, SecurityContext $sc, Container $cont)
      {
          /** @var AnnotationReader $reader */
          $this-&gt;reader = $reader;
  
          $this-&gt;router = $rou;
          $this-&gt;session = $session;
          $this-&gt;sc = $sc; //security.context
          $this-&gt;container = $cont; //container        
      }
  
      public function onKernelController(FilterControllerEvent $event)
      {
  
          $controller = $event-&gt;getController();
          if (!is_array($controller)) {
              return;
          }
          $class_name = get_class($event-&gt;getController()[0]);
          $method_name = $event-&gt;getController()[1];
  
          dump($class_name); // "Symfony\Bundle\WebProfilerBundle\Controller\ProfilerController"
          dump($method_name);
  
          $method = new \ReflectionMethod($class_name, $method_name);
          dump('method'); dump($method);
  
          // Read the annotation
          $annotation = $this-&gt;reader-&gt;getMethodAnnotation($method, $this-&gt;annotation_name);     
          dump($annotation);//null
  
          if (!is_null($annotation)) {
              // Retrieve the validation group from the annotation, and try to
              // validate the user
              $validation_group = $annotation-&gt;getValidationGroup();
  
              dump($validation_group);
  
              $user = $this-&gt;container-&gt;get('security.token_storage')-&gt;getToken()-&gt;getUser();            
              dump($user);
  
              $validator = $this-&gt;container-&gt;get('validator');
              dump($validator);
  
              $errors = $validator-&gt;validate($user);
              dump($errors);
              //original: $errors = $this-&gt;validator-&gt;validate($user, $validation_group);
  
              if (count($errors)) {
                  $event-&gt;setController(function(){
                      $this-&gt;session-&gt;getFlashBag()-&gt;add('warning', 'You must fill in your phone number before joining a meetup.');
                      return new RedirectResponse($this-&gt;router-&gt;generate(
                              'user_edit',
                              array ('id' =&gt; '1') ) );
                  });
              }
          }
      }
  }
  </code></pre>
  
  <p>C:\Bitnami\wampstack-5.5.30-0\sym_prog\star\src\Yoda\UserBundle\Security\Annotation\ValidateUser.php</p>
  
  <pre><code>&lt;?php
  
  namespace Yoda\UserBundle\Security\Annotation;
  
  //  Extending Symfony 2
  // annotation itself ...\src\Yoda\UserBundle\Security\Annotation\ValidateUSer.php
  // used in class ...src\Yoda\UserBundle\Entity\User.php
  // readed/analysed by ...src\Yoda\UserBundle\Security\Annotation\AnnotationServices\AnnotationDriver::loadMetadataForClass
  
  
  /**
   * @Annotation
   */
  class ValidateUser
  {
      private $validation_group;
  
      public function __construct(array $parameters)
      {
          $this-&gt;validation_group = $parameters['value'];
      }
  
      public function getValidationGroup()
      {
          return $this-&gt;validation_group;
      }
  }
  </code></pre>
  
  <p>C:\Bitnami\wampstack-5.5.30-0\sym_prog\star\src\Yoda\UserBundle\Resources\config\services.yml</p>
  
  <pre><code>yoda.user.security.valid_user_custom:
      class:      Yoda\UserBundle\Security\ValidUserListenerCustom
      arguments:  [@annotation_reader, @router, @session, @security.context, @service_container]
      tags:
          - { name: kernel.event_listener, event: kernel.controller, method: onKernelController }
  </code></pre>
  
  <p>Usage of custom annotation "ValidateUser" to check if user, who tries to join the event, has mobile number on his profile.</p>
  
  <p>url: <a href="http://127.0.0.1:8000/events/5/join4" rel="noreferrer">http://127.0.0.1:8000/events/5/join4</a></p>
  
  <p>C:\Bitnami\wampstack-5.5.30-0\sym_prog\star\src\Yoda\UserBundle\Controller\DefaultController.php</p>
  
  <pre><code>&lt;?php ...
  class DefaultController extends Controller
  { ...
  
      /**
       * @Route("/events/{event_id}/join4")
       * @Template()
       * @ValidateUser("join_event")
       */    
  public function join4Action($event_id) {
  
          //Chapter 4
          $reader = $this-&gt;get('annotation_reader');
          $method = new \ReflectionMethod(get_class($this), 'join4Action');
          $annotation_name = 'Yoda\UserBundle\Security\Annotation\ValidateUser';
          $annotation = $reader-&gt;getMethodAnnotations($method);
  
          //Chapter 1
          $em = $this-&gt;getDoctrine()-&gt;getManager();
          $meetup = $em-&gt;getRepository('EventBundle:Event')-&gt;find($event_id);
  
          $form = $this-&gt;createForm(new JoinEventType(), $meetup, array(
              'action' =&gt; '',
              'method' =&gt; 'POST',
          ));
          $form-&gt;add('submit', 'submit', array('label' =&gt; 'Join'));
  
          $form-&gt;handleRequest($this-&gt;get('request'));
  
          //Do not know how to make it to work, chec later
          //$user = $this-&gt;get('security.context')-&gt;getToken()-&gt;getUser();
          $user = $em-&gt;getRepository('UserBundle:User')-&gt;find('1');
  
          if ($form-&gt;isValid()) {
              $meetup-&gt;addAttendee($user);
              $this-&gt;get('event_dispatcher')-&gt;dispatch(MeetupEvents::MEETUP_JOIN, new MeetupEvent($user, $meetup));
              $em-&gt;flush();
          } 
  
          $form = $form-&gt;createView();
          return compact('meetup', 'user', 'form');
      }  
  </code></pre>