Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions DataFixtures/Dumper/YamlDataDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ protected function transformArrayToData($data)
$data,
$inline = 3,
$indent = 4,
$exceptionOnInvalidType = false,
$objectSupport = true
Yaml::DUMP_OBJECT
);
}
}
52 changes: 37 additions & 15 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
namespace Propel\Bundle\PropelBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\HttpKernel\Kernel;

/**
* This class contains the configuration information for the bundle
Expand All @@ -38,12 +40,20 @@ public function __construct($debug)
/**
* Generates the configuration tree builder.
*
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
* @return TreeBuilder The tree builder
*/
public function getConfigTreeBuilder()
{
if (Kernel::MAJOR_VERSION > 4 || Kernel::MAJOR_VERSION === 4 && Kernel::MINOR_VERSION >= 2)
{
$treeBuilder = new TreeBuilder('propel');
$rootNode = $treeBuilder->getRootNode();
}
else
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('propel');
}

$this->addGeneralSection($rootNode);
$this->addDbalSection($rootNode);
Expand Down Expand Up @@ -100,6 +110,8 @@ private function addGeneralSection(ArrayNodeDefinition $node)
*/
private function addDbalSection(ArrayNodeDefinition $node)
{
$dNormalizer = new DriverNormalizer();
$dClosure = function($v) use ($dNormalizer) { return $dNormalizer->normalize($v); };
$node
->children()
->arrayNode('dbal')
Expand All @@ -112,7 +124,7 @@ private function addDbalSection(ArrayNodeDefinition $node)
->scalarNode('driver')
->beforeNormalization()
->always()
->then(function($v) { return str_replace('pdo_', '', $v); })
->then($dClosure)
->end()
->defaultValue('mysql')
->end()
Expand All @@ -121,7 +133,7 @@ private function addDbalSection(ArrayNodeDefinition $node)
->scalarNode('dsn')
->beforeNormalization()
->always()
->then(function($v) { return str_replace('pdo_', '', $v); })
->then($dClosure)
->end()
->defaultValue('')
->end()
Expand All @@ -145,14 +157,14 @@ private function addDbalSection(ArrayNodeDefinition $node)
->children()
->arrayNode('settings')
->useAttributeAsKey('key')
->prototype('array')
->arrayPrototype()
->useAttributeAsKey('key')
->prototype('scalar')->end()
->end()
->end()
->end()
->fixXmlConfig('connection')
->append($this->getDbalConnectionsNode())
->append($this->getDbalConnectionsNode($dNormalizer))
->end()
;
}
Expand All @@ -171,22 +183,32 @@ private function addDbalSection(ArrayNodeDefinition $node)
* attributes: {}
* settings: {}
*
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
* @return ArrayNodeDefinition|NodeDefinition The tree builder
*/
private function getDbalConnectionsNode()
private function getDbalConnectionsNode(DriverNormalizer $normalizer)
{
$treeBuilder = new TreeBuilder();
$node = $treeBuilder->root('connections');
$closure = function($v) use ($normalizer) { return $normalizer->normalize($v); };

if (Kernel::MAJOR_VERSION > 4 || Kernel::MAJOR_VERSION === 4 && Kernel::MINOR_VERSION >= 2)
{
$treeBuilder = new TreeBuilder('connections');
$node = $treeBuilder->getRootNode();
}
else
{
$treeBuilder = new TreeBuilder();
$node = $treeBuilder->root('connections');
};

$node
->requiresAtLeastOneElement()
->useAttributeAsKey('name')
->prototype('array')
->arrayPrototype()
->children()
->scalarNode('driver')
->beforeNormalization()
->always()
->then(function($v) { return str_replace('pdo_', '', $v); })
->then($closure)
->end()
->defaultValue('mysql')
->end()
Expand All @@ -195,19 +217,19 @@ private function getDbalConnectionsNode()
->scalarNode('dsn')
->beforeNormalization()
->always()
->then(function($v) { return str_replace('pdo_', '', $v); })
->then($closure)
->end()
->defaultValue('')
->end()
->scalarNode('classname')->defaultValue($this->debug ? 'DebugPDO' : 'PropelPDO')->end()
->arrayNode('slaves')
->useAttributeAsKey('name')
->prototype('array')
->arrayPrototype()
->children()
->scalarNode('driver')
->beforeNormalization()
->always()
->then(function($v) { return str_replace('pdo_', '', $v); })
->then($closure)
->end()
->defaultValue('mysql')
->end()
Expand All @@ -216,7 +238,7 @@ private function getDbalConnectionsNode()
->scalarNode('dsn')
->beforeNormalization()
->always()
->then(function($v) { return str_replace('pdo_', '', $v); })
->then($closure)
->end()
->defaultValue('')
->end()
Expand Down
47 changes: 47 additions & 0 deletions DependencyInjection/DriverNormalizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Propel\Bundle\PropelBundle\DependencyInjection;

/**
* Provides normalization for Database Driver values.
*
* Class DriverNormalizer
* @package Propel\Bundle\PropelBundle\DependencyInjection
*/
class DriverNormalizer
{
/**
* Normalizes the database driver related keys in a Propel datasource configuration, specifically the 'adapter'
* value & the dsn value of the connection configuration.
*
* @param array $datasource
*
* @return array
*/
public function normalizeDatasource($datasource)
{
if ($adapter = $datasource['adapter'] ?? null)
{
$datasource['adapter'] = $this->normalize($adapter);
}

if ($dsn = $datasource['connection']['dsn'] ?? null)
{
$datasource['connection']['dsn'] = $this->normalize($dsn);
}

return $datasource;
}

/**
* Removes the 'pdo_' prefix found in some database driver strings.
*
* @param string $value
*
* @return string
*/
public function normalize($value)
{
return str_replace('pdo_', '', $value);
}
}
80 changes: 0 additions & 80 deletions DependencyInjection/EnvResolver.php

This file was deleted.

28 changes: 14 additions & 14 deletions DependencyInjection/PropelExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ class PropelExtension extends Extension
*/
public function load(array $configs, ContainerBuilder $container)
{
// WORKAROUND for https://github.com/symfony/symfony/issues/27683 https://github.com/symfony/symfony/issues/40906
// Note that this may require the clearing of the cache after a related ENV var is changed.
$configs = (new EnvResolver($container))->resolve($configs);
// END WORKAROUND

$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);

Expand All @@ -57,13 +52,8 @@ public function load(array $configs, ContainerBuilder $container)
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.');
}

if (isset($config['logging']) && $config['logging']) {
$logging = $config['logging'];
} else {
$logging = false;
}

$container->setParameter('propel.logging', $logging);
// Set Logging Parameters
$container->setParameter('propel.logging', $config['logging'] ?? false);

if (!empty($config['schema_path']))
{
Expand Down Expand Up @@ -92,7 +82,12 @@ public function load(array $configs, ContainerBuilder $container)
}
}

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

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

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

public function getConfiguration(array $config, ContainerBuilder $container)
Expand Down
Loading