8000 [Validator] Changed component to use the Intl component · symfony/symfony@01d0ee8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 01d0ee8

Browse files
committed
[Validator] Changed component to use the Intl component
1 parent 0c1fe39 commit 01d0ee8

File tree

8 files22

-30
lines changed

8 files changed

+22
-30
lines changed

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

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

1212
namespace Symfony\Component\Validator\Constraints;
1313

14+
use Symfony\Component\Intl\Intl;
1415
use Symfony\Component\Validator\Constraint;
1516
use Symfony\Component\Validator\ConstraintValidator;
1617
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
@@ -39,7 +40,7 @@ public function validate($value, Constraint $constraint)
3940

4041
$value = (string) $value;
4142

42-
if (!in_array($value, \Symfony\Component\Locale\Locale::getCountries())) {
43+
if (!in_array($value, array_keys(Intl::getRegionBundle()->getCountryNames(\Locale::getDefault())))) {
4344
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
4445
}
4546
}

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

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

1212
namespace Symfony\Component\Validator\Constraints;
1313

14+
use Symfony\Component\Intl\Intl;
1415
use Symfony\Component\Validator\Constraint;
1516
use Symfony\Component\Validator\ConstraintValidator;
1617
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
@@ -39,7 +40,7 @@ public function validate($value, Constraint $constraint)
3940

4041
$value = (string) $value;
4142

42-
if (!in_array($value, \Symfony\Component\Locale\Locale::getLanguages())) {
43+
if (!in_array($value, array_keys(Intl::getLanguageBundle()->getLanguageNames(\Locale::getDefault())))) {
4344
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
4445
}
4546
}

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

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

1212
namespace Symfony\Component\Validator\Constraints;
1313

14+
use Symfony\Component\Intl\Intl;
1415
use Symfony\Component\Validator\Constraint;
1516
use Symfony\Component\Validator\ConstraintValidator;
1617
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
@@ -38,8 +39,9 @@ public function validate($value, Constraint $constraint)
3839
}
3940

4041
$value = (string) $value;
42+
$locales = Intl::getLocaleBundle()->getLocaleNames(\Locale::getDefault());
4143

42-
if (!in_array($value, \Symfony\Component\Locale\Locale::getLocales())) {
44+
if (!isset($locales[$value])) {
4345
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
4446
}
4547
}

src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ public function testExpectsStringCompatibleType()
6363
*/
6464
public function testValidCountries($country)
6565
{
66-
if (!class_exists('Symfony\Component\Locale\Locale')) {
67-
$this->markTestSkipped('The "Locale" component is not available');
68-
}
69-
7066
$this->context->expects($this->never())
7167
->method('addViolation');
7268

@@ -87,10 +83,6 @@ public function getValidCountries()
8783
*/
8884
public function testInvalidCountries($country)
8985
{
90-
if (!class_exists('Symfony\Component\Locale\Locale')) {
91-
$this->markTestSkipped('The "Locale" component is not available');
92-
}
93-
9486
$constraint = new Country(array(
9587
'message' => 'myMessage'
9688
));

src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ public function testExpectsStringCompatibleType()
6363
*/
6464
public function testValidLanguages($language)
6565
{
66-
if (!class_exists('Symfony\Component\Locale\Locale')) {
67-
$this->markTestSkipped('The "Locale" component is not available');
68-
}
69-
7066
$this->context->expects($this->never())
7167
->method('addViolation');
7268

@@ -87,10 +83,6 @@ public function getValidLanguages()
8783
*/
8884
public function testInvalidLanguages($language)
8985
{
90-
if (!class_exists('Symfony\Component\Locale\Locale')) {
91-
$this->markTestSkipped('The "Locale" component is not available');
92-
}
93-
9486
$constraint = new Language(array(
9587
'message' => 'myMessage'
9688
));

src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ public function testExpectsStringCompatibleType()
6363
*/
6464
public function testValidLocales($locale)
6565
{
66-
if (!class_exists('Symfony\Component\Locale\Locale')) {
67-
$this->markTestSkipped('The "Locale" component is not available');
68-
}
69-
7066
$this->context->expects($this->never())
7167
->method('addViolation');
7268

@@ -89,10 +85,6 @@ public function getValidLocales()
8985
*/
9086
public function testInvalidLocales($locale)
9187
{
92-
if (!class_exists('Symfony\Component\Locale\Locale')) {
93-
$this->markTestSkipped('The "Locale" component is not available');
94-
}
95-
9688
$constraint = new Locale(array(
9789
'message' => 'myMessage'
9890
));

src/Symfony/Component/Validator/Tests/Constraints/LocalizedTestCase.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,24 @@
1111

1212
namespace Symfony\Component\Validator\Tests\Constraints;
1313

14+
use Symfony\Component\Intl\Intl;
15+
1416
abstract class LocalizedTestCase extends \PHPUnit_Framework_TestCase
1517
{
1618
protected function setUp()
1719
{
18-
if (!extension_loaded('intl')) {
20+
parent::setUp();
21+
22+
if (!class_exists('Symfony\Component\Intl\Intl')) {
23+
$this->markTestSkipped('The "Intl" component is not available');
24+
}
25+
26+
if (!Intl::isExtensionLoaded()) {
1927
$this->markTestSkipped('The "intl" extension is not available');
2028
}
29+
30+
Intl::setDataSource(Intl::STUB);
31+
32+
\Locale::setDefault('en');
2133
}
2234
}

src/Symfony/Component/Validator/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
},
2222
"require-dev": {
2323
"symfony/http-foundation": "~2.1",
24-
"symfony/locale": "~2.0",
24+
"symfony/intl": "~2.3",
2525
"symfony/yaml": "~2.0",
2626
"symfony/config": ">=2.2,<2.4-dev"
2727
},
2828
"suggest": {
2929
"doctrine/common": "~2.2",
3030
"symfony/http-foundation": "2.2.*",
31-
"symfony/locale": "2.2.*",
31+
"symfony/intl": "2.3.*",
3232
"symfony/yaml": "2.2.*",
3333
"symfony/config": "2.2.*"
3434
},

0 commit comments

Comments
 (0)
0