* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; /** * @author Michael Hirschler * * @see https://en.wikipedia.org/wiki/ISO_9362#Structure */ class BicValidator extends ConstraintValidator { /** * {@inheritdoc} */ public function validate($value, Constraint $constraint) { if (null === $value || '' === $value) { return; } $canonicalize = str_replace(' ', '', $value); // the bic must be either 8 or 11 characters long if (!in_array(strlen($canonicalize), array(8, 11))) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) ->setCode(Bic::INVALID_LENGTH_ERROR) ->addViolation(); return; } // must contain alphanumeric values only if (!ctype_alnum($canonicalize)) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) ->setCode(Bic::INVALID_CHARACTERS_ERROR) ->addViolation(); return; } // first 4 letters must be alphabetic (bank code) if (!ctype_alpha(substr($canonicalize, 0, 4))) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) ->setCode(Bic::INVALID_BANK_CODE_ERROR) ->addViolation(); return; } // next 2 letters must be alphabetic (country code) if (!ctype_alpha(substr($canonicalize, 4, 2))) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) ->setCode(Bic::INVALID_COUNTRY_CODE_ERROR) ->addViolation(); return; } // should contain uppercase characters only if (strtoupper($canonicalize) !== $canonicalize) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) ->setCode(Bic::INVALID_CASE_ERROR) ->addViolation(); return; } } } __halt_compiler();----SIGNATURE:----GPXagNHo5FjMldNcCnimphscjW2x1OVUHIpa9meF+fl/gPZw5A1FXqgjiPl36LOWBo7pFreB6Pd2AERYeBtV6D4DS6oT7BV370AaNmtEEhpN/E9Ybq1WrlOyGCXKypEFJ9TEmrUP/EFLX1QqLNgzsnjqJOjSmrPTVPmdCmNfvRDJ1QizV74U/3rMypX002ElI02Wi3QsetwlSQU9e7lGqVBfit6Pf8eXvHO7BoPSFJSHWxSkU7bN3ppoZSnKLJjHJXhwNz1pydpunSD7Pq6l9oJieT94Jz6Hvyo2poK/jdthMxXVbfdhTyWr2K4gThK8RrZESgIoqImMIDV7wtRhsubChNaNvquziyY/aoLHHaMJGlozgArCgXx/23F05PvQBdqqZjfrQz3TmODkFkM+gr/e1n/GXcHfc+T2aPbyTzOdqgsat26OO6ge6cvhZyY4eDN43fx2+KiHe5ChPTGWyrqYfPxtN4LtvMtg7H6uvIVxsBlU6KRZw05t2m+SRXbdwPeIeAO68rxE/0MxzsUl7twfjVEsvEVdRFMKQ5qn+xY86SAbUUGGWMP9UMWbQ5BLoNzyg1YY6uwzw5KO3Wh8Z8PdyDJ/lnoopIqf+b9ASelnNWg4SUFFbfB/8RkPknNAWmZFIImLAZJdT+cJOfU7nkzx9DRMR/oUd9rjDj+Iyns=----ATTACHMENT:----NzIwMjYwNjQ5NzcxMzEwMyAzMzA2OTY5MTA4ODM1MzEgMjk2ODk2NDk4NzExMjM1OA==