Move into nested docroot
This commit is contained in:
parent
83a0d3a149
commit
c8b70abde9
13405 changed files with 0 additions and 0 deletions
85
web/vendor/symfony/validator/Constraints/BicValidator.php
vendored
Normal file
85
web/vendor/symfony/validator/Constraints/BicValidator.php
vendored
Normal file
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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 <michael.vhirsch@gmail.com>
|
||||
*
|
||||
* @link 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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue