Skip to content

Commit

Permalink
Merge pull request #17 from mpdude/override-transformations
Browse files Browse the repository at this point in the history
Allow overriding transformation definitions in later config files
  • Loading branch information
jbouzekri authored Jan 4, 2021
2 parents b999650 + fdb2d66 commit 5cccddc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
4 changes: 3 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ private function addTransformationSection(ArrayNodeDefinition $rootNode)
$rootNode
->children()
->arrayNode('transformations')
->prototype('array')
->useAttributeAsKey('id')
->arrayPrototype()
->performNoDeepMerging()
// Filter key is a prototype array. Remove it if empty array
->validate()
->always(function ($val) {
Expand Down
35 changes: 35 additions & 0 deletions Tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,41 @@ public function testServerConfiguration()
$this->assertEquals($config['server']['secret'], '123456789');
}

public function testTransformationMerging()
{
// When a transformation is re-defined (overridden) in a later config file,
// the newer definition entirely replaces the older one.

$processor = new Processor();
$config = $processor->processConfiguration(new Configuration(), array(
// Values from first config file
array(
'transformations' => array(
'test_not_overridden' => array(
'resize' => array('width' => 100, 'height' => 100),
),
'test_overridden' => array(
'filters' => array(array('name' => 'quality', 'arguments' => array(60))),
'resize' => array('width' => 100, 'height' => 100),
),
)
),
// Values from second config file, should win
array(
'transformations' => array(
'test_overridden' => array(
'resize' => array('width' => 200, 'height' => 200),
),
)
),
));

$this->assertEquals(array(
'test_overridden' => array('resize' => array('width'=>200, 'height'=>200)),
'test_not_overridden' => array('resize' => array('width'=>100, 'height'=>100)),
), $config['transformations']);
}

/**
* @dataProvider getTransformationData
*/
Expand Down

0 comments on commit 5cccddc

Please sign in to comment.