8000 [DI] added support for PHP constants in yaml configuration files · symfony/symfony@4f861c0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4f861c0

Browse files
committed
[DI] added support for PHP constants in yaml configuration files
1 parent 902eb0b commit 4f861c0

File tree

5 files changed

+10
-4
lines changed

5 files changed

+10
-4
lines changed

src/Symfony/Component/DependencyInjection/CHANGELOG.md

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

77
* allowed to prioritize compiler passes by introducing a third argument to `PassConfig::addPass()`, to `Compiler::addPass` and to `ContainerBuilder::addCompilerPass()`
8+
* added support for PHP constants in YAML configuration files
89

910
3.0.0
1011
-----

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Component\Config\Resource\FileResource;
2222
use Symfony\Component\Yaml\Exception\ParseException;
2323
use Symfony\Component\Yaml\Parser as YamlParser;
24+
use Symfony\Component\Yaml\Yaml;
2425
use Symfony\Component\ExpressionLanguage\Expression;
2526

2627
/**
@@ -366,7 +367,7 @@ protected function loadFile($file)
366367
}
367368

368369
try {
369-
$configuration = $this->yamlParser->parse(file_get_contents($file));
370+
$configuration = $this->yamlParser->parse(file_get_contents($file), Yaml::PARSE_CONSTANT);
370371
} catch (ParseException $e) {
371372
throw new InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $file), 0, $e);
372373
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services2.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ parameters:
55
- false
66
- 0
77
- 1000.3
8+
- !php/const:PHP_INT_MAX
89
bar: foo
910
escape: '@@escapeme'
1011
foo_bar: '@foo_bar'

src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function testLoadParameters()
9797
$container = new ContainerBuilder();
9898
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
9999
$loader->load('services2.yml');
100-
$this->assertEquals(array('foo' => 'bar', 'mixedcase' => array('MixedCaseKey' => 'value'), 'values' => array(true, false, 0, 1000.3), 'bar' => 'foo', 'escape' => '@escapeme', 'foo_bar' => new Reference('foo_bar')), $container->getParameterBag()->all(), '->load() converts YAML keys to lowercase');
100+
$this->assertEquals(array('foo' => 'bar', 'mixedcase' => array('MixedCaseKey' => 'value'), 'values' => array(true, false, 0, 1000.3, PHP_INT_MAX), 'bar' => 'foo', 'escape' => '@escapeme', 'foo_bar' => new Reference('foo_bar')), $container->getParameterBag()->all(), '->load() converts YAML keys to lowercase');
101101
}
102102

103103
public function testLoadImports()
@@ -113,7 +113,7 @@ public function testLoadImports()
113113
$loader->load('services4.yml');
114114

115115
$actual = $container->getParameterBag()->all();
116-
$expected = array('foo' => 'bar', 'values' => array(true, false), 'bar' => '%foo%', 'escape' => '@escapeme', 'foo_bar' => new Reference('foo_bar'), 'mixedcase' => array('MixedCaseKey' => 'value'), 'imported_from_ini' => true, 'imported_from_xml' => true);
116+
$expected = array('foo' => 'bar', 'values' => array(true, false, PHP_INT_MAX), 'bar' => '%foo%', 'escape' => '@escapeme', 'foo_bar' => new Reference('foo_bar'), 'mixedcase' => array('MixedCaseKey' => 'value'), 'imported_from_ini' => true, 'imported_from_xml' => true);
117117
$this->assertEquals(array_keys($expected), array_keys($actual), '->load() imports and merges imported files');
118118

119119
// Bad import throws no exception due to ignore_errors value.

src/Symfony/Component/DependencyInjection/composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": ">=5.5.9"
2020
},
2121
"require-dev": {
22-
"symfony/yaml": "~2.8|~3.0",
22+
"symfony/yaml": "~3.2",
2323
"symfony/config": "~2.8|~3.0",
2424
"symfony/expression-language": "~2.8|~3.0"
2525
},
@@ -29,6 +29,9 @@
2929
"symfony/expression-language": "For using expressions in service container configuration",
3030
"symfony/proxy-manager-bridge": "Generate service proxies to lazy load them"
3131
},
32+
"conflict": {
33+
"symfony/yaml": "<3.2"
34+
},
3235
"autoload": {
3336
"psr-4": { "Symfony\\Component\\DependencyInjection\\": "" },
3437
"exclude-from-classmap": [

0 commit comments

Comments
 (0)
0