Exemple #1
0
 protected function testValidCountryCodeDataProvider()
 {
     $countryCodes = array();
     $vatNumber = new TestedVatNumber();
     foreach ($vatNumber->getCountryCodes() as $countryCode) {
         $countryCodes[] = array($countryCode, $countryCode);
         $countryCodes[] = array((string) new TestedVatNumber($countryCode, '1'), $countryCode);
         if ('EL' === $countryCode) {
             $countryCodes[] = array('GR', 'EL');
             $countryCodes[] = array((string) new TestedVatNumber('GR', '1'), 'EL');
         }
     }
     return $countryCodes;
 }
Exemple #2
0
 /**
  * {@inheritDoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (null === $value || '' === $value) {
         return;
     }
     $vatNumber = new VatNumber();
     try {
         $value = (string) $vatNumber->fromString($value);
     } catch (\InvalidArgumentException $e) {
         throw new UnexpectedTypeException($value, 'string');
     }
     try {
         $result = $this->getSoapClient()->checkVat(array('countryCode' => $vatNumber->getCountryCode(), 'vatNumber' => $vatNumber->getNumber()));
         if ($result->valid != 1) {
             $this->context->addViolation($constraint->message, array('{{ countryCode }}' => $vatNumber->getCountryCode()));
         }
     } catch (\SoapException $e) {
         $this->context->addViolation($constraint->remoteError);
         throw $e;
     }
 }
Exemple #3
0
 /**
  * {@inheritDoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (null === $value || '' === $value) {
         return;
     }
     $vatNumber = new VatNumber();
     try {
         $value = (string) $vatNumber->fromString($value);
     } catch (\InvalidArgumentException $e) {
         throw new UnexpectedTypeException($value, 'string');
     } catch (Vat\InvalidCountryCodeException $e) {
         $this->context->addViolation($constraint->incorrectCountryCodeMessage, array('{{ countryCode }}' => $vatNumber->getCountryCode()));
     } catch (Vat\InvalidNumberException $e) {
         $this->context->addViolation($constraint->invalidMessage);
     }
     $pattern = $vatNumber->getPattern($vatNumber->getCountryCode());
     if (null !== $pattern && !preg_match($pattern, $vatNumber->getNumber())) {
         $this->context->addViolation($constraint->invalidMessage);
     }
     //$validateForCountryCB = 'validateForCountry'.$vatNumber->getCountryCode();
     //if (method_exists($this, $validateForCountryCB)) {
     //if (!$this->$validateForCountryCB($vatNumber)) {
     ////
     //$this->context->addViolation();
     //}
     //}
 }