Created
April 18, 2019 06:42
-
-
Save coreymcmahon/9f5a5d9bde803a3c6927f5b38da8f8d3 to your computer and use it in GitHub Desktop.
Demonstration of a Symfony console command.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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