Skip to content

Commit eb07151

Browse files
authored
Merge pull request #180 from next-sentence/file-storage
Add FileUploaderInterface
2 parents d8499a8 + 2c43ba5 commit eb07151

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

src/Controller/FormController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
use MonsieurBiz\SyliusRichEditorPlugin\Exception\UiElementNotFoundException;
1717
use MonsieurBiz\SyliusRichEditorPlugin\UiElement\RegistryInterface;
18-
use MonsieurBiz\SyliusRichEditorPlugin\Uploader\FileUploader;
18+
use MonsieurBiz\SyliusRichEditorPlugin\Uploader\FileUploaderInterface;
1919
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
2020
use Symfony\Component\Form\Extension\Core\Type\FileType as NativeFileType;
2121
use Symfony\Component\Form\FormInterface;
@@ -122,7 +122,7 @@ public function renderElementsAction(Request $request): Response
122122
/**
123123
* Validate submitted data and return an UI Element JSON if everything is OK.
124124
*/
125-
public function submitAction(Request $request, FileUploader $fileUploader, string $code, bool $isEdition): Response
125+
public function submitAction(Request $request, FileUploaderInterface $fileUploader, string $code, bool $isEdition): Response
126126
{
127127
// Find UI Element from type
128128
try {
@@ -181,7 +181,7 @@ public function submitAction(Request $request, FileUploader $fileUploader, strin
181181
*
182182
* @return array|mixed|string
183183
*/
184-
private function processFormData(FormInterface $form, FileUploader $fileUploader, $requestData)
184+
private function processFormData(FormInterface $form, FileUploaderInterface $fileUploader, $requestData)
185185
{
186186
// No child, end of recursivity, return form value or uploaded file path
187187
if (!\count($form->all())) {
@@ -202,7 +202,7 @@ private function processFormData(FormInterface $form, FileUploader $fileUploader
202202
*
203203
* @return array|mixed|string
204204
*/
205-
private function processFormDataWithoutChild(FormInterface $form, FileUploader $fileUploader, $requestData)
205+
private function processFormDataWithoutChild(FormInterface $form, FileUploaderInterface $fileUploader, $requestData)
206206
{
207207
if ($form->isValid() && $form->getData() instanceof UploadedFile) {
208208
// Upload image selected by user

src/Resources/config/services.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ services:
3838
$fileTargetPath: '%monsieurbiz.richeditor.config.upload_directory%'
3939
$imageTargetPath: '%monsieurbiz.richeditor.config.image_upload_directory%'
4040
$publicDirectory: '%kernel.project_dir%/public'
41+
42+
MonsieurBiz\SyliusRichEditorPlugin\Uploader\FileUploaderInterface: '@MonsieurBiz\SyliusRichEditorPlugin\Uploader\FileUploader'

src/Uploader/FileUploader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Symfony\Component\HttpFoundation\File\File;
1818
use Symfony\Component\HttpFoundation\File\UploadedFile;
1919

20-
class FileUploader
20+
class FileUploader implements FileUploaderInterface
2121
{
2222
public const FILE_TYPE_DOCUMENT = 'document';
2323

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Monsieur Biz' Rich Editor plugin for Sylius.
5+
*
6+
* (c) Monsieur Biz <sylius@monsieurbiz.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace MonsieurBiz\SyliusRichEditorPlugin\Uploader;
15+
16+
use Symfony\Component\HttpFoundation\File\UploadedFile;
17+
18+
interface FileUploaderInterface
19+
{
20+
/**
21+
* Upload a file and return the path to it.
22+
*/
23+
public function upload(UploadedFile $file, ?string $type = null): string;
24+
}

0 commit comments

Comments
 (0)