<?php
declare(strict_types=1);
/**
* @author Mehrez Labidi
* @Description il s'agit d'un modèle pour définir les différents validations utilisés dans le formulaire FormType
* Ce modèle n'interagit pas avec la base de données
*/
namespace App\Form\Models;
use App\Validator\Constraints\ContainsOnlyAlphabetic;
use App\Validator\Constraints\ContainsOnlyNumeric;
use App\Validator\Constraints\Nom;
use App\Validator\Constraints\PhoneNumber;
use App\Validator\Constraints\Prenom;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Constraints\IsTrue;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use EWZ\Bundle\RecaptchaBundle\Validator\Constraints as Recaptcha;
use App\Validator\Constraints\Message;
class Publicite
{
public $nom;
public $prenom;
public $mail;
public $societe;
public $telephone;
public $indicatif;
public $budget;
public $duree;
public $interesse_par;
public $commentaire;
/**
* @Recaptcha\IsTrue(message="captcha invalide")
*/
public $recaptcha;
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('telephone', new PhoneNumber());
$metadata->addPropertyConstraint('nom', new Nom() );
$metadata->addPropertyConstraint('prenom', new Prenom());
$metadata->addPropertyConstraint('societe', new ContainsOnlyAlphabetic());
$metadata->addPropertyConstraint('nom', new NotBlank(['message' => 'le champ nom est obligatoire']));
$metadata->addPropertyConstraint('prenom', new NotBlank(['message' => 'le champ prenom est obligatoire']));
$metadata->addPropertyConstraint('societe', new NotBlank(['message' => 'le champ societe est obligatoire']));
$metadata->addPropertyConstraint('telephone', new NotBlank(['message' => 'le champ telephone est obligatoire']));
$metadata->addPropertyConstraint('mail', new NotBlank(['message' => 'le champ email est obligatoire']));
$metadata->addPropertyConstraint('mail', new Assert\Email(['message' => 'le champ email est invalide']));
$metadata->addPropertyConstraint('commentaire', new Message() );
$metadata->addPropertyConstraint('budget', new NotBlank(['message' => 'le champ budget est obligatoire']));
$metadata->addPropertyConstraint('duree', new NotBlank(['message' => 'le champ duree est obligatoire']));
$metadata->addPropertyConstraint('interesse_par', new NotBlank(['message' => 'le champ interesse par est obligatoire']));
/**
* renfort de validation: voir ici:
* https://github.com/jbafford/PasswordStrengthBundle
*/
}
/**
* @param $property
* @return mixed
*/
public function _get($property)
{
return $this->$property;
}
/**
* Magic setter to save public properties.
* @param string $property
* @param mixed $value
*/
public function _set($property, $value)
{
$this->$property = $value;
}
}