Path.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\View\Design\Theme\Customization;
  7. use Magento\Framework\App\Filesystem\DirectoryList;
  8. use Magento\Framework\Component\ComponentRegistrar;
  9. use Magento\Framework\Component\ComponentRegistrarInterface;
  10. /**
  11. * Theme Customization Path
  12. */
  13. class Path
  14. {
  15. /**
  16. * Customization directory name
  17. */
  18. const DIR_NAME = 'theme_customization';
  19. /**
  20. * File name
  21. *
  22. * @var string
  23. */
  24. protected $filename;
  25. /**
  26. * File system
  27. *
  28. * @var \Magento\Framework\Filesystem
  29. */
  30. protected $filesystem;
  31. /**
  32. * Media directory read
  33. *
  34. * @var \Magento\Framework\Filesystem\Directory\Read
  35. */
  36. protected $mediaDirectoryRead;
  37. /**
  38. * Component registrar
  39. *
  40. * @var ComponentRegistrarInterface
  41. */
  42. private $componentRegistrar;
  43. /**
  44. * Constructor
  45. *
  46. * @param \Magento\Framework\Filesystem $filesystem
  47. * @param ComponentRegistrarInterface $componentRegistrar
  48. * @param string $filename
  49. */
  50. public function __construct(
  51. \Magento\Framework\Filesystem $filesystem,
  52. ComponentRegistrarInterface $componentRegistrar,
  53. $filename = \Magento\Framework\View\ConfigInterface::CONFIG_FILE_NAME
  54. ) {
  55. $this->filesystem = $filesystem;
  56. $this->filename = $filename;
  57. $this->mediaDirectoryRead = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
  58. $this->componentRegistrar = $componentRegistrar;
  59. }
  60. /**
  61. * Returns customization absolute path
  62. *
  63. * @param \Magento\Framework\View\Design\ThemeInterface $theme
  64. * @return string|null
  65. */
  66. public function getCustomizationPath(\Magento\Framework\View\Design\ThemeInterface $theme)
  67. {
  68. $path = null;
  69. if ($theme->getId()) {
  70. $path = $this->mediaDirectoryRead->getAbsolutePath(self::DIR_NAME . '/' . $theme->getId());
  71. }
  72. return $path;
  73. }
  74. /**
  75. * Get directory where themes files are stored
  76. *
  77. * @param \Magento\Framework\View\Design\ThemeInterface $theme
  78. * @return string|null
  79. */
  80. public function getThemeFilesPath(\Magento\Framework\View\Design\ThemeInterface $theme)
  81. {
  82. $path = null;
  83. if ($theme->getFullPath()) {
  84. $path = $this->componentRegistrar->getPath(ComponentRegistrar::THEME, $theme->getFullPath());
  85. }
  86. return $path;
  87. }
  88. /**
  89. * Get path to custom view configuration file
  90. *
  91. * @param \Magento\Framework\View\Design\ThemeInterface $theme
  92. * @return string|null
  93. */
  94. public function getCustomViewConfigPath(\Magento\Framework\View\Design\ThemeInterface $theme)
  95. {
  96. $path = null;
  97. if ($theme->getId()) {
  98. $path = $this->mediaDirectoryRead->getAbsolutePath(
  99. self::DIR_NAME . '/' . $theme->getId() . '/' . $this->filename
  100. );
  101. }
  102. return $path;
  103. }
  104. }