Skip to content

Commit 20245f4

Browse files
author
Bomko, Alex(abomko)
committed
Merge pull request #97 from magento-tango/pr
[Tango] Bug fixes
2 parents f578e54 + 281feb3 commit 20245f4

File tree

5 files changed

+39
-10
lines changed

5 files changed

+39
-10
lines changed

app/code/Magento/Eav/Model/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ protected function _initAttributes($entityType)
418418
*
419419
* @param mixed $entityType
420420
* @param mixed $code
421-
* @return \Magento\Eav\Model\Entity\Attribute\AbstractAttribute|false
421+
* @return \Magento\Eav\Model\Entity\Attribute\AbstractAttribute
422422
* @throws \Magento\Framework\Exception\LocalizedException
423423
*/
424424
public function getAttribute($entityType, $code)

app/design/frontend/Magento/blank/etc/view.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,5 +286,6 @@
286286
<item type="directory">Lib::mage/requirejs</item>
287287
<item type="directory">Lib::mage/adminhtml</item>
288288
<item type="directory">Lib::mage/backend</item>
289+
<item type="directory">Magento_Swagger::swagger-ui</item>
289290
</exclude>
290291
</view>

app/design/frontend/Magento/luma/etc/view.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,5 +290,6 @@
290290
<item type="directory">Lib::mage/requirejs</item>
291291
<item type="directory">Lib::mage/adminhtml</item>
292292
<item type="directory">Lib::mage/backend</item>
293+
<item type="directory">Magento_Swagger::swagger-ui</item>
293294
</exclude>
294295
</view>

lib/internal/Magento/Framework/View/Asset/Bundle.php

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ class Bundle
2121
*/
2222
protected $assets = [];
2323

24+
/**
25+
* @var array
26+
*/
27+
protected $assetsContent = [];
28+
2429
/** @var Bundle\Config */
2530
protected $bundleConfig;
2631

@@ -79,10 +84,8 @@ protected function add(LocalInterface $asset)
7984
$parts = &$this->assets[$this->getContextCode($asset)][$asset->getContentType()];
8085
if (!isset($parts[$partIndex])) {
8186
$parts[$partIndex]['assets'] = [];
82-
$parts[$partIndex]['space'] = $this->getMaxPartSize($asset);
8387
}
8488
$parts[$partIndex]['assets'][$this->getAssetKey($asset)] = $asset;
85-
$parts[$partIndex]['space'] -= $this->getAssetSize($asset);
8689
}
8790

8891
/**
@@ -119,12 +122,11 @@ protected function getPartIndex(LocalInterface $asset)
119122
$parts = $this->assets[$this->getContextCode($asset)][$asset->getContentType()];
120123

121124
$maxPartSize = $this->getMaxPartSize($asset);
122-
$assetSize = $this->getAssetSize($asset);
123-
$minSpace = $maxPartSize + 1;
125+
$minSpace = $maxPartSize;
124126
$minIndex = -1;
125127
if ($maxPartSize && count($parts)) {
126128
foreach ($parts as $partIndex => $part) {
127-
$space = $part['space'] - $assetSize;
129+
$space = $maxPartSize - $this->getSizePartWithNewAsset($asset, $part['assets']);
128130
if ($space >= 0 && $space < $minSpace) {
129131
$minSpace = $space;
130132
$minIndex = $partIndex;
@@ -145,12 +147,16 @@ protected function getMaxPartSize(LocalInterface $asset)
145147
}
146148

147149
/**
150+
* Get part size after adding new asset
151+
*
148152
* @param LocalInterface $asset
149-
* @return int
153+
* @param LocalInterface[] $assets
154+
* @return float
150155
*/
151-
protected function getAssetSize(LocalInterface $asset)
156+
protected function getSizePartWithNewAsset(LocalInterface $asset, $assets = [])
152157
{
153-
return mb_strlen(json_encode(utf8_encode($asset->getContent()), JSON_UNESCAPED_SLASHES), 'utf-8') / 1024;
158+
$assets[$this->getAssetKey($asset)] = $asset;
159+
return mb_strlen($this->getPartContent($assets), 'utf-8') / 1024;
154160
}
155161

156162
/**
@@ -176,7 +182,7 @@ protected function getPartContent($assets)
176182
{
177183
$contents = [];
178184
foreach ($assets as $key => $asset) {
179-
$contents[$key] = utf8_encode($asset->getContent());
185+
$contents[$key] = $this->getAssetContent($asset);
180186
}
181187

182188
$partType = reset($assets)->getContentType();
@@ -190,6 +196,24 @@ protected function getPartContent($assets)
190196
return $content;
191197
}
192198

199+
/**
200+
* Get content of asset
201+
*
202+
* @param LocalInterface $asset
203+
* @return string
204+
*/
205+
protected function getAssetContent(LocalInterface $asset)
206+
{
207+
$assetContextCode = $this->getContextCode($asset);
208+
$assetContentType = $asset->getContentType();
209+
$assetKey = $this->getAssetKey($asset);
210+
if (!isset($this->assetsContent[$assetContextCode][$assetContentType][$assetKey])) {
211+
$this->assetsContent[$assetContextCode][$assetContentType][$assetKey] = utf8_encode($asset->getContent());
212+
}
213+
214+
return $this->assetsContent[$assetContextCode][$assetContentType][$assetKey];
215+
}
216+
193217
/**
194218
* @return string
195219
*/
@@ -220,6 +244,7 @@ public function flush()
220244
}
221245
$this->assets = [];
222246
$this->content = [];
247+
$this->assetsContent = [];
223248
}
224249

225250
/**

lib/internal/Magento/Framework/View/Test/Unit/Asset/BundleTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ public function testMinSuffix()
6666
->expects($this->any())
6767
->method('addMinifiedSign')
6868
->withConsecutive(
69+
['onefile.js'],
6970
['onefile.js'],
7071
['/js/bundle/bundle0.js']
7172
)
7273
->willReturnOnConsecutiveCalls(
74+
'onefile.min.js',
7375
'onefile.min.js',
7476
'/js/bundle/bundle0.min.js'
7577
);

0 commit comments

Comments
 (0)