Skip to content

Commit

Permalink
Merge pull request #180 from next-sentence/file-storage
Browse files Browse the repository at this point in the history
Add FileUploaderInterface
  • Loading branch information
maximehuran committed Apr 6, 2022
2 parents d8499a8 + 2c43ba5 commit eb07151
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Controller/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use MonsieurBiz\SyliusRichEditorPlugin\Exception\UiElementNotFoundException;
use MonsieurBiz\SyliusRichEditorPlugin\UiElement\RegistryInterface;
use MonsieurBiz\SyliusRichEditorPlugin\Uploader\FileUploader;
use MonsieurBiz\SyliusRichEditorPlugin\Uploader\FileUploaderInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\FileType as NativeFileType;
use Symfony\Component\Form\FormInterface;
Expand Down Expand Up @@ -122,7 +122,7 @@ public function renderElementsAction(Request $request): Response
/**
* Validate submitted data and return an UI Element JSON if everything is OK.
*/
public function submitAction(Request $request, FileUploader $fileUploader, string $code, bool $isEdition): Response
public function submitAction(Request $request, FileUploaderInterface $fileUploader, string $code, bool $isEdition): Response
{
// Find UI Element from type
try {
Expand Down Expand Up @@ -181,7 +181,7 @@ public function submitAction(Request $request, FileUploader $fileUploader, strin
*
* @return array|mixed|string
*/
private function processFormData(FormInterface $form, FileUploader $fileUploader, $requestData)
private function processFormData(FormInterface $form, FileUploaderInterface $fileUploader, $requestData)
{
// No child, end of recursivity, return form value or uploaded file path
if (!\count($form->all())) {
Expand All @@ -202,7 +202,7 @@ private function processFormData(FormInterface $form, FileUploader $fileUploader
*
* @return array|mixed|string
*/
private function processFormDataWithoutChild(FormInterface $form, FileUploader $fileUploader, $requestData)
private function processFormDataWithoutChild(FormInterface $form, FileUploaderInterface $fileUploader, $requestData)
{
if ($form->isValid() && $form->getData() instanceof UploadedFile) {
// Upload image selected by user
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ services:
$fileTargetPath: '%monsieurbiz.richeditor.config.upload_directory%'
$imageTargetPath: '%monsieurbiz.richeditor.config.image_upload_directory%'
$publicDirectory: '%kernel.project_dir%/public'

MonsieurBiz\SyliusRichEditorPlugin\Uploader\FileUploaderInterface: '@MonsieurBiz\SyliusRichEditorPlugin\Uploader\FileUploader'
2 changes: 1 addition & 1 deletion src/Uploader/FileUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;

class FileUploader
class FileUploader implements FileUploaderInterface
{
public const FILE_TYPE_DOCUMENT = 'document';

Expand Down
24 changes: 24 additions & 0 deletions src/Uploader/FileUploaderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/*
* This file is part of Monsieur Biz' Rich Editor plugin for Sylius.
*
* (c) Monsieur Biz <sylius@monsieurbiz.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace MonsieurBiz\SyliusRichEditorPlugin\Uploader;

use Symfony\Component\HttpFoundation\File\UploadedFile;

interface FileUploaderInterface
{
/**
* Upload a file and return the path to it.
*/
public function upload(UploadedFile $file, ?string $type = null): string;
}

0 comments on commit eb07151

Please sign in to comment.