I created a command that starts downloading files from the Internet, however, since these files must be processed by another component, we must make sure that every file that was downloaded and has not been modified in the last 10 seconds is the correct video and not damaged / partially downloaded .
For this reason, we need to find a way to catch CTRL + C or the completion of commands and clear any file that has not been successfully downloaded.
This is what I have tried so far, using symfony/consoleand symfony/event-dispatcher:
<?php
require_once(__DIR__ . '/../vendor/autoload.php');
use Symfony\Component\Console\Application;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Component\EventDispatcher\EventDispatcher;
use ImportExport\Console\ImportCommand;
use Monolog\Logger;
$dotenv = new Dotenv\Dotenv(__DIR__ . '/../');
$dotenv->load();
$logger = new Logger('console');
$dispatcher = new EventDispatcher();
$dispatcher->addListener(ConsoleEvents::TERMINATE, function (ConsoleTerminateEvent $event) {
$command = $event->getCommand();
var_dump($command);
});
$application = new Application("Import-Export System", 'v0.1.0-ALPHA');
$application->add(new ImportCommand($logger));
$application->setDispatcher($dispatcher);
$application->run();
However, it var_dump()never displays in the console if I do CTRL + C.
Suggestions?
source
share