Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Config.php
Go to the documentation of this file.
1 <?php
8 
15 
21 class Config implements Bundle\ConfigInterface
22 {
26  const VIEW_CONFIG_MODULE = 'Js_Bundle';
27  const VIEW_CONFIG_BUNDLE_SIZE_NAME = 'bundle_size';
31  protected $themeList;
32 
36  protected $viewConfig;
37 
41  private $themeProvider;
42 
46  private $config = [];
47 
52  public function __construct(
55  ) {
56  $this->viewConfig = $viewConfig;
57  $this->themeList = $themeList;
58  }
59 
64  public function isSplit(FallbackContext $assetContext)
65  {
66  return (bool)$this->getPartSize($assetContext);
67  }
68 
73  public function getConfig(FallbackContext $assetContext)
74  {
75  $themePath = $assetContext->getAreaCode() . '/' . $assetContext->getThemePath();
76  if (!isset($this->config[$themePath])) {
77  $this->config[$themePath] = $this->viewConfig->getViewConfig([
78  'area' => $assetContext->getAreaCode(),
79  'themeModel' => $this->getThemeProvider()->getThemeByFullPath(
80  $themePath
81  )
82  ]);
83  }
84 
85  return $this->config[$themePath];
86  }
87 
92  public function getPartSize(FallbackContext $assetContext)
93  {
94  $size = $this->getConfig($assetContext)->getVarValue(
95  self::VIEW_CONFIG_MODULE,
96  self::VIEW_CONFIG_BUNDLE_SIZE_NAME
97  );
98  $unit = preg_replace('/[^a-zA-Z]+/', '', $size);
99  $unit = strtoupper($unit);
100  switch ($unit) {
101  case 'KB':
102  return (int)$size;
103  case 'MB':
104  return (int)$size * 1024;
105  default:
106  return (int)($size / 1024);
107  }
108  }
109 
113  private function getThemeProvider()
114  {
115  if (null === $this->themeProvider) {
116  $this->themeProvider = ObjectManager::getInstance()->get(ThemeProviderInterface::class);
117  }
118 
119  return $this->themeProvider;
120  }
121 }
__construct(View\ConfigInterface $viewConfig, ListInterface $themeList)
Definition: Config.php:52
isSplit(FallbackContext $assetContext)
Definition: Config.php:64
getPartSize(FallbackContext $assetContext)
Definition: Config.php:92
getConfig(FallbackContext $assetContext)
Definition: Config.php:73