Commit be6e27a2 authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Ajout du UploadedFileTransformer.

Showing with 74 additions and 0 deletions
+74 -0
<?php
/*
* Copyright (C) 2015 IRSTEA
* All rights reserved.
*/
namespace Irstea\FileUploadBundle\Form\DataTranformer;
use Irstea\FileUploadBundle\Entity\UploadedFile;
use Irstea\FileUploadBundle\Service\FileManagerInterface;
use Symfony\Component\Form\DataTransformerInterface;
/**
* Description of UploadedFileTransformer
*/
class UploadedFileTransformer implements DataTransformerInterface
{
/**
*
* @var boolean
*/
private $multiple;
/**
*
* @var FileManagerInterface
*/
private $fileManager;
public function __construct(FileManagerInterface $fileManager, $multiple = false)
{
$this->fileManager = $fileManager;
$this->multiple = $multiple;
}
/**
* {@inheritdoc}
*/
public function reverseTransform($value)
{
$result = $value instanceof UploadedFile ? $value : (is_string($value) ? $this->reverseTransformFile($value) : null);
return $result;
}
/**
* {@inheritdoc}
*/
public function transform($value)
{
$result = $value instanceof UploadedFile ? $this->transformFile($value) : null;
return $result;
}
/**
*
* @param UploadedFile $file
* @return array
*/
protected function transformFile(UploadedFile $file)
{
return $file;
}
/**
*
* @param string $id
* @return UploadedFile
*/
protected function reverseTransformFile($id)
{
return $this->fileManager->get($id);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment