src/Form/Models/Publicite.php line 24

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * @author      Mehrez Labidi
  5.  * @Description il s'agit d'un modèle pour définir les différents validations utilisés dans le formulaire FormType
  6.  * Ce modèle n'interagit pas avec la base de  données
  7.  */
  8. namespace App\Form\Models;
  9. use App\Validator\Constraints\ContainsOnlyAlphabetic;
  10. use App\Validator\Constraints\ContainsOnlyNumeric;
  11. use App\Validator\Constraints\Nom;
  12. use App\Validator\Constraints\PhoneNumber;
  13. use App\Validator\Constraints\Prenom;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. use Symfony\Component\Validator\Constraints\IsTrue;
  16. use Symfony\Component\Validator\Constraints\NotBlank;
  17. use Symfony\Component\Validator\Mapping\ClassMetadata;
  18. use EWZ\Bundle\RecaptchaBundle\Validator\Constraints as Recaptcha;
  19. use App\Validator\Constraints\Message;
  20. class Publicite
  21. {
  22.     public $nom;
  23.     public $prenom;
  24.     public $mail;
  25.     public $societe;
  26.     public $telephone;
  27.     public $indicatif;
  28.     public $budget;
  29.     public $duree;
  30.     public $interesse_par;
  31.     public $commentaire;
  32.     /**
  33.      * @Recaptcha\IsTrue(message="captcha invalide")
  34.      */
  35.     public $recaptcha;
  36.     public static function loadValidatorMetadata(ClassMetadata $metadata)
  37.     {
  38.         $metadata->addPropertyConstraint('telephone', new PhoneNumber());
  39.         $metadata->addPropertyConstraint('nom', new Nom() );
  40.         $metadata->addPropertyConstraint('prenom', new Prenom());
  41.         $metadata->addPropertyConstraint('societe', new ContainsOnlyAlphabetic());
  42.         $metadata->addPropertyConstraint('nom', new NotBlank(['message' => 'le champ nom est obligatoire']));
  43.         $metadata->addPropertyConstraint('prenom', new NotBlank(['message' => 'le champ prenom est obligatoire']));
  44.         $metadata->addPropertyConstraint('societe', new NotBlank(['message' => 'le champ societe est obligatoire']));
  45.         $metadata->addPropertyConstraint('telephone', new NotBlank(['message' => 'le champ telephone est obligatoire']));
  46.         $metadata->addPropertyConstraint('mail', new NotBlank(['message' => 'le champ email est obligatoire']));
  47.         $metadata->addPropertyConstraint('mail', new Assert\Email(['message' => 'le champ email est invalide']));
  48.         $metadata->addPropertyConstraint('commentaire', new Message() );
  49.         $metadata->addPropertyConstraint('budget', new NotBlank(['message' => 'le champ budget est obligatoire']));
  50.         $metadata->addPropertyConstraint('duree', new NotBlank(['message' => 'le champ duree est obligatoire']));
  51.         $metadata->addPropertyConstraint('interesse_par', new NotBlank(['message' => 'le champ interesse par est obligatoire']));
  52.          
  53.         /**
  54.          * renfort de validation: voir ici:
  55.          * https://github.com/jbafford/PasswordStrengthBundle
  56.          */
  57.     }
  58.     /**
  59.      * @param $property
  60.      * @return mixed
  61.      */
  62.     public function _get($property)
  63.     {
  64.         return $this->$property;
  65.     }
  66.     /**
  67.      * Magic setter to save public properties.
  68.      * @param string $property
  69.      * @param mixed  $value
  70.      */
  71.     public function _set($property$value)
  72.     {
  73.         $this->$property $value;
  74.     }
  75. }