Skip to content

Instantly share code, notes, and snippets.

@coreymcmahon
Created April 18, 2019 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coreymcmahon/9f5a5d9bde803a3c6927f5b38da8f8d3 to your computer and use it in GitHub Desktop.
Save coreymcmahon/9f5a5d9bde803a3c6927f5b38da8f8d3 to your computer and use it in GitHub Desktop.
Demonstration of a Symfony console command.
<?php
namespace App;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class CleanTempCommand extends Command
{
protected static $defaultName = 'app:clean-temp';
protected function configure()
{
$this
->setDescription('Clears out the temporary files folder.');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$unlinked = 0;
foreach (glob("storage/tmp/*.*") as $file) {
unlink($file);
$unlinked++;
}
$output->writeln("\nUnlinked {$unlinked} files.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment