Config.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\View\Asset\Bundle;
  7. use Magento\Framework\App\ObjectManager;
  8. use Magento\Framework\View;
  9. use Magento\Framework\View\Asset\Bundle;
  10. use Magento\Framework\View\Design\Theme\ListInterface;
  11. use Magento\Framework\View\Asset\File\FallbackContext;
  12. use Magento\Framework\View\Design\Theme\ThemeProviderInterface;
  13. /**
  14. * Class Config
  15. * @deprecated 101.0.0
  16. * @see \Magento\Deploy\Config\BundleConfig
  17. */
  18. class Config implements Bundle\ConfigInterface
  19. {
  20. /**#@+
  21. * Bundle config info
  22. */
  23. const VIEW_CONFIG_MODULE = 'Js_Bundle';
  24. const VIEW_CONFIG_BUNDLE_SIZE_NAME = 'bundle_size';
  25. /**#@-*/
  26. /**#@-*/
  27. protected $themeList;
  28. /**
  29. * @var View\ConfigInterface
  30. */
  31. protected $viewConfig;
  32. /**
  33. * @var ThemeProviderInterface
  34. */
  35. private $themeProvider;
  36. /**
  37. * @var \Magento\Framework\Config\View[]
  38. */
  39. private $config = [];
  40. /**
  41. * @param View\ConfigInterface $viewConfig
  42. * @param ListInterface $themeList
  43. */
  44. public function __construct(
  45. View\ConfigInterface $viewConfig,
  46. ListInterface $themeList
  47. ) {
  48. $this->viewConfig = $viewConfig;
  49. $this->themeList = $themeList;
  50. }
  51. /**
  52. * @param FallbackContext $assetContext
  53. * @return bool
  54. */
  55. public function isSplit(FallbackContext $assetContext)
  56. {
  57. return (bool)$this->getPartSize($assetContext);
  58. }
  59. /**
  60. * @param FallbackContext $assetContext
  61. * @return \Magento\Framework\Config\View
  62. */
  63. public function getConfig(FallbackContext $assetContext)
  64. {
  65. $themePath = $assetContext->getAreaCode() . '/' . $assetContext->getThemePath();
  66. if (!isset($this->config[$themePath])) {
  67. $this->config[$themePath] = $this->viewConfig->getViewConfig([
  68. 'area' => $assetContext->getAreaCode(),
  69. 'themeModel' => $this->getThemeProvider()->getThemeByFullPath(
  70. $themePath
  71. )
  72. ]);
  73. }
  74. return $this->config[$themePath];
  75. }
  76. /**
  77. * @param FallbackContext $assetContext
  78. * @return int
  79. */
  80. public function getPartSize(FallbackContext $assetContext)
  81. {
  82. $size = $this->getConfig($assetContext)->getVarValue(
  83. self::VIEW_CONFIG_MODULE,
  84. self::VIEW_CONFIG_BUNDLE_SIZE_NAME
  85. );
  86. $unit = preg_replace('/[^a-zA-Z]+/', '', $size);
  87. $unit = strtoupper($unit);
  88. switch ($unit) {
  89. case 'KB':
  90. return (int)$size;
  91. case 'MB':
  92. return (int)$size * 1024;
  93. default:
  94. return (int)($size / 1024);
  95. }
  96. }
  97. /**
  98. * @return ThemeProviderInterface
  99. */
  100. private function getThemeProvider()
  101. {
  102. if (null === $this->themeProvider) {
  103. $this->themeProvider = ObjectManager::getInstance()->get(ThemeProviderInterface::class);
  104. }
  105. return $this->themeProvider;
  106. }
  107. }