Skip to content

Instantly share code, notes, and snippets.

@ayalon
Last active December 29, 2015 15:19
Show Gist options
  • Save ayalon/7690324 to your computer and use it in GitHub Desktop.
Save ayalon/7690324 to your computer and use it in GitHub Desktop.
Example Progress Command
<?php
namespace Ayalon\ProductBundle\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class ProgressCommand extends Command
{
protected function configure()
{
$this
->setName('ayalon:progress')
->setDescription('Progress Test')
->addArgument(
'name',
InputArgument::OPTIONAL,
'Who do you want to greet?'
)
->addOption(
'yell',
null,
InputOption::VALUE_NONE,
'If set, the task will yell in uppercase letters'
)
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$name = $input->getArgument('name');
$progress = $this->getHelperSet()->get('progress');
$progress->start($output, 10);
$i = 0;
while ($i++ < 5) {
// ... do some work
//usleep(50000);
sleep(1);
$output->writeln('test line');
flush();
//$output->write('test line 2' . "\n");
$line = stream_get_line($output->getStream(),0, "\n");
$line = fgets($output->getStream());
echo 'test' . $line;
flush();
//rewind($output->getStream());
// advance the progress bar 1 unit
$progress->advance();
}
$progress->finish();
//$output->writeln($text);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment