-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
546 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace Craue\FormFlowBundle\Storage; | ||
|
||
use Craue\FormFlowBundle\Exception\InvalidTypeException; | ||
use Craue\FormFlowBundle\Util\TempFileUtil; | ||
use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
|
||
/** | ||
* Representation of a serializable file. Only supports {@code UploadedFile} currently. | ||
* | ||
* @author Christian Raue <christian.raue@gmail.com> | ||
* @copyright 2011-2014 Christian Raue | ||
* @license http://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
class SerializableFile { | ||
|
||
protected $content; | ||
protected $type; // for possible future support of further types | ||
|
||
protected $clientOriginalName; | ||
protected $clientMimeType; | ||
protected $clientSize; | ||
|
||
/** | ||
* @param mixed $file An object meant to be serialized. | ||
* @throws InvalidTypeException If the type of {@code $file} is unsupported. | ||
*/ | ||
public function __construct($file) { | ||
if (!self::isSupported($file)) { | ||
throw new InvalidTypeException($file, 'Symfony\Component\HttpFoundation\File\UploadedFile'); | ||
} | ||
|
||
$this->content = base64_encode(file_get_contents($file->getPathname())); | ||
$this->type = 'Symfony\Component\HttpFoundation\File\UploadedFile'; | ||
|
||
$this->clientOriginalName = $file->getClientOriginalName(); | ||
$this->clientMimeType = $file->getClientMimeType(); | ||
$this->clientSize = $file->getClientSize(); | ||
} | ||
|
||
/** | ||
* @param string|null $tempDir Directory for storing temporary files. If {@code null}, the system's default will be used. | ||
* @return mixed The unserialized object. | ||
*/ | ||
public function getAsFile($tempDir = null) { | ||
if ($tempDir === null) { | ||
$tempDir = sys_get_temp_dir(); | ||
} | ||
|
||
// create a temporary file with its original content | ||
$tempFile = tempnam($tempDir, 'craue_form_flow_serialized_file'); | ||
file_put_contents($tempFile, base64_decode($this->content)); | ||
|
||
TempFileUtil::addTempFile($tempFile); | ||
|
||
return new UploadedFile($tempFile, $this->clientOriginalName, $this->clientMimeType, $this->clientSize, null, true); | ||
} | ||
|
||
/** | ||
* @param mixed $file | ||
* @return boolean | ||
*/ | ||
public static function isSupported($file) { | ||
return $file instanceof UploadedFile; | ||
} | ||
|
||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
some text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Craue\FormFlowBundle\Tests\IntegrationTestBundle\Entity; | ||
|
||
use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
/** | ||
* @author Christian Raue <christian.raue@gmail.com> | ||
* @copyright 2011-2014 Christian Raue | ||
* @license http://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
class PhotoUpload { | ||
|
||
/** | ||
* @var UploadedFile | ||
* @Assert\NotNull(groups={"flow_photoUpload_step1"}) | ||
* @Assert\Image(groups={"flow_photoUpload_step1"}) | ||
*/ | ||
public $photo; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $comment; | ||
|
||
public function getPhotoDataBase64Encoded() { | ||
return base64_encode(file_get_contents($this->photo->getPathname())); | ||
} | ||
|
||
public function getPhotoMimeType() { | ||
return $this->photo->getMimeType(); | ||
} | ||
|
||
} |
Oops, something went wrong.