title: Creating a custom requirement validator for @Route annotation in Symfony
body: <p>As you can see below, my <code>@Route-&gt;requirements</code> regex below (I'm using it in many other controller/methods) is a bit long, doesn't look good and <strong>most importantly</strong> <em>it could be hard to maintain in the case of syntax update</em> in future so the question is, are we able to do something like below?</p>
  
  <p>I've seen many similar questions and tutorials for creating custom annotations but not something like this question.</p>
  
  <p><strong>CURRENT</strong></p>
  
  <pre><code>/**
   * @param string $id
   *
   * @Method({"GET"})
   * @Route("/class/{id}", requirements={"id"="([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}"})
   * @Secure(roles="ROLE_ADMIN")
   *
   * @return Response
   */
  public function getClassAction($id)
  </code></pre>
  
  <p><strong>MAYBE SOMETHING LIKE THIS</strong></p>
  
  <pre><code>/**
   * @param string $id
   *
   * @Method({"GET"})
   * @Route("/class/{id}", requirements={"id"="MyClass::MyValidation"})
   * @Secure(roles="ROLE_ADMIN")
   *
   * @return Response
   */
  public function getClassAction($id)
  </code></pre>
  
  <p><strong>MyClass</strong></p>
  
  <pre><code>MyClass
  {
       // Would be ideal to stick this into parameters.yml though
       const ID = "([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}";
  
       public function MyValidation($value)
       {
            if (!preg_match(self::ID, $value)) {
                 return 'Bad ID';
            }
  
            return true;
       }
  }
  </code></pre>