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

Skip to content

[Validator] add exception when intl component not found #28513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2018
Merged

[Validator] add exception when intl component not found #28513

merged 1 commit into from
Sep 21, 2018

Conversation

ronfroy
Copy link
Contributor

@ronfroy ronfroy commented Sep 19, 2018

Q A
Branch? master
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
License MIT

@ronfroy ronfroy changed the title add exception when intl component not found [Validator] add exception when intl component not found Sep 19, 2018
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Here are some comments.

@@ -28,6 +29,10 @@ class CountryValidator extends ConstraintValidator
*/
public function validate($value, Constraint $constraint)
{
if (!class_exists('Intl')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be Intl::class instead.

@@ -28,6 +29,10 @@ class CountryValidator extends ConstraintValidator
*/
public function validate($value, Constraint $constraint)
{
if (!class_exists('Intl')) {
throw new RuntimeException('symfony/intl is required to use the Country constraint');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing dot at end of message, also I'd suggest to be a little bit more explicit (same in other messages below):
The "symfony/intl" component is required to use the Country constraint.

@ronfroy
Copy link
Contributor Author

ronfroy commented Sep 19, 2018

@nicolas-grekas fixed

@nicolas-grekas nicolas-grekas added this to the next milestone Sep 19, 2018
@@ -40,6 +41,10 @@ public function validate($value, Constraint $constraint)
throw new UnexpectedTypeException($value, 'string');
}

if (!class_exists(Intl::class)) {
throw new RuntimeException('The "symfony/intl" component is required to use the Country constraint.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, shouldn't it be a LogicException instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think not, this is not a logic issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at the code, we use LogicException quite often in similar situations, so could be worth for consistency at least (there are a few similar cases using RuntimeException, but they're not the majority and could be worth fixing)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have used RuntimeException too ... but if we use LogicException in similar situations, it's better to keep consistency. @ronfroy can you please update this? Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how can we use LogicException elsewhere if this PR introduces it as a new class?

For this case we use the RuntimeException already 👍

if (null === $this->expressionLanguage) {
if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {
throw new RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
}
$this->expressionLanguage = new ExpressionLanguage();
}
return $this->expressionLanguage;

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

if (!class_exists(Intl::class)) {
throw new RuntimeException('The "symfony/intl" component is required to use the Country constraint.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have used RuntimeException too ... but if we use LogicException in similar situations, it's better to keep consistency. @ronfroy can you please update this? Thanks!

@ronfroy
Copy link
Contributor Author

ronfroy commented Sep 20, 2018

done

@nicolas-grekas
Copy link
Member

can you update src/Symfony/Component/Validator/Constraints/BicValidator.php and src/Symfony/Component/Validator/Mapping/Factory/BlackHoleMetadataFactory.php to use the new exception also please?

@ronfroy
Copy link
Contributor Author

ronfroy commented Sep 21, 2018

@nicolas-grekas done

@nicolas-grekas
Copy link
Member

and src/Symfony/Component/Validator/ValidatorBuilder.php

@ro0NL
Copy link
Contributor

ro0NL commented Sep 21, 2018

for consitency we should change Runtime to Logic in EmailValidator, ExpressionValidator & ImageValidator too :)

@@ -17,7 +17,7 @@
class BlackHoleMetadataFactoryTest extends TestCase
{
/**
* @expectedException \LogicException
* @expectedException \Symfony\Component\Validator\Exception\LogicException;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about the trailing;

@@ -191,8 +192,8 @@ public function enableAnnotationMapping(Reader $annotationReader = null)
}

if (null === $annotationReader) {
if (!class_exists('Doctrine\Common\Annotations\AnnotationReader') || !class_exists('Doctrine\Common\Cache\ArrayCache')) {
throw new \RuntimeException('Enabling annotation based constraint mapping requires the packages doctrine/annotations and doctrine/cache to be installed.');
if (!class_exists(Doctrine\Common\Annotations\AnnotationReader::class) || !class_exists(Doctrine\Common\Cache\ArrayCache::class)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be moved as "use" statements.

@nicolas-grekas
Copy link
Member

for consitency we should change Runtime to Logic in EmailValidator, ExpressionValidator & ImageValidator too :)

in another PR :)

@nicolas-grekas
Copy link
Member

Thank you @ronfroy.

@nicolas-grekas nicolas-grekas merged commit b6f29f4 into symfony:master Sep 21, 2018
nicolas-grekas added a commit that referenced this pull request Sep 21, 2018
…(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
@ronfroy ronfroy deleted the add-exception-on-the-validator-component branch September 21, 2018 11:38
nicolas-grekas added a commit that referenced this pull request Sep 24, 2018
…ro0NL)

This PR was merged into the 4.2-dev branch.

Discussion
----------

Favor LogicException for missing classes & functions

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes-ish
| BC breaks?    | no-ish     <!-- see https://symfony.com/bc -->
| Deprecations? | no
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #28513 (comment)
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

<!--
Write a short README entry for your feature/bugfix here (replace this comment block.)
This will help people understand your PR and can be used as a start of the Doc PR.
Additionally:
 - Bug fixes must be submitted against the lowest branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against the master branch.
-->

Commits
-------

c762735 Favor LogicException for missing classes & functions
fabpot added a commit that referenced this pull request Sep 29, 2018
This PR was merged into the 4.2-dev branch.

Discussion
----------

[Form] Check for Intl availibility

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #...   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

Same as #28513 for the form component

Commits
-------

73c688c [Form] Check for Intl availibility
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.2 Nov 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants