Skip to content

Commit cebbe1e

Browse files
committed
MAGETWO-33080: Preferences, Shared Instance creation and Compiled Factory optimization
- removed non shared instances config in compiled mode - arguments serialization placed to area operation
1 parent 5672ce6 commit cebbe1e

File tree

5 files changed

+28
-47
lines changed

5 files changed

+28
-47
lines changed

dev/tests/unit/testsuite/Magento/Tools/Di/App/Task/AreaTest.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,23 @@ public function testDoOperationEmptyPath()
6464
public function testDoOperationGlobalArea()
6565
{
6666
$path = 'path/to/codebase/';
67+
$arguments = ['class' => []];
6768
$generatedConfig = [
68-
'arguments' => [],
69-
'nonShared' => [],
69+
'arguments' => $arguments,
7070
'preferences' => [],
7171
'instanceTypes' => []
7272
];
73-
$definitions = new DefinitionsCollection();
74-
$definitions->addDefinition('class', []);
73+
$expectedConfig = [
74+
'arguments' => array_map(
75+
function ($arguments) {
76+
return serialize($arguments);
77+
},
78+
$arguments
79+
),
80+
'preferences' => [],
81+
'instanceTypes' => []
82+
];
83+
7584
$areaOperation = new Area(
7685
$this->areaListMock,
7786
$this->areaInstancesNamesList,
@@ -86,7 +95,7 @@ public function testDoOperationGlobalArea()
8695
$this->areaInstancesNamesList->expects($this->once())
8796
->method('getList')
8897
->with($path)
89-
->willReturn(['class' => []]);
98+
->willReturn($arguments);
9099
$this->configReaderMock->expects($this->once())
91100
->method('generateCachePerScope')
92101
->with(
@@ -98,7 +107,7 @@ public function testDoOperationGlobalArea()
98107
->method('write')
99108
->with(
100109
App\Area::AREA_GLOBAL,
101-
$generatedConfig
110+
$expectedConfig
102111
);
103112

104113
$areaOperation->doOperation();

dev/tests/unit/testsuite/Magento/Tools/Di/Compiler/Config/ReaderTest.php

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,6 @@ public function testGenerateCachePerScopeGlobal()
9797
->method('getInstanceType')
9898
->willReturnMap($this->getInstanceTypeMap($this->getVirtualTypes()));
9999

100-
$this->diContainerConfig->expects($this->any())
101-
->method('isShared')
102-
->willReturnMap($this->getExpectedNonShared());
103-
104100
$this->diContainerConfig->expects($this->any())
105101
->method('getPreference')
106102
->willReturnMap($this->getPreferencesMap());
@@ -138,13 +134,9 @@ private function getExpectedGlobalConfig()
138134
{
139135
return [
140136
'arguments' => [
141-
'ConcreteType1' => serialize(['resolved_argument1', 'resolved_argument2']),
142-
'ConcreteType2' => serialize(['resolved_argument1', 'resolved_argument2']),
143-
'virtualType1' => serialize(['resolved_argument1', 'resolved_argument2'])
144-
],
145-
'nonShared' => [
146-
'ConcreteType2' => true,
147-
'ThirdPartyInterface' => true
137+
'ConcreteType1' => ['resolved_argument1', 'resolved_argument2'],
138+
'ConcreteType2' => ['resolved_argument1', 'resolved_argument2'],
139+
'virtualType1' => ['resolved_argument1', 'resolved_argument2']
148140
],
149141
'preferences' => $this->getPreferences(),
150142
'instanceTypes' => $this->getVirtualTypes(),
@@ -172,19 +164,6 @@ private function getVirtualTypes()
172164
return ['virtualType1' => 'ConcreteType1'];
173165
}
174166

175-
/**
176-
* @return array
177-
*/
178-
private function getExpectedNonShared()
179-
{
180-
return [
181-
['ConcreteType1', true],
182-
['ConcreteType2', false],
183-
['Interface1', true],
184-
['ThirdPartyInterface', false]
185-
];
186-
}
187-
188167
/**
189168
* @return array
190169
*/

dev/tools/Magento/Tools/Di/App/Task/Operation/Area.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,17 @@ public function doOperation()
7575

7676
$areaCodes = array_merge([App\Area::AREA_GLOBAL], $this->areaList->getCodes());
7777
foreach ($areaCodes as $areaCode) {
78+
$config = $this->configReader->generateCachePerScope($definitionsCollection, $areaCode);
79+
80+
foreach ($config['arguments'] as $key => $value) {
81+
if ($value !== null) {
82+
$config['arguments'][$key] = serialize($value);
83+
}
84+
}
85+
7886
$this->configWriter->write(
7987
$areaCode,
80-
$this->configReader->generateCachePerScope($definitionsCollection, $areaCode)
88+
$config
8189
);
8290
}
8391
}

dev/tools/Magento/Tools/Di/Compiler/Config/Reader.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,8 @@ public function generateCachePerScope(
8282

8383
$this->fillThirdPartyInterfaces($areaConfig, $definitionsCollection);
8484
$config['arguments'] = $this->getConfigForScope($definitionsCollection, $areaConfig);
85-
foreach ($config['arguments'] as $key => $value) {
86-
if ($value !== null) {
87-
$config['arguments'][$key] = serialize($value);
88-
}
89-
}
9085

9186
foreach ($definitionsCollection->getInstancesNamesList() as $instanceName) {
92-
if (!$areaConfig->isShared($instanceName)) {
93-
$config['nonShared'][$instanceName] = true;
94-
}
9587
$preference = $areaConfig->getPreference($instanceName);
9688
if ($instanceName !== $preference) {
9789
$config['preferences'][$instanceName] = $preference;

lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ class Compiled implements \Magento\Framework\ObjectManager\ConfigInterface
1616
*/
1717
private $arguments;
1818

19-
/**
20-
* @var array
21-
*/
22-
private $nonShared;
23-
2419
/**
2520
* @var array
2621
*/
@@ -37,7 +32,6 @@ class Compiled implements \Magento\Framework\ObjectManager\ConfigInterface
3732
public function __construct($data)
3833
{
3934
$this->arguments = $data['arguments'];
40-
$this->nonShared = $data['nonShared'];
4135
$this->virtualTypes = $data['instanceTypes'];
4236
$this->preferences = $data['preferences'];
4337
}
@@ -94,7 +88,7 @@ public function getArguments($type)
9488
*/
9589
public function isShared($type)
9690
{
97-
return !isset($this->nonShared[$type]);
91+
return true;
9892
}
9993

10094
/**
@@ -135,7 +129,6 @@ public function getPreference($type)
135129
public function extend(array $configuration)
136130
{
137131
$this->arguments = $configuration['arguments'];
138-
$this->nonShared = $configuration['nonShared'];
139132
$this->virtualTypes = $configuration['instanceTypes'];
140133
$this->preferences = $configuration['preferences'];
141134
}

0 commit comments

Comments
 (0)