File.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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\Design\ThemeInterface;
  8. /**
  9. * View file in the file system with context of its identity
  10. */
  11. class File
  12. {
  13. /**
  14. * File name
  15. *
  16. * @var string
  17. */
  18. protected $filename;
  19. /**
  20. * Module
  21. *
  22. * @var string
  23. */
  24. protected $module;
  25. /**
  26. * Theme
  27. *
  28. * @var ThemeInterface
  29. */
  30. protected $theme;
  31. /**
  32. * Base flag
  33. *
  34. * @var string
  35. */
  36. protected $isBase;
  37. /**
  38. * Identifier
  39. *
  40. * @var string
  41. */
  42. protected $identifier;
  43. /**
  44. * Constructor
  45. *
  46. * @param string $filename
  47. * @param string $module
  48. * @param ThemeInterface $theme
  49. * @param bool $isBase
  50. */
  51. public function __construct($filename, $module, ThemeInterface $theme = null, $isBase = false)
  52. {
  53. $this->filename = $filename;
  54. $this->module = $module;
  55. $this->theme = $theme;
  56. $this->isBase = $isBase;
  57. }
  58. /**
  59. * Retrieve full filename
  60. *
  61. * @return string
  62. */
  63. public function getFilename()
  64. {
  65. return $this->filename;
  66. }
  67. /**
  68. * Retrieve name of a file without a directory path
  69. *
  70. * @return string
  71. */
  72. public function getName()
  73. {
  74. return basename($this->filename);
  75. }
  76. /**
  77. * Retrieve fully-qualified name of a module a file belongs to
  78. *
  79. * @return string
  80. */
  81. public function getModule()
  82. {
  83. return $this->module;
  84. }
  85. /**
  86. * Retrieve instance of a theme a file belongs to
  87. *
  88. * @return ThemeInterface|null
  89. */
  90. public function getTheme()
  91. {
  92. return $this->theme;
  93. }
  94. /**
  95. * Whether file is a base one
  96. *
  97. * @return bool
  98. */
  99. public function isBase()
  100. {
  101. return $this->theme === null;
  102. }
  103. /**
  104. * Calculate unique identifier for a view file
  105. *
  106. * @return string
  107. */
  108. public function getFileIdentifier()
  109. {
  110. if (null === $this->identifier) {
  111. $theme = $this->getTheme() ? ('|theme:' . $this->theme->getFullPath()) : '';
  112. $this->identifier = ($this->isBase ? 'base' : '')
  113. . $theme . '|module:' . $this->getModule() . '|file:' . $this->getName();
  114. }
  115. return $this->identifier;
  116. }
  117. }