コード例 #1
0
ファイル: VatNumber.php プロジェクト: rayhan0421/accounting
 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;
 }
コード例 #2
0
ファイル: ViesValidator.php プロジェクト: rezzza/accounting
 /**
  * {@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;
     }
 }
コード例 #3
0
ファイル: VatValidator.php プロジェクト: rezzza/accounting
 /**
  * {@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();
     //}
     //}
 }