本文整理汇总了PHP中Symfony\Component\Console\Helper\ProgressBar::display方法的典型用法代码示例。如果您正苦于以下问题:PHP ProgressBar::display方法的具体用法?PHP ProgressBar::display怎么用?PHP ProgressBar::display使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Helper\ProgressBar
的用法示例。
在下文中一共展示了ProgressBar::display方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Run the command.
*
* @param InputInterface $input
* @param OutputInterface $output
*
* @return void
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$serviceName = $input->getArgument('service');
$service = $this->serviceManager->getService($serviceName);
$hostProvider = $service->getHostProvider();
$this->getApplication()->find('listhosts')->run(new ArrayInput(['service' => $serviceName]), $output);
$output->writeln("");
$progress = new ProgressBar($output, 5);
$progress->setFormat(' %current%/%max% [%bar%] %percent:3s%% %message%');
$progress->setMessage('Checking existing hosts');
$progress->start();
$currentHostCount = count($hostProvider->getHostsForService($service));
if ($service->maxHosts && $currentHostCount >= $service->maxHosts) {
throw new Exception("There are already {$currentHostCount}/{$service->maxHosts} hosts for {$serviceName}.");
}
$newInstance = $currentHostCount + 1;
$hostname = sprintf($service->hostnameTemplate, $newInstance);
$host = $hostProvider->launch($hostname, $service->hostDefaults);
$hostname = $host->getHostname();
// Just check it set the right name
$progress->setMessage("Created host " . $hostname . " at " . $hostProvider->getName());
$progress->advance();
sleep(5);
$progress->setMessage("Waiting for " . $hostname . " to be ready");
$progress->advance();
while (!$host->isReady()) {
$lastState = $host->getState();
$progress->setMessage("Waiting for " . $hostname . " to be ready (Current sate: " . $lastState . ")");
$progress->display();
sleep(10);
}
if (!empty($service->testUrl)) {
$progress->setMessage("Testing host's HTTP response");
$progress->advance();
do {
$lastResponse = $host->testHttp($service->testUrl, $service->testUrlHeaders);
$progress->setMessage("Testing host's HTTP response (Current response: {$lastResponse})");
$progress->display();
$lastResponse === 200 || sleep(5);
} while ($lastResponse !== 200);
}
$dnsProvider = $service->getDnsProvider();
$recordData = [];
foreach ($host->publicIps as $ip) {
foreach ($service->dnsRecords as $domain => $domainRecords) {
foreach ($domainRecords as $record => $recordSettings) {
$data = ['domain' => $domain, 'type' => $ip->version === 6 ? 'AAAA' : 'A', 'name' => sprintf($record, $newInstance), 'value' => $ip->ip];
$recordData[] = $data + $recordSettings;
}
}
}
$progress->setMessage("Adding " . count($recordData) . " DNS records to " . $dnsProvider->getName());
$progress->advance();
$dnsProvider->addRecords($recordData);
$progress->setMessage('Done!');
$progress->finish();
$output->writeln("");
$output->writeln("");
$this->getApplication()->find('listhosts')->run(new ArrayInput(['service' => $serviceName]), $output);
}
示例2: showProgressIndicator
public function showProgressIndicator()
{
if ($this->progressIndicatorRunning && !$this->progressBarDisplayed && isset($this->progressBar)) {
$this->progressBar->display();
$this->progressBarDisplayed = true;
$this->advanceProgressIndicatorCachedSteps();
}
}
示例3: advance
/**
* @param int $current
* @param PhpFileInfo $file
*/
public function advance($current, PhpFileInfo $file)
{
if (!$this->verbose) {
return;
}
if (1 === $current) {
$format = '<info>%message%</info>' . "\n" . $this->label . ': <info>%current%</info>/<info>%max%</info>';
$this->progressBar->clear();
$this->progressBar->setFormat($format);
}
$message = $file->getRelativePathname();
$this->progressBar->setMessage($message);
$this->progressBar->clear();
$this->progressBar->advance();
$this->progressBar->display();
}
示例4: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if (!Loader::includeModule('search')) {
throw new BitrixException('Search module is not installed');
}
$searchResult = array();
$bar = new ProgressBar($output, 0);
do {
$bar->display();
$searchResult = \CSearch::ReIndexAll($input->getOption('full'), static::UPDATE_TIME, $searchResult);
$bar->advance();
$bar->clear();
if (is_array($searchResult) && $searchResult['MODULE'] == 'main') {
list(, $path) = explode("|", $searchResult["ID"], 2);
$output->writeln("\r " . $path, OutputInterface::VERBOSITY_VERBOSE);
}
} while (is_array($searchResult));
$bar->finish();
$bar->clear();
$output->write("\r");
if (ModuleManager::isModuleInstalled('socialnetwork')) {
$output->writeln('<info>The Social Network module needs to be reindexed using the Social Network component in the public section of site.</info>');
}
$output->writeln(sprintf('<info>Reindexed</info> %d element%s.', $searchResult, $searchResult > 1 ? 's' : ''));
return 0;
}
示例5: makeRateLimitedRequest
/**
* TODO change interface to method passing in configuration object (which is validated)
*
* Perform a rate-limited API call. The flow is:
* 1. requestFunction()
* 2. processFunction() based on requestFunction result
* 3. publishFunction() based on processFunction result
*
* Only requestFunction() and serviceName are required fields.
*
* @param $serviceName
* @param callable $requestFunction should return a list for processing
* @param callable $processFunction must return a list of models for publishing
* @param callable $publishFunction method to upload models; responsible for handling publication failures
* @return mixed
*/
public function makeRateLimitedRequest($serviceName, $requestFunction, $processFunction = null, $publishFunction = null)
{
$rateLimit = self::$rate_limits[$serviceName];
if (SyncCommandBase::$requests_processed_this_minute[$serviceName] >= $rateLimit) {
$seconds_to_sleep = 60 - (time() - SyncCommandBase::$start_of_minute_timestamp[$serviceName]);
if ($seconds_to_sleep > 0) {
$this->progressBar->setMessage("Rate limit reached for '{$serviceName}'. Waiting {$seconds_to_sleep} seconds.");
$this->progressBar->display();
sleep($seconds_to_sleep);
$this->progressBar->setMessage("");
}
SyncCommandBase::$start_of_minute_timestamp[$serviceName] = time();
SyncCommandBase::$requests_processed_this_minute[$serviceName] = 0;
} elseif (time() - SyncCommandBase::$start_of_minute_timestamp[$serviceName] > 60) {
SyncCommandBase::$start_of_minute_timestamp[$serviceName] = time();
SyncCommandBase::$requests_processed_this_minute[$serviceName] = 0;
}
$response = $requestFunction();
SyncCommandBase::$requests_processed_this_minute[$serviceName]++;
if ($processFunction != null) {
/** @var callable $processFunction */
$processedModels = $processFunction($response);
if ($publishFunction != null) {
/** @var callable $publishFunction */
$publishFunction($processedModels);
}
} else {
// don't do anything
}
return $response;
}
示例6: setProgressBar
/**
* Set progress bar. Once a progress bar has been set on an invoker, it
* cannot be undone. Instantiate a new invoker if needed. Sub sequent calls
* to `Invoker::execute()` will reuse the progress bar object.
*
* @param ProgressBar $bar
* @return Invoker
*/
public function setProgressBar(ProgressBar $bar)
{
// start progress bar
$this->dispatcher->addListener(Events::INVOKER_START, function (InvokerEvent $event) use($bar) {
$bar->start($event->getSteps()->getUnits());
});
// finish progress bar
$this->dispatcher->addListener(Events::INVOKER_FINISH, function (InvokerEvent $event) use($bar) {
$bar->setMessage('Finished: ' . $event->getSteps()->getName());
$bar->finish();
});
// step start
$this->dispatcher->addListener(Events::STEP_BEFORE_EXECUTE, function (StepEvent $event) use($bar) {
$bar->setMessage($event->getStep()->getDescription() . '...');
$bar->display();
});
// step finish
$this->dispatcher->addListener(Events::STEP_AFTER_EXECUTE, function (StepEvent $event) use($bar) {
$bar->advance($event->getStep()->getTicksRemaining());
});
// step tick
$this->dispatcher->addListener(Events::STEP_TICK, function (StepEvent $event) use($bar) {
$bar->advance($event->getStep()->getTick());
});
return $this;
}
示例7: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$io->title('Exporting databases');
$io->section('Exporting all databases');
$strategies = $this->collectorDbStrategy->collectDatabasesStrategies();
$totalStrategies = count($strategies);
$io->writeln($totalStrategies . ' strategie(s) found.');
$progressBar = new ProgressBar($output, $totalStrategies);
$progressBar->setFormat(self::PROGRESS_BAR_FORMAT);
$progressBar->setMessage('Beginning backuping');
$this->eventDispatcher->dispatch(Events::BACKUP_BEGINS, new BackupBeginsEvent($output));
$progressBar->start();
$reportContent = new \ArrayObject();
foreach ($strategies as $strategy) {
$strategyIdentifier = $strategy->getIdentifier();
$setProgressBarMessage = function ($message) use($progressBar, $strategyIdentifier) {
$message = "[{$strategyIdentifier}] {$message}";
$progressBar->setMessage($message);
$progressBar->display();
};
$exportedFiles = $this->processorDatabaseDumper->dump($strategy, $setProgressBarMessage);
$reportContent->append("Backuping of the database: {$strategyIdentifier}");
foreach ($exportedFiles as $file) {
$filename = $file->getPath();
$reportContent->append("\t→ {$filename}");
}
$progressBar->advance();
}
$progressBar->finish();
$io->newLine(2);
$io->section('Report');
$io->text($reportContent->getArrayCopy());
$this->eventDispatcher->dispatch(Events::BACKUP_ENDS, new BackupEndsEvent($output));
}
示例8: add_success_message
/**
* {@inheritdoc
*/
public function add_success_message($error_title, $error_description = false)
{
$this->io->newLine();
$message = $this->translate_message($error_title, $error_description);
$this->io->success($message['title'] . "\n" . $message['description']);
if ($this->progress_bar !== null) {
$this->io->newLine(2);
$this->progress_bar->display();
}
}
示例9: run
public function run()
{
foreach ($this->processes as $process) {
/** @var $process Process **/
$process->setIdleTimeout($this->idleTimeout);
$process->setTimeout($this->timeout);
$process->start();
$this->printTaskInfo($process->getCommandLine());
}
$progress = new ProgressBar($this->getOutput());
$progress->start(count($this->processes));
$running = $this->processes;
$progress->display();
$this->startTimer();
while (true) {
foreach ($running as $k => $process) {
try {
$process->checkTimeout();
} catch (ProcessTimedOutException $e) {
}
if (!$process->isRunning()) {
$progress->advance();
if ($this->isPrinted) {
$this->getOutput()->writeln("");
$this->printTaskInfo("Output for <fg=white;bg=magenta> " . $process->getCommandLine() . " </fg=white;bg=magenta>");
$this->getOutput()->writeln($process->getOutput(), OutputInterface::OUTPUT_RAW);
if ($process->getErrorOutput()) {
$this->getOutput()->writeln("<error>" . $process->getErrorOutput() . "</error>");
}
}
unset($running[$k]);
}
}
if (empty($running)) {
break;
}
usleep(1000);
}
$this->getOutput()->writeln("");
$this->stopTimer();
$errorMessage = '';
$exitCode = 0;
foreach ($this->processes as $p) {
if ($p->getExitCode() === 0) {
continue;
}
$errorMessage .= "'" . $p->getCommandLine() . "' exited with code " . $p->getExitCode() . " \n";
$exitCode = max($exitCode, $p->getExitCode());
}
if (!$errorMessage) {
$this->printTaskSuccess(count($this->processes) . " processes finished running");
}
return new Result($this, $exitCode, $errorMessage, ['time' => $this->getExecutionTime()]);
}
示例10: build
/**
* Builds a loggerClosure to be called from inside the Provider to update the command
* line.
*
* @param OutputInterface $output
* @param string $action
* @param string $index
* @param string $type
*
* @return callable
*/
public function build(OutputInterface $output, $action, $index, $type)
{
if (!class_exists('Symfony\\Component\\Console\\Helper\\ProgressBar') || !is_callable(array('Symfony\\Component\\Console\\Helper\\ProgressBar', 'getProgress'))) {
return $this->buildLegacy($output, $action, $index, $type);
}
$progress = null;
return function ($increment, $totalObjects, $message = null) use(&$progress, $output, $action, $index, $type) {
if (null === $progress) {
$progress = new ProgressBar($output, $totalObjects);
$progress->start();
}
if (null !== $message) {
$progress->clear();
$output->writeln(sprintf('<info>%s</info> <error>%s</error>', $action, $message));
$progress->display();
}
$progress->setMessage(sprintf('<info>%s</info> <comment>%s/%s</comment>', $action, $index, $type));
$progress->advance($increment);
};
}
示例11: execute
public function execute(InputInterface $input, OutputInterface $output)
{
$db = $input->getOption('db') === true;
$db_path = false;
if ($db) {
$db_path = $this->config->db . $this->getTimestamp() . '.sql';
$command = new Database();
$arguments = ['--export' => $db_path];
$arguments = new ArrayInput($arguments);
$command->run($arguments, $output);
$db_path = realpath($db_path);
}
$output->writeln('<info>Scanning files</info>');
$files = $this->getJoomlaFiles($db_path, [getcwd() . '/.private']);
$output->writeln("<info>Archiving files</info>");
$path = getcwd() . DIRECTORY_SEPARATOR . $this->name . $this->getTimestamp() . '.zip';
$zip = new \ZipArchive();
if (true !== $zip->open($path, \ZipArchive::CREATE)) {
throw new \RuntimeException("Can't open {$path}.");
}
$progress = new ProgressBar($output, count($files));
$progress->display();
foreach ($files as $file) {
if (!$file->isDir()) {
$realpath = $file->getRealPath();
$localname = str_replace(getcwd() . DIRECTORY_SEPARATOR, '', $realpath);
$zip->addFile($realpath, $localname);
}
$progress->advance();
}
$progress->finish();
$output->writeln('');
$output->write("<info>Finalizing archive...</info>");
$zip->close();
if ($db_path) {
unlink($db_path);
}
$output->writeln(" <info>Done: " . basename($path) . "</info>");
}
示例12: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$batchSize = $input->getOption('batch-size');
/** @var EntityManagerInterface $entityManager */
$entityManager = $this->getContainer()->get('doctrine.orm.entity_manager');
$routeManager = $this->getContainer()->get('sulu_route.manager.route_manager');
/** @var EntityRepository $repository */
$repository = $entityManager->getRepository($input->getArgument('entity'));
$query = $repository->createQueryBuilder('entity')->select('count(entity.id)')->getQuery();
$result = $query->getResult();
$count = (int) $result[0][1];
$query = $repository->createQueryBuilder('entity')->getQuery();
$output->writeln(sprintf('<comment>updating route for "%s" instances of "%s"</comment>', $count, $input->getArgument('entity')));
$progressBar = new ProgressBar($output, $count);
$progressBar->setFormat('debug');
$progressBar->display();
$index = 0;
foreach ($query->iterate() as $item) {
$entity = $item[0];
if (null !== $entity->getRoute()) {
$routeManager->update($entity);
} else {
$entityManager->persist($routeManager->create($entity));
}
$progressBar->advance();
$entity = null;
if (0 === $index++ % $batchSize) {
$entityManager->flush();
// trigger garbage collect
$entityManager->clear();
}
}
// flush the rest of the entities
$entityManager->flush();
//$progressBar->finish();
$output->writeln('');
}
示例13: createProgressBar
/**
* @param int $width
*
* @return ProgressBar
*/
private function createProgressBar($width)
{
$progress = new ProgressBar($this->output, $width);
$progress->setBarWidth(50);
$progress->display();
return $progress;
}
示例14: catch
$phpExcel->getActiveSheet()->setCellValue('B' . $i, $book['authors']);
$phpExcel->getActiveSheet()->setCellValue('C' . $i, $book['publisher']);
$phpExcel->getActiveSheet()->setCellValue('D' . $i, $book['description']);
$phpExcel->getActiveSheet()->setCellValue('E' . $i, $book['pageCount']);
$phpExcel->getActiveSheet()->setCellValue('F' . $i, $book['imageLink']);
$i++;
} catch (BookNotFoundException $e) {
$app['monolog']->addError($e->getMessage());
} catch (ApiException $e) {
$app['monolog']->addError($e->getMessage());
}
$progress->advance();
}
$progress->setMessage('<comment>Search ready</comment>');
$progress->clear();
$progress->display();
$progress->finish();
$output->writeln('');
$output->writeln("<info>Saving data in {$target}</info>");
$phpExcel->setActiveSheetIndex(0);
$writer = PHPExcel_IOFactory::createWriter($phpExcel, 'Excel2007');
$writer->save($target);
$output->writeln("<info>Data saved in {$target}</info>");
break;
default:
$output->writeln('<error>Unrecognized API</error>');
break;
}
} else {
$output->writeln('<error>The target file ' . $source . ' does not exist</error>');
}
示例15: iterateFiles
/**
* @param ProgressBar $progressHelper
*/
private function iterateFiles(ProgressBar $progressHelper)
{
foreach ($this->getFinder()->getIterator() as $file) {
/** @var \Symfony\Component\Finder\SplFileInfo $file */
if (OutputInterface::VERBOSITY_VERBOSE <= $this->getOutput()->getVerbosity()) {
$progressHelper->clear();
$this->getOutput()->writeln("\r" . $file->getRealPath());
$progressHelper->display();
}
$this->getAnalyzer()->analyze($file);
$progressHelper->advance();
}
}