vendor/sindrive/sindrive/ContentBundle/Listener/OptimizeListener.php line 31

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: sergey
  5.  * Date: 10/16/14
  6.  * Time: 5:34 PM
  7.  */
  8. namespace Sindrive\ContentBundle\Listener;
  9. use Sindrive\ContentBundle\ImageOptim\Process;
  10. use Symfony\Component\EventDispatcher\GenericEvent;
  11. use Symfony\Component\Filesystem\Filesystem;
  12. class OptimizeListener
  13. {
  14.     /**
  15.      * @var Process
  16.      */
  17.     private $optimizer;
  18.     private $filesystem;
  19.     public function __construct(Process $optimizerFilesystem $filesystem)
  20.     {
  21.         $this->optimizer $optimizer;
  22.         $this->filesystem $filesystem;
  23.     }
  24.     public function onCreate(GenericEvent $event)
  25.     {
  26.         $this->optimizer->process($event->getArgument('image'));
  27.         foreach ($event->getArgument('thumbs') as $thumb) {
  28.             $this->optimizer->process($thumbfalse);
  29.         }
  30.     }
  31.     public function onDelete(GenericEvent $event)
  32.     {
  33.         $imagePath $event->getArgument('image');
  34.         $filename pathinfo($imagePath, \PATHINFO_FILENAME);
  35.         $imagePath str_replace($filename '.'$filename '-orig.'$imagePath);
  36.         $this->filesystem->remove($imagePath);
  37.     }