Skip to content

Commit f694eda

Browse files
Merge pull request #1 from econoprint/dotenv-fixes
Symfony Dotenv Component Fixes
2 parents 864fe84 + b24831c commit f694eda

File tree

9 files changed

+322
-134
lines changed

9 files changed

+322
-134
lines changed

DataFixtures/Dumper/YamlDataDumper.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ protected function transformArrayToData($data)
2727
$data,
2828
$inline = 3,
2929
$indent = 4,
30-
$exceptionOnInvalidType = false,
31-
$objectSupport = true
30+
Yaml::DUMP_OBJECT
3231
);
3332
}
3433
}

DependencyInjection/Configuration.php

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
namespace Propel\Bundle\PropelBundle\DependencyInjection;
1111

1212
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
13+
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
1314
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1415
use Symfony\Component\Config\Definition\ConfigurationInterface;
16+
use Symfony\Component\HttpKernel\Kernel;
1517

1618
/**
1719
* This class contains the configuration information for the bundle
@@ -38,12 +40,20 @@ public function __construct($debug)
3840
/**
3941
* Generates the configuration tree builder.
4042
*
41-
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
43+
* @return TreeBuilder The tree builder
4244
*/
4345
public function getConfigTreeBuilder()
4446
{
47+
if (Kernel::MAJOR_VERSION > 4 || Kernel::MAJOR_VERSION === 4 && Kernel::MINOR_VERSION >= 2)
48+
{
49+
$treeBuilder = new TreeBuilder('propel');
50+
$rootNode = $treeBuilder->getRootNode();
51+
}
52+
else
53+
{
4554
$treeBuilder = new TreeBuilder();
4655
$rootNode = $treeBuilder->root('propel');
56+
}
4757

4858
$this->addGeneralSection($rootNode);
4959
$this->addDbalSection($rootNode);
@@ -100,6 +110,8 @@ private function addGeneralSection(ArrayNodeDefinition $node)
100110
*/
101111
private function addDbalSection(ArrayNodeDefinition $node)
102112
{
113+
$dNormalizer = new DriverNormalizer();
114+
$dClosure = function($v) use ($dNormalizer) { return $dNormalizer->normalize($v); };
103115
$node
104116
->children()
105117
->arrayNode('dbal')
@@ -112,7 +124,7 @@ private function addDbalSection(ArrayNodeDefinition $node)
112124
->scalarNode('driver')
113125
->beforeNormalization()
114126
->always()
115-
->then(function($v) { return str_replace('pdo_', '', $v); })
127+
->then($dClosure)
116128
->end()
117129
->defaultValue('mysql')
118130
->end()
@@ -121,7 +133,7 @@ private function addDbalSection(ArrayNodeDefinition $node)
121133
->scalarNode('dsn')
122134
->beforeNormalization()
123135
->always()
124-
->then(function($v) { return str_replace('pdo_', '', $v); })
136+
->then($dClosure)
125137
->end()
126138
->defaultValue('')
127139
->end()
@@ -145,14 +157,14 @@ private function addDbalSection(ArrayNodeDefinition $node)
145157
->children()
146158
->arrayNode('settings')
147159
->useAttributeAsKey('key')
148-
->prototype('array')
160+
->arrayPrototype()
149161
->useAttributeAsKey('key')
150162
->prototype('scalar')->end()
151163
->end()
152164
->end()
153165
->end()
154166
->fixXmlConfig('connection')
155-
->append($this->getDbalConnectionsNode())
167+
->append($this->getDbalConnectionsNode($dNormalizer))
156168
->end()
157169
;
158170
}
@@ -171,22 +183,32 @@ private function addDbalSection(ArrayNodeDefinition $node)
171183
* attributes: {}
172184
* settings: {}
173185
*
174-
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
186+
* @return ArrayNodeDefinition|NodeDefinition The tree builder
175187
*/
176-
private function getDbalConnectionsNode()
188+
private function getDbalConnectionsNode(DriverNormalizer $normalizer)
177189
{
178-
$treeBuilder = new TreeBuilder();
179-
$node = $treeBuilder->root('connections');
190+
$closure = function($v) use ($normalizer) { return $normalizer->normalize($v); };
191+
192+
if (Kernel::MAJOR_VERSION > 4 || Kernel::MAJOR_VERSION === 4 && Kernel::MINOR_VERSION >= 2)
193+
{
194+
$treeBuilder = new TreeBuilder('connections');
195+
$node = $treeBuilder->getRootNode();
196+
}
197+
else
198+
{
199+
$treeBuilder = new TreeBuilder();
200+
$node = $treeBuilder->root('connections');
201+
};
180202

181203
$node
182204
->requiresAtLeastOneElement()
183205
->useAttributeAsKey('name')
184-
->prototype('array')
206+
->arrayPrototype()
185207
->children()
186208
->scalarNode('driver')
187209
->beforeNormalization()
188210
->always()
189-
->then(function($v) { return str_replace('pdo_', '', $v); })
211+
->then($closure)
190212
->end()
191213
->defaultValue('mysql')
192214
->end()
@@ -195,19 +217,19 @@ private function getDbalConnectionsNode()
195217
->scalarNode('dsn')
196218
->beforeNormalization()
197219
->always()
198-
->then(function($v) { return str_replace('pdo_', '', $v); })
220+
->then($closure)
199221
->end()
200222
->defaultValue('')
201223
->end()
202224
->scalarNode('classname')->defaultValue($this->debug ? 'DebugPDO' : 'PropelPDO')->end()
203225
->arrayNode('slaves')
204226
->useAttributeAsKey('name')
205-
->prototype('array')
227+
->arrayPrototype()
206228
->children()
207229
->scalarNode('driver')
208230
->beforeNormalization()
209231
->always()
210-
->then(function($v) { return str_replace('pdo_', '', $v); })
232+
->then($closure)
211233
->end()
212234
->defaultValue('mysql')
213235
->end()
@@ -216,7 +238,7 @@ private function getDbalConnectionsNode()
216238
->scalarNode('dsn')
217239
->beforeNormalization()
218240
->always()
219-
->then(function($v) { return str_replace('pdo_', '', $v); })
241+
->then($closure)
220242
->end()
221243
->defaultValue('')
222244
->end()
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Propel\Bundle\PropelBundle\DependencyInjection;
4+
5+
/**
6+
* Provides normalization for Database Driver values.
7+
*
8+
* Class DriverNormalizer
9+
* @package Propel\Bundle\PropelBundle\DependencyInjection
10+
*/
11+
class DriverNormalizer
12+
{
13+
/**
14+
* Normalizes the database driver related keys in a Propel datasource configuration, specifically the 'adapter'
15+
* value & the dsn value of the connection configuration.
16+
*
17+
* @param array $datasource
18+
*
19+
* @return array
20+
*/
21+
public function normalizeDatasource($datasource)
22+
{
23+
if ($adapter = $datasource['adapter'] ?? null)
24+
{
25+
$datasource['adapter'] = $this->normalize($adapter);
26+
}
27+
28+
if ($dsn = $datasource['connection']['dsn'] ?? null)
29+
{
30+
$datasource['connection']['dsn'] = $this->normalize($dsn);
31+
}
32+
33+
return $datasource;
34+
}
35+
36+
/**
37+
* Removes the 'pdo_' prefix found in some database driver strings.
38+
*
39+
* @param string $value
40+
*
41+
* @return string
42+
*/
43+
public function normalize($value)
44+
{
45+
return str_replace('pdo_', '', $value);
46+
}
47+
}

DependencyInjection/EnvResolver.php

Lines changed: 0 additions & 80 deletions
This file was deleted.

DependencyInjection/PropelExtension.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ class PropelExtension extends Extension
2929
*/
3030
public function load(array $configs, ContainerBuilder $container)
3131
{
32-
// WORKAROUND for https://github.com/symfony/symfony/issues/27683 https://github.com/symfony/symfony/issues/40906
33-
// Note that this may require the clearing of the cache after a related ENV var is changed.
34-
$configs = (new EnvResolver($container))->resolve($configs);
35-
// END WORKAROUND
36-
3732
$configuration = $this->getConfiguration($configs, $container);
3833
$config = $this->processConfiguration($configuration, $configs);
3934

@@ -57,13 +52,8 @@ public function load(array $configs, ContainerBuilder $container)
5752
throw new \InvalidArgumentException('PropelBundle expects a "phing_path" parameter that must contain the absolute path to the Phing vendor library. The "phing_path" parameter must be defined under the "propel" root node in your configuration.');
5853
}
5954

60-
if (isset($config['logging']) && $config['logging']) {
61-
$logging = $config['logging'];
62-
} else {
63-
$logging = false;
64-
}
65-
66-
$container->setParameter('propel.logging', $logging);
55+
// Set Logging Parameters
56+
$container->setParameter('propel.logging', $config['logging'] ?? false);
6757

6858
if (!empty($config['schema_path']))
6959
{
@@ -92,7 +82,12 @@ public function load(array $configs, ContainerBuilder $container)
9282
}
9383
}
9484

95-
$container->getDefinition('propel.build_properties')->setArguments(array($buildProperties));
85+
// Store the build_properties configuration at compile time, rather than injecting into service for Properties
86+
// class. This prevents issues with resolution of environment variables, which must be resolved at runtime.
87+
// The synthetic service is then set in PropelBundle::boot(). See these issues for details of problem:
88+
// https://github.com/symfony/symfony/issues/27683
89+
// https://github.com/symfony/symfony/issues/40906
90+
$container->setParameter('propel.build_properties', $buildProperties);
9691

9792
if (!empty($config['dbal'])) {
9893
$this->dbalLoad($config['dbal'], $container);
@@ -143,7 +138,12 @@ protected function dbalLoad(array $config, ContainerBuilder $container)
143138
$c['datasources']['default'] = $connectionName;
144139
}
145140

146-
$container->getDefinition('propel.configuration')->setArguments(array($c));
141+
// Store the dbal configuration at compile time, rather than creating a service for the configuration object.
142+
// This prevents issues with resolution of environment variables, which must be resolved at runtime. The
143+
// synthetic service is then set in PropelBundle::boot(). See these issues for details of problem:
144+
// https://github.com/symfony/symfony/issues/27683
145+
// https://github.com/symfony/symfony/issues/40906
146+
$container->setParameter('propel.dbal', $c);
147147
}
148148

149149
public function getConfiguration(array $config, ContainerBuilder $container)

0 commit comments

Comments
 (0)