Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3c1961c

Browse filesBrowse files
minor #28513 [Validator] add exception when intl component not found (ronfroy)
This PR was squashed before being merged into the 4.2-dev branch (closes #28513). Discussion ---------- [Validator] add exception when intl component not found | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT <!-- Add some exception when the Intl component is not found but required on some constraints --> Commits ------- b6f29f4 [Validator] add exception when intl component not found
2 parents 6856c02 + b6f29f4 commit 3c1961c
Copy full SHA for 3c1961c

File tree

Expand file treeCollapse file tree

8 files changed

+42
-6
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+42
-6
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/BicValidator.php
+4-2Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/CountryValidator.php
+5Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/CurrencyValidator.php
+5Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/LanguageValidator.php
+5Lines 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

+16Lines 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 <fabien@symfony.com>
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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Mapping/Factory/BlackHoleMetadataFactory.php
+3-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Mapping/Factory/BlackHoleMetadataFactoryTest.php
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/ValidatorBuilder.php
+3-2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.