Creating a custom requirement validator for @Route annotation in Symfony -


as can see below, @route->requirements regex below (i'm using in many other controller/methods) bit long, doesn't , most importantly it hard maintain in case of syntax update in future question is, able below?

i've seen many similar questions , tutorials creating custom annotations not question.

current

/**  * @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) 

maybe this

/**  * @param string $id  *  * @method({"get"})  * @route("/class/{id}", requirements={"id"="myclass::myvalidation"})  * @secure(roles="role_admin")  *  * @return response  */ public function getclassaction($id) 

myclass

myclass {      // ideal stick 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;      } } 

you should use pattern directly follow :

<?php  use x\y\z\myclass;  class xyz {  /**  * @param string $id  *  * @method({"get"})  * @route("/class/{id}", requirements={"id":myclass::id})  * @secure(roles="role_admin")  *  * @return response  */ public function getclassaction($id) 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -