vendor/symfonycasts/sass-bundle/src/Listener/PreAssetsCompileEventListener.php line 23

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the SymfonyCasts SassBundle package.
  4.  * Copyright (c) SymfonyCasts <https://symfonycasts.com/>
  5.  * For the full copyright and license information, please view the LICENSE
  6.  * file that was distributed with this source code.
  7.  */
  8. namespace Symfonycasts\SassBundle\Listener;
  9. use Symfony\Component\AssetMapper\Event\PreAssetsCompileEvent;
  10. use Symfony\Component\Console\Input\ArrayInput;
  11. use Symfony\Component\Console\Style\SymfonyStyle;
  12. use Symfonycasts\SassBundle\SassBuilder;
  13. class PreAssetsCompileEventListener
  14. {
  15.     public function __construct(private readonly SassBuilder $sassBuilder)
  16.     {
  17.     }
  18.     public function __invoke(PreAssetsCompileEvent $preAssetsCompileEvent): void
  19.     {
  20.         $io = new SymfonyStyle(
  21.             new ArrayInput([]),
  22.             $preAssetsCompileEvent->getOutput()
  23.         );
  24.         $this->sassBuilder->setOutput($io);
  25.         $process $this->sassBuilder->runBuild(false);
  26.         $process->wait(function ($type$buffer) use ($io) {
  27.             $io->write($buffer);
  28.         });
  29.         if ($process->isSuccessful()) {
  30.             return;
  31.         }
  32.         throw new \RuntimeException(sprintf('Error compiling sass: "%s"'$process->getErrorOutput()));
  33.     }
  34. }