src/Listeners/ClearArtefactsListener.php
/**
     * Handle the event.
     *
     * @param \League\Event\EventInterface $event The event that triggered the listener
     *
     * @return void
     */
Handle the event.
@param \League\Event\EventInterface $event The event that triggered the listener

@return void
Handle the event . @param \ League \ Event \ EventInterface $event The event that triggered the listener @return void
public function handle(EventInterface $event)
    {
        if (!$this->getConfiguration()->haveClearArtefacts()) {
            $this->getSystemLogger()->info('Clear artefacts functionality has not been activated');
            return;
        }
        clearstatcache();
        $files = $this->getLoader()->load();
        $patterns = array();
        foreach ($files as $file) {
            $elements = explode('_', pathinfo($file, PATHINFO_FILENAME));
            for ($i = sizeof($elements); $i > 0; $i--) {
                $filename = implode('_', array_slice($elements, 0, $i));
                $patterns[$filename] = sprintf('%s/%s.*', dirname($file), $filename);
            }
        }
        usort($patterns, function ($a, $b) {
            return strcmp($a, $b);
        });
        foreach ($patterns as $pattern) {
            foreach (glob($pattern) as $filename) {
                $this->getFilesystemAdapter()->delete($filename);
            }
        }
    }
public function handle ( EventInterface $ event ) { if ( ! $ this -> getConfiguration ( ) -> haveClearArtefacts ( ) ) { $ this -> getSystemLogger ( ) -> info ( 'Clear artefacts functionality has not been activated' ) ; return ; } clearstatcache ( ) ; $ files = $ this -> getLoader ( ) -> load ( ) ; $ patterns = array ( ) ; foreach ( $ files as $ file ) { $ elements = explode ( '_' , pathinfo ( $ file , PATHINFO_FILENAME ) ) ; for ( $ i = sizeof ( $ elements ) ; $ i > 0 ; $ i -- ) { $ filename = implode ( '_' , array_slice ( $ elements , 0 , $ i ) ) ; $ patterns [ $ filename ] = sprintf ( '%s/%s.*' , dirname ( $ file ) , $ filename ) ; } } usort ( $ patterns , function ( $ a , $ b ) { return strcmp ( $ a , $ b ) ; } ) ; foreach ( $ patterns as $ pattern ) { foreach ( glob ( $ pattern ) as $ filename ) { $ this -> getFilesystemAdapter ( ) -> delete ( $ filename ) ; } } }
Handle the event.
Handle the event .
// query whether or not we've to clear the artefacts // clear the filecache // load the serial and directories to clear // initialize the array for the patterns // iterate over the artefacts and clear // them as well as the flag files // exctract the components of the artefact file // build filenames for the possible element combinations, // which is necesary because of the .OK file possiblities // prepare the filename to build the pattern with // prepare the glob pattern to load the artefact as well as it's flag files // sort the patterns // iterate over the patterns and delete the matching files // iterate over the found files and delete them