<?php
namespace Plugin\Synplgresizeimage;
use Plugin\Synplgresizeimage\Service\ResizeImageService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
class Event implements EventSubscriberInterface
{
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
KernelEvents::REQUEST => 'OnKernelRequest',
];
}
public function OnKernelRequest()
{
if (empty($_FILES)) return;
foreach ($_FILES as $file) {
if (isset($file['tmp_name'])) {
if (!is_array($file['tmp_name'])) return;
foreach ($file['tmp_name'] as $value) {
$resizeImage = new ResizeImageService();
if (is_array($value)) {
foreach ($value as $value2) {
if (!file_exists($value2)) return;
if (!empty($value2) && exif_imagetype($value2)) {
$resizeImage->resizeImage($value2, 1200, 1200, 'contain', true);
}
}
} else {
if (!file_exists($value)) return;
if (!empty($value) && exif_imagetype($value)) {
$resizeImage->resizeImage($value, 1200, 1200, 'contain', true);
}
}
}
}
}
}
}