Skip to content

Commit

Permalink
quick & dirty solution to remove temp files
Browse files Browse the repository at this point in the history
  • Loading branch information
craue committed Aug 11, 2014
1 parent 3939e62 commit c160923
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions CraueFormFlowBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,15 @@
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
class CraueFormFlowBundle extends Bundle {

public static $tempFiles = array();

public function shutdown() {
foreach (self::$tempFiles as $tempFile) {
if (is_file($tempFile)) {
unlink($tempFile);
}
}
}

}
3 changes: 3 additions & 0 deletions Storage/SerializableFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Craue\FormFlowBundle\Storage;

use Craue\FormFlowBundle\CraueFormFlowBundle;
use Symfony\Component\HttpFoundation\File\UploadedFile;

/**
Expand Down Expand Up @@ -43,6 +44,8 @@ public function getAsFile($tempDir = null) {
$pathToFile = tempnam($tempDir, 'craue_form_flow_serialized_file');
file_put_contents($pathToFile, base64_decode($this->content));

CraueFormFlowBundle::$tempFiles[] = $pathToFile;

return new UploadedFile($pathToFile, $this->clientOriginalName, $this->clientMimeType, $this->clientSize, null, true);
}

Expand Down
8 changes: 8 additions & 0 deletions Tests/Form/SerializableFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Craue\FormFlowBundle\Tests\Form;

use Craue\FormFlowBundle\CraueFormFlowBundle;
use Craue\FormFlowBundle\Storage\SerializableFile;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\File\File;
Expand All @@ -24,6 +25,13 @@ protected function tearDown() {
if ($this->tempFile !== null) {
unlink($this->tempFile);
}

foreach (CraueFormFlowBundle::$tempFiles as $tempFile) {
if (is_file($tempFile)) {
unlink($tempFile);
}
}

if ($this->tempFolder !== null) {
rmdir($this->tempFolder);
}
Expand Down

0 comments on commit c160923

Please sign in to comment.