FallbackContext.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\View\Asset\File;
  7. use Magento\Framework\App\Filesystem\DirectoryList;
  8. /**
  9. * An advanced context that contains information necessary for view files fallback system
  10. *
  11. * @api
  12. * @since 100.0.2
  13. */
  14. class FallbackContext extends Context
  15. {
  16. /**
  17. * @var string
  18. */
  19. private $area;
  20. /**
  21. * @var string
  22. */
  23. private $theme;
  24. /**
  25. * @var string
  26. */
  27. private $locale;
  28. /**
  29. * @param string $baseUrl
  30. * @param string $areaType
  31. * @param string $themePath
  32. * @param string $localeCode
  33. */
  34. public function __construct($baseUrl, $areaType, $themePath, $localeCode)
  35. {
  36. $this->area = $areaType;
  37. $this->theme = $themePath;
  38. $this->locale = $localeCode;
  39. parent::__construct($baseUrl, DirectoryList::STATIC_VIEW, $this->generatePath());
  40. }
  41. /**
  42. * Get area code
  43. *
  44. * @return string
  45. */
  46. public function getAreaCode()
  47. {
  48. return $this->area;
  49. }
  50. /**
  51. * Get theme path
  52. *
  53. * @return string
  54. */
  55. public function getThemePath()
  56. {
  57. return $this->theme;
  58. }
  59. /**
  60. * Get locale code
  61. *
  62. * @return string
  63. */
  64. public function getLocale()
  65. {
  66. return $this->locale;
  67. }
  68. /**
  69. * Generate path based on the context parameters
  70. *
  71. * @return string
  72. */
  73. private function generatePath()
  74. {
  75. return $this->area .
  76. ($this->theme ? '/' . $this->theme : '') .
  77. ($this->locale ? '/' . $this->locale : '');
  78. }
  79. /**
  80. * Returns path to Require.js config object depending on HTTPS or HTTP protocol being used
  81. *
  82. * @return string
  83. */
  84. public function getConfigPath()
  85. {
  86. return $this->getPath();
  87. }
  88. }