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

Skip to content

Commit 5a5ea8d

Browse files
author
Adam Szaraniec
committed
Support for parsing PHP constants in yaml loader
1 parent 89c3f5c commit 5a5ea8d

File tree

5 files changed

+84
-58
lines changed

5 files changed

+84
-58
lines changed

src/Symfony/Component/Validator/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* deprecated `Tests\Constraints\AbstractContraintValidatorTest` in favor of `Test\ConstraintValidatorTestCase`
8+
* added support for PHP constants in YAML configuration files
89

910
3.1.0
1011
-----

src/Symfony/Component/Validator/Mapping/Loader/YamlFileLoader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Validator\Mapping\ClassMetadata;
1515
use Symfony\Component\Yaml\Exception\ParseException;
1616
use Symfony\Component\Yaml\Parser as YamlParser;
17+
use Symfony\Component\Yaml\Yaml;
1718

1819
/**
1920
* Loads validation metadata from a YAML file.
@@ -115,7 +116,7 @@ protected function parseNodes(array $nodes)
115116
private function parseFile($path)
116117
{
117118
try {
118-
$classes = $this->yamlParser->parse(file_get_contents($path));
119+
$classes = $this->yamlParser->parse(file_get_contents($path), Yaml::PARSE_CONSTANT);
119120
} catch (ParseException $e) {
120121
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $path), 0, $e);
121122
}

src/Symfony/Component/Validator/Tests/Mapping/Loader/YamlFileLoaderTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,19 @@ public function testLoadClassMetadata()
124124
$this->assertEquals($expected, $metadata);
125125
}
126126

127+
public function testLoadClassMetadataWithConstants()
128+
{
129+
$loader = new YamlFileLoader(__DIR__.'/mapping-with-constants.yml');
130+
$metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
131+
132+
$loader->loadClassMetadata($metadata);
133+
134+
$expected = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
135+
$expected->addPropertyConstraint('firstName', new Range(array('max' => PHP_INT_MAX)));
136+
137+
$this->assertEquals($expected, $metadata);
138+
}
139+
127140
public function testLoadGroupSequenceProvider()
128141
{
129142
$loader = new YamlFileLoader(__DIR__.'/constraint-mapping.yml');
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespaces:
2+
custom: Symfony\Component\Validator\Tests\Fixtures\
3+
4+
Symfony\Component\Validator\Tests\Fixtures\Entity:
5+
properties:
6+
firstName:
7+
- Range:
8+
max: !php/const:PHP_INT_MAX
Lines changed: 60 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,64 @@
11
{
2-
"name": "symfony/validator",
3-
"type": "library",
4-
"description": "Symfony Validator Component",
5-
"keywords": [],
6-
"homepage": "https://symfony.com",
7-
"license": "MIT",
8-
"authors": [
9-
{
10-
"name": "Fabien Potencier",
11-
"email": "[email protected]"
12-
},
13-
{
14-
"name": "Symfony Community",
15-
"homepage": "https://symfony.com/contributors"
16-
}
17-
],
18-
"require": {
19-
"php": ">=5.5.9",
20-
"symfony/polyfill-mbstring": "~1.0",
21-
"symfony/translation": "~2.8|~3.0"
2+
"name": "symfony/validator",
3+
"type": "library",
4+
"description": "Symfony Validator Component",
5+
"keywords": [],
6+
"homepage": "https://symfony.com",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Fabien Potencier",
11+
"email": "[email protected]"
2212
},
23-
"require-dev": {
24-
"symfony/http-foundation": "~2.8|~3.0",
25-
"symfony/intl": "^2.8.18|^3.2.5",
26-
"symfony/yaml": "~2.8|~3.0",
27-
"symfony/config": "~2.8|~3.0",
28-
"symfony/expression-language": "~2.8|~3.0",
29-
"symfony/cache": "~3.1",
30-
"doctrine/annotations": "~1.0",
31-
"doctrine/cache": "~1.0",
32-
"egulias/email-validator": "^1.2.8|~2.0"
33-
},
34-
"conflict": {
35-
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0"
36-
},
37-
"suggest": {
38-
"psr/cache-implementation": "For using the metadata cache.",
39-
"doctrine/annotations": "For using the annotation mapping. You will also need doctrine/cache.",
40-
"doctrine/cache": "For using the default cached annotation reader and metadata cache.",
41-
"symfony/http-foundation": "",
42-
"symfony/intl": "",
43-
"symfony/yaml": "",
44-
"symfony/config": "",
45-
"egulias/email-validator": "Strict (RFC compliant) email validation",
46-
"symfony/property-access": "For using the Expression validator",
47-
"symfony/expression-language": "For using the Expression validator"
48-
},
49-
"autoload": {
50-
"psr-4": { "Symfony\\Component\\Validator\\": "" },
51-
"exclude-from-classmap": [
52-
"/Tests/"
53-
]
54-
},
55-
"minimum-stability": "dev",
56-
"extra": {
57-
"branch-alias": {
58-
"dev-master": "3.2-dev"
59-
}
13+
{
14+
"name": "Symfony Community",
15+
"homepage": "https://symfony.com/contributors"
16+
}
17+
],
18+
"require": {
19+
"php": ">=5.5.9",
20+
"symfony/polyfill-mbstring": "~1.0",
21+
"symfony/translation": "~2.8|~3.0"
22+
},
23+
"require-dev": {
24+
"symfony/http-foundation": "~2.8|~3.0",
25+
"symfony/intl": "^2.8.18|^3.2.5",
26+
"symfony/yaml": "~3.2",
27+
"symfony/config": "~2.8|~3.0",
28+
"symfony/expression-language": "~2.8|~3.0",
29+
"symfony/cache": "~3.1",
30+
"doctrine/annotations": "~1.0",
31+
"doctrine/cache": "~1.0",
32+
"egulias/email-validator": "^1.2.8|~2.0"
33+
},
34+
"conflict": {
35+
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0"
36+
},
37+
"suggest": {
38+
"psr/cache-implementation": "For using the metadata cache.",
39+
"doctrine/annotations": "For using the annotation mapping. You will also need doctrine/cache.",
40+
"doctrine/cache": "For using the default cached annotation reader and metadata cache.",
41+
"symfony/http-foundation": "",
42+
"symfony/intl": "",
43+
"symfony/yaml": "",
44+
"symfony/config": "",
45+
"egulias/email-validator": "Strict (RFC compliant) email validation",
46+
"symfony/property-access": "For using the Expression validator",
47+
"symfony/expression-language": "For using the Expression validator"
48+
},
49+
"conflict": {
50+
"symfony/yaml": "<3.2"
51+
},
52+
"autoload": {
53+
"psr-4": { "Symfony\\Component\\Validator\\": "" },
54+
"exclude-from-classmap": [
55+
"/Tests/"
56+
]
57+
},
58+
"minimum-stability": "dev",
59+
"extra": {
60+
"branch-alias": {
61+
"dev-master": "3.2-dev"
6062
}
63+
}
6164
}

0 commit comments

Comments
 (0)