Skip to content

Commit 3d843e9

Browse files
author
He, Joan(johe)
committed
Merge pull request #372 from magento-extensibility/MAGETWO-48214-di-config
[Extensibility] MAGETWO-48214
2 parents 53a52ec + a852b5c commit 3d843e9

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

lib/internal/Magento/Framework/App/Config/Data.php

+17-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class Data implements DataInterface
2929
*/
3030
public function __construct(MetadataProcessor $processor, array $data)
3131
{
32-
$this->_data = $processor->process($data);
32+
/** Clone the array to work around a kink in php7 that modifies the argument by reference */
33+
$this->_data = $processor->process($this->arrayClone($data));
3334
$this->_source = $data;
3435
}
3536

@@ -77,4 +78,19 @@ public function setValue($path, $value)
7778
}
7879
$currentElement[$lastKey] = $value;
7980
}
81+
82+
/**
83+
* Copy array by value
84+
*
85+
* @param array $data
86+
* @return array
87+
*/
88+
private function arrayClone(array $data)
89+
{
90+
$clone = [];
91+
foreach ($data as $key => $value) {
92+
$clone[$key]= $value;
93+
}
94+
return $clone;
95+
}
8096
}

setup/src/Magento/Setup/Module/Di/Compiler/Config/Chain/InterceptorSubstitution.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,9 @@ public function modify(array $config)
3838
}
3939

4040
$config['preferences'] = $this->resolvePreferences($config['preferences'], $interceptors);
41-
42-
$config['preferences'] = array_merge($config['preferences'], $interceptors);
41+
$config['preferences'] = array_merge($interceptors, $config['preferences']);
4342
$config['instanceTypes'] = $this->resolvePreferences($config['instanceTypes'], $interceptors);
4443

45-
46-
4744
return $config;
4845
}
4946

setup/src/Magento/Setup/Test/Unit/Module/Di/Compiler/Config/Chain/InterceptorSubstitutionTest.php

+30
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,36 @@ public function testModifyArguments()
2424
$this->assertEquals($this->getOutputConfig(), $modifier->modify($this->getInputConfig()));
2525
}
2626

27+
public function testModifyPreferences()
28+
{
29+
$inputConfig = [
30+
'arguments' => [
31+
'ClassReplaced' => [],
32+
'ClassReplacement' => [],
33+
'ClassReplaced\Interceptor' => [],
34+
'ClassReplacement\Interceptor' => []
35+
],
36+
'preferences' => [
37+
'ClassReplaced' => 'ClassReplacement'
38+
],
39+
'instanceTypes' => []
40+
];
41+
42+
$outputConfig = [
43+
'arguments' => [
44+
'ClassReplaced\Interceptor' => [],
45+
'ClassReplacement\Interceptor' => []
46+
],
47+
'preferences' => [
48+
'ClassReplaced' => 'ClassReplacement\Interceptor',
49+
'ClassReplacement' => 'ClassReplacement\Interceptor'
50+
],
51+
'instanceTypes' => []
52+
];
53+
54+
$modifier = new InterceptorSubstitution();
55+
$this->assertEquals($outputConfig, $modifier->modify($inputConfig));
56+
}
2757

2858
/**
2959
* Input config

0 commit comments

Comments
 (0)