Skip to content

Commit

Permalink
Merge pull request #97 from magento-tango/pr
Browse files Browse the repository at this point in the history
[Tango] Bug fixes
  • Loading branch information
Bomko, Alex(abomko) committed Nov 2, 2015
2 parents f578e54 + 281feb3 commit 20245f4
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Eav/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ protected function _initAttributes($entityType)
*
* @param mixed $entityType
* @param mixed $code
* @return \Magento\Eav\Model\Entity\Attribute\AbstractAttribute|false
* @return \Magento\Eav\Model\Entity\Attribute\AbstractAttribute
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getAttribute($entityType, $code)
Expand Down
1 change: 1 addition & 0 deletions app/design/frontend/Magento/blank/etc/view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -286,5 +286,6 @@
<item type="directory">Lib::mage/requirejs</item>
<item type="directory">Lib::mage/adminhtml</item>
<item type="directory">Lib::mage/backend</item>
<item type="directory">Magento_Swagger::swagger-ui</item>
</exclude>
</view>
1 change: 1 addition & 0 deletions app/design/frontend/Magento/luma/etc/view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -290,5 +290,6 @@
<item type="directory">Lib::mage/requirejs</item>
<item type="directory">Lib::mage/adminhtml</item>
<item type="directory">Lib::mage/backend</item>
<item type="directory">Magento_Swagger::swagger-ui</item>
</exclude>
</view>
43 changes: 34 additions & 9 deletions lib/internal/Magento/Framework/View/Asset/Bundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class Bundle
*/
protected $assets = [];

/**
* @var array
*/
protected $assetsContent = [];

/** @var Bundle\Config */
protected $bundleConfig;

Expand Down Expand Up @@ -79,10 +84,8 @@ protected function add(LocalInterface $asset)
$parts = &$this->assets[$this->getContextCode($asset)][$asset->getContentType()];
if (!isset($parts[$partIndex])) {
$parts[$partIndex]['assets'] = [];
$parts[$partIndex]['space'] = $this->getMaxPartSize($asset);
}
$parts[$partIndex]['assets'][$this->getAssetKey($asset)] = $asset;
$parts[$partIndex]['space'] -= $this->getAssetSize($asset);
}

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

$maxPartSize = $this->getMaxPartSize($asset);
$assetSize = $this->getAssetSize($asset);
$minSpace = $maxPartSize + 1;
$minSpace = $maxPartSize;
$minIndex = -1;
if ($maxPartSize && count($parts)) {
foreach ($parts as $partIndex => $part) {
$space = $part['space'] - $assetSize;
$space = $maxPartSize - $this->getSizePartWithNewAsset($asset, $part['assets']);
if ($space >= 0 && $space < $minSpace) {
$minSpace = $space;
$minIndex = $partIndex;
Expand All @@ -145,12 +147,16 @@ protected function getMaxPartSize(LocalInterface $asset)
}

/**
* Get part size after adding new asset
*
* @param LocalInterface $asset
* @return int
* @param LocalInterface[] $assets
* @return float
*/
protected function getAssetSize(LocalInterface $asset)
protected function getSizePartWithNewAsset(LocalInterface $asset, $assets = [])
{
return mb_strlen(json_encode(utf8_encode($asset->getContent()), JSON_UNESCAPED_SLASHES), 'utf-8') / 1024;
$assets[$this->getAssetKey($asset)] = $asset;
return mb_strlen($this->getPartContent($assets), 'utf-8') / 1024;
}

/**
Expand All @@ -176,7 +182,7 @@ protected function getPartContent($assets)
{
$contents = [];
foreach ($assets as $key => $asset) {
$contents[$key] = utf8_encode($asset->getContent());
$contents[$key] = $this->getAssetContent($asset);
}

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

/**
* Get content of asset
*
* @param LocalInterface $asset
* @return string
*/
protected function getAssetContent(LocalInterface $asset)
{
$assetContextCode = $this->getContextCode($asset);
$assetContentType = $asset->getContentType();
$assetKey = $this->getAssetKey($asset);
if (!isset($this->assetsContent[$assetContextCode][$assetContentType][$assetKey])) {
$this->assetsContent[$assetContextCode][$assetContentType][$assetKey] = utf8_encode($asset->getContent());
}

return $this->assetsContent[$assetContextCode][$assetContentType][$assetKey];
}

/**
* @return string
*/
Expand Down Expand Up @@ -220,6 +244,7 @@ public function flush()
}
$this->assets = [];
$this->content = [];
$this->assetsContent = [];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ public function testMinSuffix()
->expects($this->any())
->method('addMinifiedSign')
->withConsecutive(
['onefile.js'],
['onefile.js'],
['/js/bundle/bundle0.js']
)
->willReturnOnConsecutiveCalls(
'onefile.min.js',
'onefile.min.js',
'/js/bundle/bundle0.min.js'
);
Expand Down

0 comments on commit 20245f4

Please sign in to comment.