FileExists.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\View\Asset\MergeStrategy;
  7. use Magento\Framework\App\Filesystem\DirectoryList;
  8. /**
  9. * Skip merging if the merged file already exists
  10. */
  11. class FileExists implements \Magento\Framework\View\Asset\MergeStrategyInterface
  12. {
  13. /**
  14. * @var \Magento\Framework\View\Asset\MergeStrategyInterface
  15. */
  16. protected $strategy;
  17. /**
  18. * @var \Magento\Framework\Filesystem
  19. */
  20. protected $filesystem;
  21. /**
  22. * @param \Magento\Framework\View\Asset\MergeStrategyInterface $strategy
  23. * @param \Magento\Framework\Filesystem $filesystem
  24. */
  25. public function __construct(
  26. \Magento\Framework\View\Asset\MergeStrategyInterface $strategy,
  27. \Magento\Framework\Filesystem $filesystem
  28. ) {
  29. $this->strategy = $strategy;
  30. $this->filesystem = $filesystem;
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function merge(array $assetsToMerge, \Magento\Framework\View\Asset\LocalInterface $resultAsset)
  36. {
  37. $dir = $this->filesystem->getDirectoryRead(DirectoryList::STATIC_VIEW);
  38. if (!$dir->isExist($resultAsset->getPath())) {
  39. $this->strategy->merge($assetsToMerge, $resultAsset);
  40. }
  41. }
  42. }