From ea4c5c6405c1c5826bf4cca17197c6687255557b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Guillaume=20Perr=C3=A9al?= <guillaume.perreal@irstea.fr>
Date: Wed, 28 Jan 2015 15:25:35 +0100
Subject: [PATCH] =?UTF-8?q?UploadController:=20utilise=20la=20m=C3=A9thode?=
 =?UTF-8?q?=20UploadedFileInterface->toArray.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Controller/UploadController.php | 45 +++++++++++++++++----------------
 1 file changed, 23 insertions(+), 22 deletions(-)

diff --git a/Controller/UploadController.php b/Controller/UploadController.php
index cfcc654a..7c32e324 100644
--- a/Controller/UploadController.php
+++ b/Controller/UploadController.php
@@ -10,6 +10,7 @@ namespace Irstea\FileUploadBundle\Controller;
 use Irstea\FileUploadBundle\Entity\UploadedFile;
 use Irstea\FileUploadBundle\Http\UploadedFileResponse;
 use Irstea\FileUploadBundle\Model\FileManagerInterface;
+use Irstea\FileUploadBundle\Model\UploadedFileInterface;
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
@@ -77,18 +78,20 @@ class UploadController extends Controller
 
         $deleteUrl = $this->router->generate('file_upload_delete', $parameters);
 
-        return $this->createResponse(
-            Response::HTTP_CREATED,
-            'New file created',
-            [
-                'id'          => $file->getId(),
-                'put_url'     => $this->router->generate('file_upload_put_content', $parameters),
-                'delete_type' => 'DELETE',
-                'delete_url'  => $deleteUrl,
-            ],
-            // On a pas de get pour l'instant, le DELETE et ce qui y ressemble le plus
-            [ 'Location' => $deleteUrl ]
-        );
+            return $this->createResponse(
+                Response::HTTP_CREATED,
+                'New file created',
+                array_merge(
+                    $file->toArray(),
+                    [
+                        'put_url'     => $this->router->generate('file_upload_put_content', $parameters),
+                        'delete_type' => 'DELETE',
+                        'delete_url'  => $deleteUrl
+                    ]
+                ),
+                // On a pas de get pour l'instant, le DELETE et ce qui y ressemble le plus
+                [ 'Location' => $deleteUrl ]
+            );
     }
 
     /**
@@ -142,16 +145,14 @@ class UploadController extends Controller
             'File uploaded',
             [
                 'files' => [
-                    [
-                        'id'          => $file->getId(),
-                        'name'        => $file->getDisplayName(),
-                        'type'        => $file->getMimeType(),
-                        'size'        => $file->getSize(),
-                        'icon'        => MimeTypeIcon::getMimeTypeIcon($file->getMimeType()),
-                        'url'         => $this->router->generate('file_upload_get_content', $parameters),
-                        'delete_type' => 'DELETE',
-                        'delete_url'  => $this->router->generate('file_upload_delete', $parameters),
-                    ]
+                    array_merge(
+                        $file->toArray(),
+                        [
+                            'url'         => $this->router->generate('file_upload_get_content', $parameters),
+                            'delete_type' => 'DELETE',
+                            'delete_url'  => $this->router->generate('file_upload_delete', $parameters),
+                        ]
+                    )
                 ]
             ]
         );
-- 
GitLab