Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b6f29f4

Browse files
ronfroynicolas-grekas
authored andcommitted
[Validator] add exception when intl component not found
1 parent 6856c02 commit b6f29f4

File tree

8 files changed

+42
-6
lines changed

8 files changed

+42
-6
lines changed

src/Symfony/Component/Validator/Constraints/BicValidator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Intl\Intl;
1515
use Symfony\Component\Validator\Constraint;
1616
use Symfony\Component\Validator\ConstraintValidator;
17+
use Symfony\Component\Validator\Exception\LogicException;
1718
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
1819

1920
/**
@@ -68,10 +69,11 @@ public function validate($value, Constraint $constraint)
6869
return;
6970
}
7071

71-
// next 2 letters must be alphabetic (country code)
7272
if (!class_exists(Intl::class)) {
73-
throw new \LogicException('The "symfony/intl" component is required to use the Bic constraint.');
73+
throw new LogicException('The "symfony/intl" component is required to use the Bic constraint.');
7474
}
75+
76+
// next 2 letters must be alphabetic (country code)
7577
$countries = Intl::getRegionBundle()->getCountryNames();
7678
if (!isset($countries[substr($canonicalize, 4, 2)])) {
7779
$this->context->buildViolation($constraint->message)

src/Symfony/Component/Validator/Constraints/CountryValidator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Intl\Intl;
1515
use Symfony\Component\Validator\Constraint;
1616
use Symfony\Component\Validator\ConstraintValidator;
17+
use Symfony\Component\Validator\Exception\LogicException;
1718
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
1819

1920
/**
@@ -40,6 +41,10 @@ public function validate($value, Constraint $constraint)
4041
throw new UnexpectedTypeException($value, 'string');
4142
}
4243

44+
if (!class_exists(Intl::class)) {
45+
throw new LogicException('The "symfony/intl" component is required to use the Country constraint.');
46+
}
47+
4348
$value = (string) $value;
4449
$countries = Intl::getRegionBundle()->getCountryNames();
4550

src/Symfony/Component/Validator/Constraints/CurrencyValidator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Intl\Intl;
1515
use Symfony\Component\Validator\Constraint;
1616
use Symfony\Component\Validator\ConstraintValidator;
17+
use Symfony\Component\Validator\Exception\LogicException;
1718
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
1819

1920
/**
@@ -41,6 +42,10 @@ public function validate($value, Constraint $constraint)
4142
throw new UnexpectedTypeException($value, 'string');
4243
}
4344

45+
if (!class_exists(Intl::class)) {
46+
throw new LogicException('The "symfony/intl" component is required to use the Currency constraint.');
47+
}
48+
4449
$value = (string) $value;
4550
$currencies = Intl::getCurrencyBundle()->getCurrencyNames();
4651

src/Symfony/Component/Validator/Constraints/LanguageValidator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Intl\Intl;
1515
use Symfony\Component\Validator\Constraint;
1616
use Symfony\Component\Validator\ConstraintValidator;
17+
use Symfony\Component\Validator\Exception\LogicException;
1718
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
1819

1920
/**
@@ -40,6 +41,10 @@ public function validate($value, Constraint $constraint)
4041
throw new UnexpectedTypeException($value, 'string');
4142
}
4243

44+
if (!class_exists(Intl::class)) {
45+
throw new LogicException('The "symfony/intl" component is required to use the Language constraint.');
46+
}
47+
4348
$value = (string) $value;
4449
$languages = Intl::getLanguageBundle()->getLanguageNames();
4550

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Validator\Exception;
13+
14+
class LogicException extends \LogicException implements ExceptionInterface
15+
{
16+
}

src/Symfony/Component/Validator/Mapping/Factory/BlackHoleMetadataFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Validator\Mapping\Factory;
1313

14+
use Symfony\Component\Validator\Exception\LogicException;
15+
1416
/**
1517
* Metadata factory that does not store metadata.
1618
*
@@ -27,7 +29,7 @@ class BlackHoleMetadataFactory implements MetadataFactoryInterface
2729
*/
2830
public function getMetadataFor($value)
2931
{
30-
throw new \LogicException('This class does not support metadata.');
32+
throw new LogicException('This class does not support metadata.');
3133
}
3234

3335
/**

src/Symfony/Component/Validator/Tests/Mapping/Factory/BlackHoleMetadataFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
class BlackHoleMetadataFactoryTest extends TestCase
1818
{
1919
/**
20-
* @expectedException \LogicException
20+
* @expectedException \Symfony\Component\Validator\Exception\LogicException
2121
*/
2222
public function testGetMetadataForThrowsALogicException()
2323
{

src/Symfony/Component/Validator/ValidatorBuilder.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Doctrine\Common\Cache\ArrayCache;
1818
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
1919
use Symfony\Component\Validator\Context\ExecutionContextFactory;
20+
use Symfony\Component\Validator\Exception\LogicException;
2021
use Symfony\Component\Validator\Exception\ValidatorException;
2122
use Symfony\Component\Validator\Mapping\Cache\CacheInterface;
2223
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
@@ -191,8 +192,8 @@ public function enableAnnotationMapping(Reader $annotationReader = null)
191192
}
192193

193194
if (null === $annotationReader) {
194-
if (!class_exists('Doctrine\Common\Annotations\AnnotationReader') || !class_exists('Doctrine\Common\Cache\ArrayCache')) {
195-
throw new \RuntimeException('Enabling annotation based constraint mapping requires the packages doctrine/annotations and doctrine/cache to be installed.');
195+
if (!class_exists(AnnotationReader::class) || !class_exists(ArrayCache::class)) {
196+
throw new LogicException('Enabling annotation based constraint mapping requires the packages doctrine/annotations and doctrine/cache to be installed.');
196197
}
197198

198199
$annotationReader = new CachedReader(new AnnotationReader(), new ArrayCache());

0 commit comments

Comments
 (0)