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 37afeea

Browse filesBrowse files
author
Adam Szaraniec
committed
Support for parsing PHP constants in yaml loader
1 parent 9d24e80 commit 37afeea
Copy full SHA for 37afeea

File tree

4 files changed

+23
-1
lines changed
Filter options

4 files changed

+23
-1
lines changed

‎src/Symfony/Component/Validator/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/CHANGELOG.md
+1Lines 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

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

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