Config.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\View;
  7. use Magento\Framework\View\Asset\Repository;
  8. use Magento\Framework\Config\ViewFactory;
  9. /**
  10. * Handles theme view.xml files
  11. */
  12. class Config implements \Magento\Framework\View\ConfigInterface
  13. {
  14. /**
  15. * List of view configuration objects per theme
  16. *
  17. * @var array
  18. */
  19. protected $viewConfigs = [];
  20. /**
  21. * View service
  22. *
  23. * @var \Magento\Framework\View\Asset\Repository
  24. */
  25. protected $assetRepo;
  26. /**
  27. * File view factory
  28. *
  29. * @var \Magento\Framework\Config\ViewFactory
  30. */
  31. protected $viewConfigFactory;
  32. /**
  33. * Constructor
  34. *
  35. * @param Asset\Repository $assetRepo
  36. * @param \Magento\Framework\Config\ViewFactory $viewConfigFactory
  37. */
  38. public function __construct(
  39. Repository $assetRepo,
  40. ViewFactory $viewConfigFactory
  41. ) {
  42. $this->assetRepo = $assetRepo;
  43. $this->viewConfigFactory = $viewConfigFactory;
  44. }
  45. /**
  46. * Render view config object for current package and theme
  47. *
  48. * @param array $params
  49. * @return \Magento\Framework\Config\View
  50. */
  51. public function getViewConfig(array $params = [])
  52. {
  53. $this->assetRepo->updateDesignParams($params);
  54. $viewConfigParams = [];
  55. if (isset($params['themeModel'])) {
  56. /** @var \Magento\Framework\View\Design\ThemeInterface $currentTheme */
  57. $currentTheme = $params['themeModel'];
  58. $key = $currentTheme->getFullPath();
  59. if (isset($this->viewConfigs[$key])) {
  60. return $this->viewConfigs[$key];
  61. }
  62. $viewConfigParams['themeModel'] = $currentTheme;
  63. }
  64. $viewConfigParams['area'] = (isset($params['area'])) ? $params['area'] : null;
  65. /** @var \Magento\Framework\Config\View $config */
  66. $config = $this->viewConfigFactory->create($viewConfigParams);
  67. if (isset($key)) {
  68. $this->viewConfigs[$key] = $config;
  69. }
  70. return $config;
  71. }
  72. }