MinifyTemplates.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Deploy\Service;
  7. use Magento\Framework\View\Template\Html\MinifierInterface;
  8. use Magento\Framework\App\Utility\Files;
  9. /**
  10. * Minify PHTML templates service
  11. */
  12. class MinifyTemplates
  13. {
  14. /**
  15. * @var Files
  16. */
  17. private $filesUtils;
  18. /**
  19. * @var MinifierInterface
  20. */
  21. private $htmlMinifier;
  22. /**
  23. * @param Files $filesUtils
  24. * @param MinifierInterface $htmlMinifier
  25. */
  26. public function __construct(
  27. Files $filesUtils,
  28. MinifierInterface $htmlMinifier
  29. ) {
  30. $this->filesUtils = $filesUtils;
  31. $this->htmlMinifier = $htmlMinifier;
  32. }
  33. /**
  34. * Minify template files
  35. *
  36. * @return int
  37. */
  38. public function minifyTemplates()
  39. {
  40. $count = 0;
  41. foreach ($this->filesUtils->getPhtmlFiles(false, false) as $template) {
  42. $this->htmlMinifier->minify($template);
  43. $count++;
  44. }
  45. return $count;
  46. }
  47. }