app/Plugin/Synplgresizeimage/Event.php line 22

Open in your IDE?
  1. <?php
  2. namespace Plugin\Synplgresizeimage;
  3. use Plugin\Synplgresizeimage\Service\ResizeImageService;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpKernel\KernelEvents;
  6. class Event implements EventSubscriberInterface
  7. {
  8.     /**
  9.      * @return array
  10.      */
  11.     public static function getSubscribedEvents()
  12.     {
  13.         return [
  14.             KernelEvents::REQUEST => 'OnKernelRequest',
  15.         ];
  16.     }
  17.     public function OnKernelRequest()
  18.     {
  19.         if (empty($_FILES)) return;
  20.         foreach ($_FILES as $file) {
  21.             if (isset($file['tmp_name'])) {
  22.                 if (!is_array($file['tmp_name'])) return;
  23.                 foreach ($file['tmp_name'] as $value) {
  24.                     $resizeImage = new ResizeImageService();
  25.                     if (is_array($value)) {
  26.                         foreach ($value as $value2) {
  27.                             if (!file_exists($value2)) return;
  28.                             if (!empty($value2) && exif_imagetype($value2)) {
  29.                                 $resizeImage->resizeImage($value212001200'contain'true);
  30.                             }
  31.                         }
  32.                     } else {
  33.                         if (!file_exists($value)) return;
  34.                         if (!empty($value) && exif_imagetype($value)) {
  35.                             $resizeImage->resizeImage($value12001200'contain'true);
  36.                         }
  37.                     }
  38.                 }
  39.             }
  40.         }
  41.     }
  42. }