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

Skip to content

Commit 2028461

Browse files
author
Adam Szaraniec
committed
Support for parsing PHP constants in yaml loader
1 parent 9d24e80 commit 2028461

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

src/Symfony/Component/Validator/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ CHANGELOG
1818
-----
1919

2020
* deprecated `Tests\Constraints\AbstractContraintValidatorTest` in favor of `Test\ConstraintValidatorTestCase`
21+
* added support for PHP constants in YAML configuration files
2122

2223
3.1.0
2324
-----

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ protected function parseNodes(array $nodes)
116116
private function parseFile($path)
117117
{
118118
try {
119-
$classes = $this->yamlParser->parse(file_get_contents($path), Yaml::PARSE_KEYS_AS_STRINGS);
119+
$classes = $this->yamlParser->parse(file_get_contents($path), Yaml::PARSE_KEYS_AS_STRINGS|Yaml::PARSE_CONSTANT);
120120
} catch (ParseException $e) {
121121
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $path), 0, $e);
122122
}

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

0 commit comments

Comments
 (0)