本文整理匯總了PHP中Symfony\Component\Console\Helper\ProgressBar::setProgress方法的典型用法代碼示例。如果您正苦於以下問題:PHP ProgressBar::setProgress方法的具體用法?PHP ProgressBar::setProgress怎麽用?PHP ProgressBar::setProgress使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Console\Helper\ProgressBar
的用法示例。
在下文中一共展示了ProgressBar::setProgress方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: download
/**
* @return bool
*/
public function download()
{
if ($this->isDownloaded()) {
return true;
}
$httpClient = new Client();
$request = new Request('GET', $this->getUrl());
$response = $httpClient->send($request, [RequestOptions::PROGRESS => function ($total, $current) {
if ($total <= 0 || !$this->output) {
return;
}
if (!$this->progressBar) {
$this->progressBar = new ProgressBar($this->output, $total);
$this->progressBar->setPlaceholderFormatterDefinition('max', function (ProgressBar $bar) {
return $this->formatSize($bar->getMaxSteps());
});
$this->progressBar->setPlaceholderFormatterDefinition('current', function (ProgressBar $bar) {
return str_pad($this->formatSize($bar->getProgress()), 11, ' ', STR_PAD_LEFT);
});
}
$this->progressBar->setProgress($current);
}]);
$this->filesystem->dumpFile($this->getDestinationFile(), $response->getBody()->getContents());
$this->downloaded = true;
return true;
}
示例2: fire
/**
* {@inheritdoc}
*/
protected function fire()
{
$offset = $this->argument('offset');
// Get all the element IDs ever
$result = $this->craft->db->createCommand()->select('id, type')->from('elements')->offset($offset)->queryAll();
$progressBar = new ProgressBar($this->output, count($result) + $offset);
foreach ($result as $i => $row) {
// Get the element type
$elementType = $this->craft->elements->getElementType($row['type']);
if (!$elementType) {
$progressBar->setProgress($offset + $i + 1);
continue;
}
// delete existing indexes
$this->craft->db->createCommand()->delete('searchindex', 'elementId = :elementId', array(':elementId' => $row['id']));
if ($elementType->isLocalized()) {
$localeIds = $this->craft->i18n->getSiteLocaleIds();
} else {
$localeIds = array($this->craft->i18n->getPrimarySiteLocaleId());
}
$criteria = $this->craft->elements->getCriteria($row['type'], array('id' => $row['id'], 'status' => null, 'localeEnabled' => null));
foreach ($localeIds as $localeId) {
$criteria->locale = $localeId;
$element = $criteria->first();
if (!$element) {
continue;
}
$this->craft->search->indexElementAttributes($element);
if (!$elementType->hasContent()) {
continue;
}
$fieldLayout = $element->getFieldLayout();
$keywords = array();
foreach ($fieldLayout->getFields() as $fieldLayoutField) {
$field = $fieldLayoutField->getField();
if (!$field) {
continue;
}
$fieldType = $field->getFieldType();
if (!$fieldType) {
continue;
}
$fieldType->element = $element;
$handle = $field->handle;
// Set the keywords for the content's locale
$fieldSearchKeywords = $fieldType->getSearchKeywords($element->getFieldValue($handle));
$keywords[$field->id] = $fieldSearchKeywords;
$this->craft->search->indexElementFields($element->id, $localeId, $keywords);
}
}
$progressBar->setProgress($offset + $i + 1);
}
$progressBar->finish();
$this->line('');
$this->info('Search indexes have been rebuilt.');
}
示例3: progressAdvance
/**
* @phpcsSuppress SlevomatCodingStandard.Typehints.TypeHintDeclaration.missingParameterTypeHint
* @param int $step
*/
public function progressAdvance($step = 1)
{
if ($this->output->isDecorated() && $step > 0) {
$stepTime = (time() - $this->progressBar->getStartTime()) / $step;
if ($stepTime > 0 && $stepTime < 1) {
$this->progressBar->setRedrawFrequency(1 / $stepTime);
} else {
$this->progressBar->setRedrawFrequency(1);
}
}
$this->progressBar->setProgress($this->progressBar->getProgress() + $step);
}
示例4: execute
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return null|int null or 0 if everything went fine, or an error code
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$config = Config::getInstance();
$noProgress = $input->getOption('no-progress');
$query = $input->getArgument('query');
$provider = $config->getQuery($query);
if (empty($provider)) {
$output->writeln("<error>cannot found query \"{$query}\"</error>");
$output->writeln("<info>you can execute \"</info>ipv4 edit<info>\" to configure the query</info>");
return 1;
}
$type = $input->getOption('type');
$filename = $config->getFilename($input->getArgument('filename'));
$export = ExportQuery::create($type, $filename);
if (empty($export)) {
$output->writeln("<error>cannot found export query \"{$type}\"</error>");
return 2;
}
$export->setProviders([$provider]);
$encoding = $input->getOption('encoding');
if (!empty($encoding)) {
$export->setEncoding($encoding);
}
$ecdz = $input->getOption('ecdz');
if ($ecdz && method_exists($export, 'setEcdz')) {
$export->setEcdz($ecdz);
}
$remove_ip_in_recode = $input->getOption('remove-ip-in-recode');
if ($remove_ip_in_recode && method_exists($export, 'setRemoveIpInRecode')) {
$export->setRemoveIpInRecode($remove_ip_in_recode);
}
$output->writeln("<info>export \"{$query}\" to \"{$type}\" filename \"{$filename}\":</info>");
if (!$noProgress) {
$export->init(function ($code, $n) use($output) {
switch ($code) {
case 0:
$this->progress = new ProgressBar($output, $n);
$this->progress->start();
break;
case 1:
$this->progress->setProgress($n);
break;
case 2:
$this->progress->finish();
break;
}
});
} else {
$export->init();
}
$output->writeln('<info> completed!</info>');
return 0;
}
示例5: setDownloadWithProgressBar
private function setDownloadWithProgressBar()
{
$emitter = $this->httpClient->getEmitter();
$emitter->on('before', function (\GuzzleHttp\Event\BeforeEvent $event) {
echo $event->getRequest();
});
$emitter->once('progress', function (\GuzzleHttp\Event\ProgressEvent $event) {
$this->progressBar->start($event->downloadSize);
});
$emitter->on('progress', function (\GuzzleHttp\Event\ProgressEvent $event) {
$this->progressBar->setProgress($event->downloaded);
});
}
示例6: waitMultiple
/**
* Wait for multiple activities to complete.
*
* @param Activity[] $activities
* @param OutputInterface $output
*/
public static function waitMultiple(array $activities, OutputInterface $output)
{
$count = count($activities);
if ($count <= 0) {
return;
}
$complete = 0;
$output->writeln("Waiting...");
$bar = new ProgressBar($output);
$bar->start($count);
$bar->setFormat('verbose');
while ($complete < $count) {
sleep(1);
foreach ($activities as $activity) {
if (!$activity->isComplete()) {
$activity->refresh();
} else {
$complete++;
}
}
$bar->setProgress($complete);
}
$bar->finish();
$output->writeln('');
}
示例7: generate
/**
* @param OutputInterface $output
* @param Query $query
* @param string $name
* @param bool $force
* @param bool $noProgress
* @return void
* @throws \Exception
*/
protected function generate(OutputInterface $output, Query $query, $name, $force, $noProgress)
{
$use = implode(', ', $query->getProviders());
if (!$force && $query->exists()) {
$output->writeln("<comment>use exist {$name} table.</comment>", OutputInterface::VERBOSITY_VERBOSE);
} else {
$output->writeln("<info>generate {$name} table with {$use}:</info>");
if (!$noProgress) {
$query->init(function ($code, $n) use($output) {
switch ($code) {
case 0:
$this->progress = new ProgressBar($output, $n);
$this->progress->start();
break;
case 1:
$this->progress->setProgress($n);
break;
case 2:
$this->progress->finish();
break;
}
});
} else {
$query->init();
}
$output->writeln('<info> completed!</info>');
}
}
示例8: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$desde = (int) $input->getArgument('desde');
$output->writeln('Importando actividades...');
$cantidad = 100;
$progress = null;
$importador = new ImportadorActividades($this->getContainer(), $this->getContainer()->get('doctrine')->getManager());
$importador->Inicializar();
$progress = new ProgressBar($output, $importador->ObtenerCantidadTotal());
$progress->start();
$ResultadoFinal = new ResultadoImportacion($importador);
while (true) {
$resultado = $importador->Importar($desde, $cantidad);
$ResultadoFinal->AgregarContadoresLote($resultado);
$progress->setProgress($resultado->PosicionCursor());
if (!$resultado->HayMasRegistros()) {
break;
}
$desde += $cantidad;
}
$progress->finish();
$output->writeln('');
$importador->RecalcularParent($output);
$output->writeln(' Se importaron ' . $ResultadoFinal->RegistrosNuevos . ' registros nuevos.');
$output->writeln(' Se actualizaron ' . $ResultadoFinal->RegistrosActualizados . ' registros.');
$output->writeln(' Se ignoraron ' . $ResultadoFinal->RegistrosIgnorados . ' registros.');
$output->writeln('Importación finalizada, se procesaron ' . $ResultadoFinal->TotalRegistrosProcesados() . ' registros.');
}
示例9: download
/**
* Download
*/
protected function download(OutputInterface &$output, $from, $to)
{
$output->writeln('Download ' . $from);
$progress = new ProgressBar($output);
$progress->setFormat('normal_nomax');
$step = 0;
$ctx = stream_context_create(array(), array('notification' => function ($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) use($output, $progress, &$step) {
switch ($notification_code) {
case STREAM_NOTIFY_FILE_SIZE_IS:
$progress->start(100);
break;
case STREAM_NOTIFY_PROGRESS:
$newStep = round($bytes_transferred / $bytes_max * 100);
if ($newStep > $step) {
$step = $newStep;
$progress->setProgress($step);
}
break;
}
}));
$file = file_get_contents($from, false, $ctx);
$progress->finish();
file_put_contents($to, $file);
$output->writeln('');
return $to;
}
示例10: execute
/**
* Executes the current command.
*
* This method is not abstract because you can use this class
* as a concrete class. In this case, instead of defining the
* execute() method, you set the code to execute by passing
* a Closure to the setCode() method.
*
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*
* @return null|int null or 0 if everything went fine, or an error code
*
* @throws \LogicException When this abstract method is not implemented
*
* @see setCode()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
/* @var $em \Doctrine\ORM\EntityManager */
$em = $this->getContainer()->get('doctrine.orm.' . $this->getContainer()->getParameter('geonames.entity_manager'));
$connection = $em->getConnection();
$population = $this->getContainer()->getParameter('geonames.cities_population');
$quote = function ($value) use($connection) {
return $connection->quote($value);
};
// Disable SQL logger
$connection->getConfiguration()->setSQLLogger(null);
$output->writeln('<info>> Start update Geonames list</info>');
if (!in_array($population, [1000, 5000, 15000])) {
$output->writeln('<error>False population value set in config "geonames.cities_population". Value must be one of 1000|5000|15000</error>');
} else {
$fileName = 'cities' . $population . '.zip';
$file = $this->download($output, 'http://download.geonames.org/export/dump/' . $fileName, $this->getTempDir('/' . $fileName));
$output->writeln('Clear Geonames table');
$connection->query('SET FOREIGN_KEY_CHECKS=0');
$connection->executeUpdate($connection->getDatabasePlatform()->getTruncateTableSql('timiki_geonames'));
$connection->query('SET FOREIGN_KEY_CHECKS=1');
$output->writeln('Load new Geonames list to table...wait');
$output->writeln('Processing downloaded data...');
// Prepare
$handler = fopen('zip://' . $file . '#cities' . $population . '.txt', 'r');
$count = 0;
while (!feof($handler)) {
fgets($handler);
$count++;
}
// rewind
fclose($handler);
$handler = fopen('zip://' . $file . '#cities' . $population . '.txt', 'r');
$progress = new ProgressBar($output);
$progress->setFormat('normal_nomax');
$step = 0;
$sql = '';
$progress->start($count);
// Load to db
while (!feof($handler)) {
$step++;
$line = fgets($handler);
$explode = explode("\t", $line);
if (count($explode) > 1) {
$sql .= $connection->createQueryBuilder()->insert('timiki_geonames')->values(['geoname_id' => $quote(array_key_exists(0, $explode) ? $explode[0] : null), 'name' => $quote(array_key_exists(1, $explode) ? $explode[1] : null), 'ascii_name' => $quote(array_key_exists(2, $explode) ? $explode[2] : null), 'alternate_names' => $quote(array_key_exists(3, $explode) ? $explode[3] : null), 'latitude' => $quote(array_key_exists(4, $explode) ? $explode[4] : null), 'longitude' => $quote(array_key_exists(5, $explode) ? $explode[5] : null), 'feature_class' => $quote(array_key_exists(6, $explode) ? $explode[6] : null), 'feature_code' => $quote(array_key_exists(7, $explode) ? $explode[7] : null), 'country_code' => $quote(array_key_exists(8, $explode) ? $explode[8] : null), 'cc2' => $quote(array_key_exists(9, $explode) ? $explode[9] : null), 'admin1_code' => $quote(array_key_exists(10, $explode) ? $explode[10] : null), 'admin2_code' => $quote(array_key_exists(11, $explode) ? $explode[11] : null), 'admin3_code' => $quote(array_key_exists(12, $explode) ? $explode[12] : null), 'admin4_code' => $quote(array_key_exists(13, $explode) ? $explode[13] : null), 'population' => $quote(array_key_exists(14, $explode) ? $explode[14] : 0), 'elevation' => $quote(array_key_exists(15, $explode) ? $explode[15] : 0), 'dem' => $quote(array_key_exists(16, $explode) ? $explode[16] : 0), 'timezone' => $quote(array_key_exists(17, $explode) ? $explode[17] : null), 'modification_date' => $quote(array_key_exists(18, $explode) ? $explode[18] : null)])->getSQL() . ';';
if ($step % 1000 === 0) {
$progress->setProgress($step);
$connection->exec($sql);
$sql = '';
}
}
}
$progress->setProgress($step);
$connection->exec($sql);
fclose($handler);
$output->writeln('');
$output->writeln('Done!');
}
}
示例11: execute
/**
* Executes the current command.
*
* This method is not abstract because you can use this class
* as a concrete class. In this case, instead of defining the
* execute() method, you set the code to execute by passing
* a Closure to the setCode() method.
*
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*
* @return null|int null or 0 if everything went fine, or an error code
*
* @throws \LogicException When this abstract method is not implemented
*
* @see setCode()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
/* @var $em \Doctrine\ORM\EntityManager */
$em = $this->getContainer()->get('doctrine.orm.' . $this->getContainer()->getParameter('geonames.entity_manager'));
$connection = $em->getConnection();
$quote = function ($value) use($connection) {
return $connection->quote($value);
};
// Disable SQL logger
$connection->getConfiguration()->setSQLLogger(null);
$output->writeln('<info>> Start update Geonames alternate names list</info>');
$file = $this->download($output, 'http://download.geonames.org/export/dump/alternateNames.zip', $this->getTempDir('/alternateNames.zip'));
$output->writeln('Clear Geonames alternate names table');
$connection->query('SET FOREIGN_KEY_CHECKS=0');
$connection->executeUpdate($connection->getDatabasePlatform()->getTruncateTableSql('timiki_geonames_alternate_names'));
$connection->query('SET FOREIGN_KEY_CHECKS=1');
$output->writeln('Load new Geonames alternate names list to table...wait');
$output->writeln('Processing downloaded data...');
// Prepare
$handler = fopen('zip://' . $file . '#alternateNames.txt', 'r');
$count = 0;
while (!feof($handler)) {
fgets($handler);
$count++;
}
// rewind
fclose($handler);
$handler = fopen('zip://' . $file . '#alternateNames.txt', 'r');
$progress = new ProgressBar($output);
$progress->setFormat('normal_nomax');
$step = 0;
$sql = '';
$progress->start($count);
// Output one line until end-of-file
while (!feof($handler)) {
$step++;
$line = fgets($handler);
$explode = explode("\t", $line);
if (count($explode) > 1) {
$isoLanguage = array_key_exists(2, $explode) ? $explode[2] : null;
$isHistoric = array_key_exists(7, $explode) ? $explode[7] : null;
$isShortName = array_key_exists(5, $explode) ? $explode[5] : null;
// Not load not valid data
if (!empty($isoLanguage) && $isoLanguage !== 'link' && $isoLanguage !== 'post' && $isoLanguage !== 'iata' && $isoLanguage !== 'icao' && $isoLanguage !== 'faac' && $isoLanguage !== 'fr_1793' && $isoLanguage !== 'abbr' && $isHistoric !== 1 && $isShortName !== 1) {
$sql .= $connection->createQueryBuilder()->insert('timiki_geonames_alternate_names')->values(['alternate_name_id' => $quote(array_key_exists(0, $explode) ? $explode[0] : null), 'geoname_id' => $quote(array_key_exists(1, $explode) ? $explode[1] : null), 'iso_language' => $quote(array_key_exists(2, $explode) ? $explode[2] : null), 'alternate_name' => $quote(array_key_exists(3, $explode) ? $explode[3] : null), 'is_preferred_name' => $quote(array_key_exists(4, $explode) ? $explode[4] : null), 'is_short_name' => $quote(array_key_exists(5, $explode) ? $explode[5] : null), 'is_colloquial' => $quote(array_key_exists(6, $explode) ? $explode[6] : null), 'is_historic' => $quote(array_key_exists(7, $explode) ? $explode[7] : null)])->getSQL() . ';';
if ($step % 1000 === 0) {
$progress->setProgress($step);
$connection->exec($sql);
$sql = '';
}
}
}
}
$progress->setProgress($step);
$connection->exec($sql);
fclose($handler);
$output->writeln('');
$output->writeln('Done!');
}
示例12: onCollectionBefore
/**
* onCollectionBefore.
*
* @param CollectionEvent $event
*/
public function onCollectionBefore(CollectionEvent $event)
{
$target = $event->getTarget();
$this->output->writeln(sprintf('<info>[START]</info> Migrating %s to <comment>%s</comment>:', $event->getOptions()->isDirectionUp() ? 'up' : 'down', $target->getId()));
if ($this->trackProgress) {
$this->progress = new ProgressBar($this->output, $event->getProgress()->getTotal());
$this->progress->setFormat('verbose');
$this->progress->setProgress(0);
}
}
示例13: set_progress
/**
* {@inheritdoc}
*/
public function set_progress($task_lang_key, $task_number)
{
parent::set_progress($task_lang_key, $task_number);
if ($this->progress_bar !== null) {
$this->progress_bar->setProgress($this->current_task_progress);
$this->progress_bar->setMessage($this->current_task_name);
} else {
$this->output->writeln(sprintf('[%3d/%-3d] %s', $this->current_task_progress, $this->task_progress_count, $this->current_task_name));
}
}
示例14: fire
/**
* {@inheritdoc}
*/
protected function fire()
{
$tasks = $this->craft->tasks->getAllTasks();
if (!$tasks) {
$this->info('No pending tasks.');
return;
}
foreach ($tasks as $task) {
if ($task->status === TaskStatus::Running) {
if ($this->option('reset-running')) {
$this->resetTask($task);
} else {
continue;
}
}
if ($task->status === TaskStatus::Error) {
if ($this->option('reset-failed')) {
$this->resetTask($task);
} else {
continue;
}
}
try {
$taskRecord = TaskRecord::model()->findById($task->id);
$taskType = $task->getTaskType();
if (!$taskType) {
throw new Exception('Could not find task type for task ID ' . $task->id);
}
$task->totalSteps = $taskType->getTotalSteps();
$task->status = TaskStatus::Running;
$progressBar = new ProgressBar($this->output, $task->totalSteps);
$this->info($task->description);
for ($step = 0; $step < $task->totalSteps; $step++) {
$task->currentStep = $step + 1;
$this->craft->tasks->saveTask($task);
$result = $taskType->runStep($step);
if ($result !== true) {
$error = is_string($result) ? $result : 'Unknown error';
$progressBar->finish();
$this->line('');
throw new Exception($error);
}
$progressBar->setProgress($task->currentStep);
}
$taskRecord->deleteNode();
$progressBar->finish();
$this->line('');
} catch (Exception $e) {
$this->failTask($task);
$this->error($e->getMessage());
}
}
$this->info('All tasks finished.');
}
示例15: showDownloadProgress
/**
* ProgressBar callback
* @param $notificationCode
* @param $severity
* @param $message
* @param $messageCode
* @param $bytesTransferred
* @param $bytesMax
* @return void
*/
protected function showDownloadProgress($notificationCode, $severity, $message, $messageCode, $bytesTransferred, $bytesMax)
{
switch ($notificationCode) {
case STREAM_NOTIFY_FILE_SIZE_IS:
if ($this->output) {
$this->progressBar = new ProgressBar($this->output, $bytesMax);
}
break;
case STREAM_NOTIFY_PROGRESS:
if ($this->progressBar) {
$this->progressBar->setProgress($bytesTransferred);
}
break;
}
}