title: Custom method annotation with parameter insertion symfony 3.2
body: <p>So, the goal is to make the custom annotation that could also insert the parameter into a method. So after hours of looking for a solution and trying to make it work, I never found a complete one, so I put together a few of what i could found, and my code looks like this:</p>
  
  <pre><code>public function onKernelController(FilterControllerEvent $event)
  {
      if (!is_array($controller = $event-&gt;getController())){
          return;
      }
  
      $request = $event-&gt;getRequest();
      $content = $request-&gt;getContent();
      $data = json_decode($content,true);
  
      $reflectionObject = new \ReflectionObject($controller[0]);
      $reflectionMethod = $reflectionObject-&gt;getMethod($controller[1]);
      $methodAnnotation = $this-&gt;reader-&gt;getMethodAnnotation($reflectionMethod, CheckRequest::class);
      if(!$methodAnnotation){
          return;
      }
      $propertyName = $methodAnnotation-&gt;getName();
  
      try{
          if ($request-&gt;getContentType() !== 'json' ) {
              throw new ControlerNotAvailableException();
          }
  
          if(empty($content)){
              throw new ControlerNotAvailableException();
          }
  
          if(empty($data) || !array_key_exists('type', $data)) {
              throw new ControlerNotAvailableException();
          }
      }catch(ControlerNotAvailableException $e){
      }
  
      foreach($reflectionMethod-&gt;getParameters() as $param){
          if($param-&gt;getName() !== $propertyName){
              continue;
          }
          if($request-&gt;attributes-&gt;has($propertyName)){
              return;
          }
          $request-&gt;attributes-&gt;set($propertyName, $data);
      }
  }
  </code></pre>
  
  <p>And my annotation class looks like this:</p>
  
  <pre><code>class CheckRequest
  {
  private $name;
  
  public function __construct($options)
  {
      if(isset($options['value'])){
          $options['name'] = $options['value'];
          unset($options['value']);
      }
      foreach ($options as $key =&gt; $value){
          if(!property_exists($this, $key)){
              throw new \InvalidArgumentException(sprintf('Property %s does not exist', $key));
          }
          $this-&gt;$key = $value;
      }
  }
  
  
  /**
   * @return mixed
   */
  public function getName()
  {
      return $this-&gt;name;
  }
  
  /**
   * @param mixed $name
   */
  public function setName($name)
  {
      $this-&gt;name = $name;
  }
  }
  </code></pre>
  
  <p>So to make this thing little more clear. I have a listener event which listens to kernel.controller event. In that listener i'm running some small chacks, like if the content-type is json, etc...Also, <code>ControllerNotAvailableEception</code> is the custom exception i made, so don't let that confuse you. We then get to the part where my question lies, and that is the following:</p>
  
  <pre><code>foreach($reflectionMethod-&gt;getParameters() as $param){
      if($param-&gt;getName() !== $propertyName){
          continue;
      }
      if($request-&gt;attributes-&gt;has($propertyName)){
          return;
      }
      $request-&gt;attributes-&gt;set($propertyName, $data);
  }
  </code></pre>
  
  <p>Now, just to clarify things, this works, and injects the value in method parameters properly, so in my controller if i put something like this:</p>
  
  <pre><code>/**
   *@CheckRequest(name = "data")
  */
   public function createAction(array $data){
   }
  </code></pre>
  
  <p>This works, and the $data parameter is populated.
  Finally when i explained all this, i can now ask my question.
  Is this the right way to do this, or are there some 'standardized' way of injecting the parameters value through annotations and could you give me the example? I know that the <code>@ParamConverter</code> annotation does theese kind of things, but i couldn't figure out how it binds value to parameter under the hood.
  Thank you in advance for your answers!</p>