Created
December 16, 2020 20:09
-
-
Save BlackScorp/8d8b4b667b7626245ca17e7067034a6a to your computer and use it in GitHub Desktop.
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 | |
require_once __DIR__.'/vendor/autoload.php'; | |
require_once __DIR__.'/RandomCommand.php'; | |
use Symfony\Component\Console\Application; | |
$console = new Application(); | |
$console->add(new RandomCommand()); | |
$console->run(); |
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 | |
use Symfony\Component\Console\Command\Command; | |
use Symfony\Component\Console\Helper\ProgressBar; | |
use Symfony\Component\Console\Input\InputArgument; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Output\OutputInterface; | |
class RandomCommand extends Command{ | |
protected static $defaultName = 'test:show-random'; | |
public function configure(){ | |
$this->setDescription('Ein Programm welche Zufallszahlen generiert'); | |
$this->addArgument('maxNumber',InputArgument::OPTIONAL,'Maximale nummer die generiert wird',42); | |
} | |
public function execute(InputInterface $input,OutputInterface $output){ | |
$output->writeln("Programm start"); | |
$max = $input->getArgument('maxNumber'); | |
$randomNumber = random_int(0,$max); | |
$verboseOutput = $output->section(); | |
$normalOutput = $output->section(); | |
$progressBar = new ProgressBar($normalOutput,10); | |
for($i = 0;$i<10;$i++){ | |
sleep(1); | |
$verboseOutput->overwrite("ich zähle ".$i,OutputInterface::VERBOSITY_VERBOSE); | |
$progressBar->advance(); | |
} | |
$progressBar->finish(); | |
$output->write("\nIch habe lange nachgedacht und die Antwort lautet: ".$randomNumber); | |
return Command::SUCCESS; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To initialize usage of symfony console:
composer require symfony/console