|
2 | 2 |
|
3 | 3 | namespace Comur\ImageBundle\Controller; |
4 | 4 |
|
5 | | -use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
| 5 | +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
6 | 6 |
|
7 | 7 | use Symfony\Component\HttpFoundation\Request; |
8 | 8 | use Symfony\Component\HttpFoundation\Response; |
9 | 9 | use Symfony\Component\HttpFoundation\File\UploadedFile; |
10 | 10 | use Symfony\Component\HttpFoundation\StreamedResponse; |
| 11 | +use Symfony\Component\Translation\Translator; |
11 | 12 |
|
12 | 13 | use Symfony\Component\Finder\Finder; |
13 | 14 |
|
14 | 15 | use Comur\ImageBundle\Handler\UploadHandler; |
15 | 16 |
|
16 | | -class UploadController extends Controller |
| 17 | +class UploadController extends AbstractController |
17 | 18 | { |
18 | 19 | /** |
19 | 20 | * Save uploaded image according to comur_image field configuration |
20 | 21 | * |
21 | 22 | * @param Request $request |
22 | 23 | */ |
23 | | - public function uploadImageAction(Request $request |
| 24 | + public function uploadImageAction(Request $request, Translator $translator |
24 | 25 | /*, $uploadUrl, $paramName, $webDir, $minWidth=1, $minHeight=1*/ |
25 | 26 | ){ |
26 | 27 | $config = json_decode($request->request->get('config'),true); |
@@ -83,24 +84,24 @@ public function uploadImageAction(Request $request |
83 | 84 | $transDomain = $this->container->getParameter('comur_image.translation_domain'); |
84 | 85 |
|
85 | 86 | $errorMessages = array( |
86 | | - 1 => $this->get('translator')->trans('The uploaded file exceeds the upload_max_filesize directive in php.ini', array(), $transDomain), |
87 | | - 2 => $this->get('translator')->trans('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', array(), $transDomain), |
88 | | - 3 => $this->get('translator')->trans('The uploaded file was only partially uploaded', array(), $transDomain), |
89 | | - 4 => $this->get('translator')->trans('No file was uploaded', array(), $transDomain), |
90 | | - 6 => $this->get('translator')->trans('Missing a temporary folder', array(), $transDomain), |
91 | | - 7 => $this->get('translator')->trans('Failed to write file to disk', array(), $transDomain), |
92 | | - 8 => $this->get('translator')->trans('A PHP extension stopped the file upload', array(), $transDomain), |
93 | | - 'post_max_size' => $this->get('translator')->trans('The uploaded file exceeds the post_max_size directive in php.ini', array(), $transDomain), |
94 | | - 'max_file_size' => $this->get('translator')->trans('File is too big', array(), $transDomain), |
95 | | - 'min_file_size' => $this->get('translator')->trans('File is too small', array(), $transDomain), |
96 | | - 'accept_file_types' => $this->get('translator')->trans('Filetype not allowed', array(), $transDomain), |
97 | | - 'max_number_of_files' => $this->get('translator')->trans('Maximum number of files exceeded', array(), $transDomain), |
98 | | - 'max_width' => $this->get('translator')->trans('Image exceeds maximum width', array(), $transDomain), |
99 | | - 'min_width' => $this->get('translator')->trans('Image requires a minimum width (%min%)', array('%min%' => $config['cropConfig']['minWidth']), $transDomain), |
100 | | - 'max_height' => $this->get('translator')->trans('Image exceeds maximum height', array(), $transDomain), |
101 | | - 'min_height' => $this->get('translator')->trans('Image requires a minimum height (%min%)', array('%min%' => $config['cropConfig']['minHeight']), $transDomain), |
102 | | - 'abort' => $this->get('translator')->trans('File upload aborted', array(), $transDomain), |
103 | | - 'image_resize' => $this->get('translator')->trans('Failed to resize image', array(), $transDomain), |
| 87 | + 1 => $translator->trans('The uploaded file exceeds the upload_max_filesize directive in php.ini', array(), $transDomain), |
| 88 | + 2 => $translator->trans('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', array(), $transDomain), |
| 89 | + 3 => $translator->trans('The uploaded file was only partially uploaded', array(), $transDomain), |
| 90 | + 4 => $translator->trans('No file was uploaded', array(), $transDomain), |
| 91 | + 6 => $translator->trans('Missing a temporary folder', array(), $transDomain), |
| 92 | + 7 => $translator->trans('Failed to write file to disk', array(), $transDomain), |
| 93 | + 8 => $translator->trans('A PHP extension stopped the file upload', array(), $transDomain), |
| 94 | + 'post_max_size' => $translator->trans('The uploaded file exceeds the post_max_size directive in php.ini', array(), $transDomain), |
| 95 | + 'max_file_size' => $translator->trans('File is too big', array(), $transDomain), |
| 96 | + 'min_file_size' => $translator->trans('File is too small', array(), $transDomain), |
| 97 | + 'accept_file_types' => $translator->trans('Filetype not allowed', array(), $transDomain), |
| 98 | + 'max_number_of_files' => $translator->trans('Maximum number of files exceeded', array(), $transDomain), |
| 99 | + 'max_width' => $translator->trans('Image exceeds maximum width', array(), $transDomain), |
| 100 | + 'min_width' => $translator->trans('Image requires a minimum width (%min%)', array('%min%' => $config['cropConfig']['minWidth']), $transDomain), |
| 101 | + 'max_height' => $translator->trans('Image exceeds maximum height', array(), $transDomain), |
| 102 | + 'min_height' => $translator->trans('Image requires a minimum height (%min%)', array('%min%' => $config['cropConfig']['minHeight']), $transDomain), |
| 103 | + 'abort' => $translator->trans('File upload aborted', array(), $transDomain), |
| 104 | + 'image_resize' => $translator->trans('Failed to resize image', array(), $transDomain), |
104 | 105 | ); |
105 | 106 |
|
106 | 107 | $response->setCallback(function () use($handlerConfig, $errorMessages) { |
|
0 commit comments