Skip to content

Commit

Permalink
use a kernel.terminate event listener instead of a bundle shutdown ho…
Browse files Browse the repository at this point in the history
…ok as it's not called properly at the end of each request (Symfony bug?)
  • Loading branch information
craue committed Aug 12, 2014
1 parent 1acf81b commit be101f1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
9 changes: 0 additions & 9 deletions CraueFormFlowBundle.php
Expand Up @@ -2,7 +2,6 @@

namespace Craue\FormFlowBundle;

use Craue\FormFlowBundle\Util\TempFileUtil;
use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
Expand All @@ -11,12 +10,4 @@
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
class CraueFormFlowBundle extends Bundle {

/**
* {@inheritDoc}
*/
public function shutdown() {
TempFileUtil::removeTempFiles();
}

}
21 changes: 21 additions & 0 deletions EventListener/KernelTerminateEventListener.php
@@ -0,0 +1,21 @@
<?php

namespace Craue\FormFlowBundle\EventListener;

use Craue\FormFlowBundle\Util\TempFileUtil;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;

/**
* Removes all temporary files created while handling file uploads.
*
* @author Christian Raue <christian.raue@gmail.com>
* @copyright 2011-2014 Christian Raue
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
class KernelTerminateEventListener {

public function onKernelTerminate(PostResponseEvent $event) {
TempFileUtil::removeTempFiles();
}

}
6 changes: 6 additions & 0 deletions Resources/config/form_flow.xml
Expand Up @@ -14,6 +14,8 @@
<parameter key="craue.form.flow.storage.class">Craue\FormFlowBundle\Storage\SessionStorage</parameter>
<parameter key="craue.form.flow.event_listener.previous_step_invalid.class">Craue\FormFlowBundle\EventListener\PreviousStepInvalidEventListener</parameter>
<parameter key="craue.form.flow.event_listener.previous_step_invalid.event" type="constant">Craue\FormFlowBundle\Form\FormFlowEvents::PREVIOUS_STEP_INVALID</parameter>
<parameter key="craue.form.flow.event_listener.kernel_terminate.class">Craue\FormFlowBundle\EventListener\KernelTerminateEventListener</parameter>
<parameter key="craue.form.flow.event_listener.kernel_terminate.event" type="constant">Symfony\Component\HttpKernel\KernelEvents::TERMINATE</parameter>
</parameters>

<services>
Expand Down Expand Up @@ -52,5 +54,9 @@
<argument type="service" id="translator" />
</call>
</service>

<service id="craue.form.flow.event_listener.kernel_terminate" class="%craue.form.flow.event_listener.kernel_terminate.class%">
<tag name="kernel.event_listener" event="%craue.form.flow.event_listener.kernel_terminate.event%" method="onKernelTerminate" />
</service>
</services>
</container>
2 changes: 2 additions & 0 deletions Util/TempFileUtil.php
Expand Up @@ -31,6 +31,8 @@ public static function removeTempFiles() {
unlink($tempFile);
}
}

self::$tempFiles = array();
}

}

0 comments on commit be101f1

Please sign in to comment.