本文整理汇总了PHP中Symfony\Component\Console\Helper\ProgressBar::setFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP ProgressBar::setFormat方法的具体用法?PHP ProgressBar::setFormat怎么用?PHP ProgressBar::setFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Helper\ProgressBar
的用法示例。
在下文中一共展示了ProgressBar::setFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepare
/**
* {@inheritdoc}
*/
public function prepare()
{
$this->progress = new ProgressBar($this->output, $this->reader->count());
$this->progress->setFormat($this->verbosity);
$this->progress->setRedrawFrequency($this->redrawFrequency);
$this->progress->start();
}
示例2: advanceProgress
/**
* @param TaskEvent $event
*/
public function advanceProgress(TaskEvent $event)
{
$taskReflection = new ReflectionClass($event->getTask());
$taskName = $taskReflection->getShortName();
$this->progressBar->setFormat($this->progressFormat);
$this->progressBar->setMessage($taskName);
$this->progressBar->advance();
}
示例3: startProgress
protected function startProgress($num = 2)
{
if (!$this->getOutput()) {
throw new \Exception('Unable to find console output object.');
}
$this->bar = new ProgressBar($this->getOutput(), $num);
$this->bar->setFormat("%message%\n [%bar%] %percent:3s%% %elapsed% %memory:6s% ");
$this->bar->start();
}
示例4: onStartedProviding
public function onStartedProviding(HasStartedProviding $event)
{
$this->output->writeln(sprintf('<info> - Running <comment>%s</comment> provider into <comment>%s/%s</comment></info>', get_class($event->getEntry()->getProvider()), $event->getEntry()->getIndex(), $event->getEntry()->getType()));
$count = $event->getEntry()->getProvider()->count();
if (null !== $count) {
$this->progressBar = new ProgressBar($this->output, $count);
$this->progressBar->setFormat(self::PROGRESS_BAR_TEMPLATE);
}
}
示例5: getProgressBar
/**
* @return \Symfony\Component\Console\Helper\ProgressBar
*/
private function getProgressBar()
{
if ($this->progressBar === null) {
$this->progressBar = new ProgressBar($this->output, $this->getFileCount());
$this->progressBar->setFormat("%message%\n%current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%");
$this->output->writeln('');
}
return $this->progressBar;
}
示例6: finishProgress
/**
* @param RunnerEvent $runnerEvent
*/
public function finishProgress(RunnerEvent $runnerEvent)
{
if ($this->progressBar->getProgress() != $this->progressBar->getMaxSteps()) {
$this->progressBar->setFormat('<fg=red>%message%</fg=red>');
$this->progressBar->setMessage('Aborted ...');
}
$this->progressBar->finish();
$this->output->writeln('');
}
示例7: start
/**
* {@inheritdoc}
*/
public function start($count, $label = '')
{
$this->count = $count;
$this->current = 0;
if ($label) {
$this->output->writeln($label);
}
$this->progress = new ProgressBar($this->output, $count);
$this->progress->setFormat('very_verbose');
}
示例8: serve
/**
* @return int|null|void
*/
protected function serve()
{
$this->progress = new ProgressBar($this->output);
$this->progress->setFormat('Archiving <cyan>%current%</cyan> files [<green>%bar%</green>] %elapsed:6s% %memory:6s%');
Grav::instance()['config']->init();
$destination = $this->input->getArgument('destination') ? $this->input->getArgument('destination') : null;
$log = JsonFile::instance(Grav::instance()['locator']->findResource("log://backup.log", true, true));
$backup = ZipBackup::backup($destination, [$this, 'output']);
$log->content(['time' => time(), 'location' => $backup]);
$log->save();
$this->output->writeln('');
$this->output->writeln('');
}
示例9: mainProgressBarAction
/**
* @param $total
* @param OutputInterface $output
* @param callable $callback
*/
public function mainProgressBarAction($total, $output, callable $callback)
{
// Перенос строки
$output->writeln("\n");
// Инициализируем прогресс бар
$progress = new ProgressBar($output, $total);
$progress->setFormat("<info>%message%\n Фильм %current% из %max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%</info>");
$progress->setMessage('Процесс запущен');
$progress->start();
// Инициализируем цикл и выполняем
$progress->setMessage('В процессе...');
for ($i = 0; $i < $total; $i++) {
// Задержка
sleep(Config::DELAY_BETWEEN_REQUESTS);
// Выполняем колбэк
$callback();
// Передвигаем прогресс бар
$progress->advance();
}
// Завершаем прогресс бар
$progress->setMessage('Процесс завершен');
$progress->finish();
// Перенос строки
$output->writeln("\n");
}
示例10: 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();
}
示例11: 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);
}
示例12: 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));
}
示例13: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->configuration = $this->getHelperSet()->get('configuration')->getConfiguration();
$this->entityManager = $this->getHelperSet()->get('em')->getEntityManager();
$this->questionHelper = $this->getHelperSet()->get('question');
if (!empty($this->configuration['assetsProcessing']['maxPixelSize']) && $this->configuration['assetsProcessing']['maxPixelSize'] > 0) {
$this->downscaler = new DownscaleImageManager($this->entityManager, null, $this->configuration['assetsProcessing']['driver'], $this->configuration['assetsProcessing']['maxPixelSize']);
$confirmation = new ConfirmationQuestion('<question>Are you sure to downscale all your image documents to ' . $this->configuration['assetsProcessing']['maxPixelSize'] . 'px?</question>', false);
if ($this->questionHelper->ask($input, $output, $confirmation)) {
$documents = $this->entityManager->getRepository('RZ\\Roadiz\\Core\\Entities\\Document')->findBy(['mimeType' => ['image/png', 'image/jpeg', 'image/gif', 'image/tiff'], 'raw' => false]);
$progress = new ProgressBar($output, count($documents));
$progress->setFormat('verbose');
$progress->start();
foreach ($documents as $document) {
$this->downscaler->processDocumentFromExistingRaw($document);
$progress->advance();
}
$progress->finish();
$text = PHP_EOL . '<info>Every documents have been downscaled, a raw version has been kept.</info>' . PHP_EOL;
/*
* Clear cache documents
*/
$assetsClearer = new AssetsClearer();
$assetsClearer->clear();
$text .= $assetsClearer->getOutput() . PHP_EOL;
}
} else {
$text = '<info>Your configuration is not set for downscaling documents.</info>' . PHP_EOL;
$text .= 'Add <info>assetsProcessing.maxPixelSize</info> parameter in your <info>config.yml</info> file.' . PHP_EOL;
}
$output->writeln($text);
}
示例14: reindex
private function reindex(string $locale, OutputInterface $output)
{
$totalEntities = $this->repository->getTotalCount();
$iterations = $this->getIterations($totalEntities, $this->batchSize);
$output->writeln(sprintf('<comment>Total entities:</comment> %s', $totalEntities));
$output->writeln(sprintf('<comment>Batch size:</comment> %s', $this->batchSize));
$output->writeln(sprintf('<comment>Iterations:</comment> %s', count($iterations)));
$output->writeln(sprintf('<comment>Locale:</comment> %s', $locale));
$output->writeln('<info>Flushing index</info>');
$this->manager->flushIndex($locale);
$progress = new ProgressBar($output, $totalEntities);
$progress->setFormat('verbose');
$progress->setRedrawFrequency($this->batchSize);
$progress->start();
foreach ($iterations as $iteration) {
$entities = $this->getEntities($iteration);
foreach ($entities as $entity) {
$document = $this->type->createDocument($entity, $locale);
$this->manager->addDocument($document);
$progress->advance();
}
}
$progress->finish();
$output->writeln('');
$output->writeln('<info>Optimizing index</info>');
$this->manager->optimizeIndex($locale);
}
示例15: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var ImportAddressService $importAddressService */
$importAddressService = $this->getHelper('container')->getByType('StreetApi\\Services\\ImportAddressService');
$cityId = $input->getArgument('cityId');
$xmlFile = simplexml_load_file($importAddressService->getRootDir() . '/../adresy.xml');
if (!$xmlFile) {
$output->writeln(PHP_EOL . '<error>Missing source file!</error>');
return 1;
}
try {
$output->writeLn('<info>Start importing addresses</info>');
$totalCount = $xmlFile->count();
$output->writeln(PHP_EOL . PHP_EOL . PHP_EOL . PHP_EOL);
$progressBar = new ProgressBar($output, $totalCount);
$progressBar->setFormat('%message%' . PHP_EOL . '%bar% %percent:3s% %' . PHP_EOL . 'count: %current%/%max%' . PHP_EOL . 'time: %elapsed:6s%/%estimated:-6s%' . PHP_EOL);
$progressBar->setBarCharacter('<info>■</info>');
$progressBar->setEmptyBarCharacter(' ');
$progressBar->setProgressCharacter('');
$progressBar->setRedrawFrequency(ceil($totalCount / 100));
$progressBar->start();
$importAddressService->import($xmlFile, $progressBar, $cityId);
$output->writeLn(PHP_EOL . '<info>Importing addresses finished</info>');
return 0;
} catch (\Exception $e) {
$output->writeLn('<error>' . $e->getMessage() . '</error>');
return 1;
}
}