Asset.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. class Asset
  9. {
  10. /**
  11. * @var string
  12. */
  13. private $fileName;
  14. /**
  15. * @var string
  16. */
  17. private $sourcePath;
  18. /**
  19. * @var string
  20. */
  21. protected $module;
  22. /**
  23. * @var string
  24. */
  25. protected $area;
  26. /**
  27. * @var string
  28. */
  29. protected $theme;
  30. /**
  31. * @var string
  32. */
  33. protected $locale;
  34. /**
  35. * @var string
  36. */
  37. private $extension;
  38. /**
  39. * File constructor.
  40. * @param string $fileName
  41. * @param string $sourcePath
  42. * @param string|null $area
  43. * @param string|null $theme
  44. * @param string|null $locale
  45. * @param string|null $module
  46. */
  47. public function __construct(
  48. $fileName,
  49. $sourcePath = null,
  50. $area = null,
  51. $theme = null,
  52. $locale = null,
  53. $module = null
  54. ) {
  55. $this->fileName = $fileName;
  56. $this->sourcePath = $sourcePath;
  57. $this->module = $module;
  58. $this->area = $area;
  59. $this->theme = $theme;
  60. $this->locale = $locale;
  61. }
  62. /**
  63. * @return string
  64. */
  65. public function getFileName()
  66. {
  67. return $this->fileName;
  68. }
  69. /**
  70. * @return string
  71. */
  72. public function getFileId()
  73. {
  74. if ($this->getModule()) {
  75. return $this->getModule() . Repository::FILE_ID_SEPARATOR . $this->getFileName();
  76. }
  77. return $this->getFileName();
  78. }
  79. /**
  80. * @return string
  81. */
  82. public function getFilePath()
  83. {
  84. if ($this->getModule()) {
  85. return $this->getModule() . '/' . $this->getFileName();
  86. }
  87. return $this->getFileName();
  88. }
  89. /**
  90. * @return string
  91. */
  92. public function getSourcePath()
  93. {
  94. return $this->sourcePath;
  95. }
  96. /**
  97. * @return string
  98. */
  99. public function getModule()
  100. {
  101. return $this->module;
  102. }
  103. /**
  104. * @return string
  105. */
  106. public function getArea()
  107. {
  108. return $this->area;
  109. }
  110. /**
  111. * @return string
  112. */
  113. public function getTheme()
  114. {
  115. return $this->theme;
  116. }
  117. /**
  118. * @return string
  119. */
  120. public function getLocale()
  121. {
  122. return $this->locale;
  123. }
  124. /**
  125. * @return string
  126. */
  127. public function getExtension()
  128. {
  129. if (!$this->extension) {
  130. $this->extension = strtolower(pathinfo($this->getFileName(), PATHINFO_EXTENSION));
  131. }
  132. return $this->extension;
  133. }
  134. }