Module.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\View\Asset\NotationResolver;
  7. use Magento\Framework\View\Asset;
  8. use Magento\Framework\View\FileSystem;
  9. /**
  10. * Module notation normalizer
  11. */
  12. class Module
  13. {
  14. /**
  15. * @var \Magento\Framework\View\Asset\Repository
  16. */
  17. private $assetRepo;
  18. /**
  19. * @param Asset\Repository $assetRepo
  20. */
  21. public function __construct(Asset\Repository $assetRepo)
  22. {
  23. $this->assetRepo = $assetRepo;
  24. }
  25. /**
  26. * Convert module notation to a path relative to the specified asset
  27. *
  28. * For example, the asset is Foo_Bar/styles/style.css and it refers to Bar_Baz::images/logo.gif
  29. * (i.e. url(Bar_Baz::images/logo.gif))
  30. * The result will be ../../Bar_Baz/images/logo.gif
  31. *
  32. * @param Asset\LocalInterface $thisAsset
  33. * @param string $relatedFileId
  34. * @return string
  35. */
  36. public function convertModuleNotationToPath(Asset\LocalInterface $thisAsset, $relatedFileId)
  37. {
  38. if (false === strpos($relatedFileId, Asset\Repository::FILE_ID_SEPARATOR)) {
  39. return $relatedFileId;
  40. }
  41. $thisPath = $thisAsset->getPath();
  42. $relatedAsset = $this->assetRepo->createSimilar($relatedFileId, $thisAsset);
  43. $relatedPath = $relatedAsset->getPath();
  44. $offset = FileSystem::offsetPath($relatedPath, $thisPath);
  45. return FileSystem::normalizePath($offset . '/' . basename($relatedPath));
  46. }
  47. }