df3d543349
* 2.4: made types consistent with those defined in Hack made {@inheritdoc} annotations consistent across the board made {@inheritdoc} annotations consistent across the board fixed types in phpdocs [Debug] Fixed ClassNotFoundFatalErrorHandler on windows. made phpdoc types consistent with those defined in Hack Add support Thai translations [Validator] Add missing czech translations made types consistent with those defined in Hack removed extra/unsupported arguments [HttpKernel] fixed an error message [TwigBundle] removed undefined argument [Translation] Make IcuDatFileLoader/IcuResFileLoader::load invalid resource compatible with HHVM. Conflicts: src/Symfony/Component/Console/Helper/TableHelper.php src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php src/Symfony/Component/Form/FormError.php src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php src/Symfony/Component/Process/ProcessPipes.php src/Symfony/Component/PropertyAccess/PropertyAccessor.php src/Symfony/Component/Security/Acl/Dbal/MutableAclProvider.php src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeServices.php src/Symfony/Component/Translation/Dumper/FileDumper.php src/Symfony/Component/Validator/ConstraintViolation.php src/Symfony/Component/Validator/Constraints/EmailValidator.php src/Symfony/Component/Validator/ExecutionContextInterface.php src/Symfony/Component/Validator/Mapping/BlackholeMetadataFactory.php
76 lines
2.1 KiB
PHP
76 lines
2.1 KiB
PHP
<?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;
|
|
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
|
|
|
/**
|
|
* @author Manuel Reinhard <manu@sprain.ch>
|
|
* @author Michael Schummel
|
|
* @link http://www.michael-schummel.de/2007/10/05/iban-prufung-mit-php/
|
|
*/
|
|
class IbanValidator extends ConstraintValidator
|
|
{
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function validate($value, Constraint $constraint)
|
|
{
|
|
if (!$constraint instanceof Iban) {
|
|
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Iban');
|
|
}
|
|
|
|
if (null === $value || '' === $value) {
|
|
return;
|
|
}
|
|
|
|
// An IBAN without a country code is not an IBAN.
|
|
if (0 === preg_match('/[A-Z]/', $value)) {
|
|
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
|
|
|
|
return;
|
|
}
|
|
|
|
$teststring = preg_replace('/\s+/', '', $value);
|
|
|
|
if (strlen($teststring) < 4) {
|
|
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
|
|
|
|
return;
|
|
}
|
|
|
|
$teststring = substr($teststring, 4)
|
|
.strval(ord($teststring{0}) - 55)
|
|
.strval(ord($teststring{1}) - 55)
|
|
.substr($teststring, 2, 2);
|
|
|
|
$teststring = preg_replace_callback('/[A-Z]/', function ($letter) {
|
|
return intval(ord(strtolower($letter[0])) - 87);
|
|
}, $teststring);
|
|
|
|
$rest = 0;
|
|
$strlen = strlen($teststring);
|
|
for ($pos = 0; $pos < $strlen; $pos += 7) {
|
|
$part = strval($rest).substr($teststring, $pos, 7);
|
|
$rest = intval($part) % 97;
|
|
}
|
|
|
|
if ($rest != 1) {
|
|
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
|
|
|
|
return;
|
|
}
|
|
}
|
|
}
|