本文整理汇总了PHP中Symfony\Component\Console\Helper\ProgressBar::advance方法的典型用法代码示例。如果您正苦于以下问题:PHP ProgressBar::advance方法的具体用法?PHP ProgressBar::advance怎么用?PHP ProgressBar::advance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Helper\ProgressBar
的用法示例。
在下文中一共展示了ProgressBar::advance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* {@inheritdoc}
*
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$buildId = $this->stdIn->getArgument('build');
$client = new Client(['base_uri' => 'https://api.travis-ci.org/', 'cookies' => true, 'headers' => ['User-Agent' => 'DrupalOrgCli/0.0.1', 'Accept' => 'application/json', 'Accept-Encoding' => '*']]);
$build = $this->getBuild($client, $buildId);
$this->stdOut->writeln("<comment>Watching build {$buildId}</comment>");
$progress = new ProgressBar($this->stdOut);
$progress->start();
if ($build->state == 'finished') {
$progress->advance();
} else {
while ($build->state != 'finished') {
$progress->advance();
sleep(60);
$build = $this->getBuild($client, $buildId);
}
}
$progress->finish();
$this->sendNotification('TravisCI', "TravisCI build {$buildId} completed");
$this->stdOut->writeln('');
$table = new Table($this->stdOut);
$table->setHeaders(['ID', 'Message', 'Result']);
if ($build->result == 0) {
$style = 'info';
$result = 'pass';
} elseif ($build->result == 1) {
$style = 'error';
$result = 'fail';
} else {
$style = 'comment';
$result = 'pending';
}
$table->addRow([$buildId, $build->message, "<{$style}>" . $result . "</{$style}>"]);
$table->render();
}
示例2: 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;
}
示例3: test
protected function test($count, $classes, OutputInterface $output)
{
$this->table = new Table($output);
$this->table->setHeaders(array('Implementation', 'Memory', 'Duration'));
$output->writeln(sprintf('<info>%d elements</info>', $count));
$this->process = new ProgressBar($output, count($classes));
$this->process->start();
foreach ($classes as $class) {
$shortClass = $class;
// if (in_array($class, $blacklist)) {
// $this->table->addRow([$class, '--', '--']);
// continue;
// };
$path = __DIR__ . '/../../bin/test.php';
$result = `php {$path} {$class} {$count}`;
$data = json_decode($result, true);
if (!$data) {
echo $result;
}
$this->table->addRow([$shortClass, sprintf('%11sb', number_format($data['memory'])), sprintf('%6.4fs', $data['time'])]);
$this->process->advance();
}
$this->process->finish();
$output->writeln('');
$this->table->render($output);
}
示例4: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$pBar = new ProgressBar($output, 10);
$pBar->start();
$showOutput = false;
try {
$sugarKernel = new SugarKernel('cli', 'dev', false);
$sugarKernel->boot();
} catch (\Exception $e) {
$output->writeln($e->getMessage());
}
$pBar->advance(2);
/** @var \User $user */
$user = $sugarKernel->getG('current_user');
$user->getSystemUser();
$modules = $sugarKernel->getG('mod_strings');
$pBar->advance();
$qrr = new Qrr();
if ($input->getOption('yell')) {
$showOutput = true;
$output->writeln('QRR output: ');
}
$qrr->repairAndClearAll(['clearAll'], [$modules['LBL_ALL_MODULES']], true, $showOutput);
$pBar->advance(5);
$sugarKernel->shutdown();
$pBar->finish();
$elapsed = time() - $pBar->getStartTime();
$output->writeln(' ');
$output->writeln(" Executed in: {$elapsed} s");
}
示例5: execute
/**
* Execute the generator command.
*
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
*
* @return void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->themes = $this->loadThemes();
$this->patterns = $this->loadPatterns();
$this->setupProgressBar($output);
$twig = new Twig_Environment(new Twig_Loader_Filesystem(BASE_PATH . '/resources/files'));
foreach ($this->themes as $theme) {
$theme->year = date('Y');
$theme->uuid = Uuid::uuid4()->toString();
foreach ($this->patterns as $pattern) {
$this->progress->setMessage("Generating '{$theme->theme->name}' theme for '{$pattern->name}'.");
foreach ($pattern->files as $source => $destination) {
$result = $twig->render($source, (array) $theme);
$destination = str_replace('{{theme}}', $theme->theme->slug, $destination);
if (count($pattern->files) > 1) {
$output = BASE_PATH . "/output/{$pattern->slug}/{$theme->theme->slug}/{$destination}";
} else {
$output = BASE_PATH . "/output/{$pattern->slug}/{$destination}";
}
@mkdir(dirname($output), 0777, true);
file_put_contents($output, $result);
}
$this->progress->advance();
}
}
$this->progress->setMessage("Enjoy the themes!");
$this->progress->finish();
}
示例6: 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);
}
示例7: start
/**
* {@inheritdoc}
*/
public function start()
{
$dispatcher = $this->getDispatcher();
$sourceEvent = new SourcePipelineEvent();
$sourceEvent->setContext($this->getContext());
$dispatcher->dispatch($this->getEventName(self::EVENT_SUFFIX_SOURCE), $sourceEvent);
$this->setContext($sourceEvent->getContext());
$sources = $sourceEvent->getSources();
$outputs = [];
$startEvent = new StartPipelineEvent();
$startEvent->setContext($this->getContext());
$startEvent->setItemCount($this->countSourceItems($sources));
$dispatcher->dispatch($this->getEventName(self::EVENT_SUFFIX_START), $startEvent);
$this->setContext($startEvent->getContext());
$this->progressBar && $this->progressBar->start($this->countSourceItems($sources));
foreach ($sources as $source) {
foreach ($source as $item) {
$itemEvent = new ItemPipelineEvent($item);
$itemEvent->setContext($this->getContext());
$dispatcher->dispatch($this->getEventName(self::EVENT_SUFFIX_MODIFY), $itemEvent);
$dispatcher->dispatch($this->getEventName(self::EVENT_SUFFIX_CONSUME), $itemEvent);
$output = $itemEvent->getOutput();
if ($output !== null) {
$outputs[] = $output;
}
$this->setContext($itemEvent->getContext());
$this->progressBar && $this->progressBar->advance();
}
}
$finishEvent = new FinishPipelineEvent();
$finishEvent->setContext($this->getContext());
$dispatcher->dispatch($this->getEventName(self::EVENT_SUFFIX_FINISH), $finishEvent);
$this->progressBar && $this->progressBar->finish();
return ['outputs' => $outputs];
}
示例8: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->setDecorated(true);
$username = $input->getOption('username');
$password = $input->getOption('password');
$plugin = $input->getOption('plugin');
$lastUpdate = $input->getOption('lastupdate');
$resource = 'piwik-' . ($plugin ? 'plugin-' . strtolower($plugin) : 'base');
$transifexApi = new API($username, $password);
// remove all existing translation files in download path
$files = glob($this->getDownloadPath() . DIRECTORY_SEPARATOR . '*.json');
array_map('unlink', $files);
if (!$transifexApi->resourceExists($resource)) {
$output->writeln("Skipping resource {$resource} as it doesn't exist on Transifex");
return;
}
$output->writeln("Fetching translations from Transifex for resource {$resource}");
$availableLanguages = LanguagesManagerApi::getInstance()->getAvailableLanguageNames();
$languageCodes = array();
foreach ($availableLanguages as $languageInfo) {
$languageCodes[] = $languageInfo['code'];
}
$languageCodes = array_filter($languageCodes, function ($code) {
return !in_array($code, array('en', 'dev'));
});
try {
$languages = $transifexApi->getAvailableLanguageCodes();
if (!empty($plugin)) {
$languages = array_filter($languages, function ($language) {
return LanguagesManagerApi::getInstance()->isLanguageAvailable(str_replace('_', '-', strtolower($language)));
});
}
} catch (AuthenticationFailedException $e) {
$languages = $languageCodes;
}
/** @var ProgressBar $progress */
$progress = new ProgressBar($output, count($languages));
$progress->start();
$statistics = $transifexApi->getStatistics($resource);
foreach ($languages as $language) {
try {
// if we have modification date given from statistics api compare it with given last update time to ignore not update resources
if (LanguagesManagerApi::getInstance()->isLanguageAvailable(str_replace('_', '-', strtolower($language))) && isset($statistics->{$language})) {
$lastupdated = strtotime($statistics->{$language}->last_update);
if ($lastUpdate > $lastupdated) {
$progress->advance();
continue;
}
}
$translations = $transifexApi->getTranslations($resource, $language, true);
file_put_contents($this->getDownloadPath() . DIRECTORY_SEPARATOR . str_replace('_', '-', strtolower($language)) . '.json', $translations);
} catch (\Exception $e) {
$output->writeln("Error fetching language file {$language}: " . $e->getMessage());
}
$progress->advance();
}
$progress->finish();
$output->writeln('');
}
示例9: 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();
}
示例10: advance
/**
* {@inheritdoc}
*/
public function advance($step = 1)
{
if ($this->current + $step > $this->count) {
$step = $this->count - $this->current;
}
$this->progress->advance($step);
$this->current += $step;
}
示例11: step
/**
* Signify the move to the next step in the install.
*
* @param string $message Very short message about the step
*/
public function step($message)
{
++$this->stepCount;
$this->info($message);
if ($this->progressBar instanceof ProgressBar) {
$this->progressBar->setMessage($message);
$this->progressBar->advance();
}
}
示例12: increment
/**
* {@inheritdoc}
*/
public function increment($increment = 1)
{
if ($this->bar === null) {
return;
}
$this->bar->advance($increment);
if ($this->bar->getProgress() === $this->bar->getMaxSteps()) {
$this->consoleIO->getOutput()->writeln(' - Finished!');
}
}
示例13: advanceProgressBar
private function advanceProgressBar()
{
if (null == $this->progressBar) {
return;
}
try {
$this->progressBar->advance();
} catch (RuntimeException $ex) {
// var_dump($ex->getMessage());
}
}
示例14: copyPasteDetection
/**
* Copy & Paste Detection (CPD).
*
* @param Iterator|array $files List of files to process
* @param int $minLines Minimum number of identical lines
* @param int $minTokens Minimum number of identical tokens
* @param bool $fuzzy
* @return CodeCloneMap Map of exact clones found in the list of files
*/
public function copyPasteDetection($files, $minLines = 5, $minTokens = 70, $fuzzy = false)
{
$result = new CodeCloneMap();
foreach ($files as $file) {
$this->strategy->processFile($file, $minLines, $minTokens, $result, $fuzzy);
if ($this->progressBar !== null) {
$this->progressBar->advance();
}
}
return $result;
}
示例15: onStatus
/**
* @param array $data
*/
protected function onStatus(array $data)
{
if (isset($data['current'])) {
$this->progress->setCurrent((int) $data['current']);
unset($data['current']);
} else {
$this->progress->advance();
}
foreach ($data as $key => $value) {
$this->progress->setMessage($value, $key);
}
}