ModuleNotation.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\View\Asset\PreProcessor;
  7. use Magento\Framework\View\Asset;
  8. use Magento\Framework\View\Url\CssResolver;
  9. /**
  10. * Support of notation "Module_Name::file/path.ext" in CSS-files
  11. *
  12. * This implementation is specific to CSS, despite that the actual algorithm of calculating offsets is generic.
  13. * The part specific to CSS is the fact that a CSS file may refer to another file and the relative path has to be
  14. * based off the current location of CSS-file. So context of base path can be known ONLY at the moment
  15. * of traversing the CSS contents in context of the file location.
  16. * Other than that, the algorithm of resolving notation "Module_Name::file/path.ext" is generic
  17. */
  18. class ModuleNotation implements Asset\PreProcessorInterface
  19. {
  20. /**
  21. * @var \Magento\Framework\View\Url\CssResolver
  22. */
  23. private $cssResolver;
  24. /**
  25. * @var \Magento\Framework\View\Asset\NotationResolver\Module
  26. */
  27. private $notationResolver;
  28. /**
  29. * @param CssResolver $cssResolver
  30. * @param \Magento\Framework\View\Asset\NotationResolver\Module $notationResolver
  31. */
  32. public function __construct(
  33. CssResolver $cssResolver,
  34. \Magento\Framework\View\Asset\NotationResolver\Module $notationResolver
  35. ) {
  36. $this->cssResolver = $cssResolver;
  37. $this->notationResolver = $notationResolver;
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function process(Chain $chain)
  43. {
  44. $asset = $chain->getAsset();
  45. $callback = function ($path) use ($asset) {
  46. return $this->notationResolver->convertModuleNotationToPath($asset, $path);
  47. };
  48. $chain->setContent($this->cssResolver->replaceRelativeUrls($chain->getContent(), $callback));
  49. }
  50. }