本文整理汇总了PHP中Symfony\Component\Console\Helper\Helper::formatTime方法的典型用法代码示例。如果您正苦于以下问题:PHP Helper::formatTime方法的具体用法?PHP Helper::formatTime怎么用?PHP Helper::formatTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Helper\Helper
的用法示例。
在下文中一共展示了Helper::formatTime方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initPlaceholderFormatters
private static function initPlaceholderFormatters()
{
return array('indicator' => function (ProgressIndicator $indicator) {
return $indicator->getCurrentValue();
}, 'message' => function (ProgressIndicator $indicator) {
return $indicator->getMessage();
}, 'elapsed' => function (ProgressIndicator $indicator) {
return Helper::formatTime(time() - $indicator->getStartTime());
}, 'memory' => function () {
return Helper::formatMemory(memory_get_usage(true));
});
}
示例2: initPlaceholderFormatters
private static function initPlaceholderFormatters()
{
return array('indicator' => function (ProgressIndicator $indicator) {
return $indicator->indicatorValues[$indicator->indicatorCurrent % count($indicator->indicatorValues)];
}, 'message' => function (ProgressIndicator $indicator) {
return $indicator->message;
}, 'elapsed' => function (ProgressIndicator $indicator) {
return Helper::formatTime(time() - $indicator->startTime);
}, 'memory' => function () {
return Helper::formatMemory(memory_get_usage(true));
});
}
示例3: initPlaceholderFormatters
private static function initPlaceholderFormatters()
{
return array('bar' => function (ProgressBar $bar, OutputInterface $output) {
$completeBars = floor($bar->getMaxSteps() > 0 ? $bar->getProgressPercent() * $bar->getBarWidth() : $bar->getProgress() % $bar->getBarWidth());
$display = str_repeat($bar->getBarCharacter(), $completeBars);
if ($completeBars < $bar->getBarWidth()) {
$emptyBars = $bar->getBarWidth() - $completeBars - Helper::strlenWithoutDecoration($output->getFormatter(), $bar->getProgressCharacter());
$display .= $bar->getProgressCharacter() . str_repeat($bar->getEmptyBarCharacter(), $emptyBars);
}
return $display;
}, 'elapsed' => function (ProgressBar $bar) {
return Helper::formatTime(time() - $bar->getStartTime());
}, 'remaining' => function (ProgressBar $bar) {
if (!$bar->getMaxSteps()) {
throw new LogicException('Unable to display the remaining time if the maximum number of steps is not set.');
}
if (!$bar->getProgress()) {
$remaining = 0;
} else {
$remaining = round((time() - $bar->getStartTime()) / $bar->getProgress() * ($bar->getMaxSteps() - $bar->getProgress()));
}
return Helper::formatTime($remaining);
}, 'estimated' => function (ProgressBar $bar) {
if (!$bar->getMaxSteps()) {
throw new LogicException('Unable to display the estimated time if the maximum number of steps is not set.');
}
if (!$bar->getProgress()) {
$estimated = 0;
} else {
$estimated = round((time() - $bar->getStartTime()) / $bar->getProgress() * $bar->getMaxSteps());
}
return Helper::formatTime($estimated);
}, 'memory' => function (ProgressBar $bar) {
return Helper::formatMemory(memory_get_usage(true));
}, 'current' => function (ProgressBar $bar) {
return str_pad($bar->getProgress(), $bar->getStepWidth(), ' ', STR_PAD_LEFT);
}, 'max' => function (ProgressBar $bar) {
return $bar->getMaxSteps();
}, 'percent' => function (ProgressBar $bar) {
return floor($bar->getProgressPercent() * 100);
});
}
示例4: testFormatTime
/**
* @dataProvider formatTimeProvider
*
* @param int $secs
* @param string $expectedFormat
*/
public function testFormatTime($secs, $expectedFormat)
{
$this->assertEquals($expectedFormat, Helper::formatTime($secs));
}
示例5: getRemaining
/**
* @return string
*/
public function getRemaining()
{
if (!$this->getMaxSteps()) {
return '???';
}
if (!$this->getProgress()) {
$remaining = 0;
} else {
$remaining = round((time() - $this->getStartTime()) / $this->getProgress() * ($this->getMaxSteps() - $this->getProgress()));
}
return Helper::formatTime($remaining);
}
示例6: 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
*
* @throws LogicException When this abstract method is not implemented
*
* @return null|int null or 0 if everything went fine, or an error code
*
* @see setCode()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$startTime = microtime(true);
$startMemUsage = memory_get_usage(true);
$output->writeln($this->getApplication()->getLongVersion() . " by overtrue and contributors.\n");
$options = $this->mergeOptions();
$verbosity = $output->getVerbosity();
if ($verbosity >= OutputInterface::VERBOSITY_DEBUG) {
$output->writeln('Options: ' . json_encode($options));
}
$linter = new Linter($options['path'], $options['exclude'], $options['extensions']);
$linter->setProcessLimit($options['jobs']);
if (!$input->getOption('no-cache') && Cache::isCached()) {
$output->writeln('Using cache.');
$linter->setCache(Cache::get());
}
$fileCount = count($linter->getFiles());
if ($fileCount <= 0) {
$output->writeln('<info>Could not find files to lint</info>');
return 0;
}
$errors = $this->executeLint($linter, $output, $fileCount, !$input->getOption('no-cache'));
$timeUsage = Helper::formatTime(microtime(true) - $startTime);
$memUsage = Helper::formatMemory(memory_get_usage(true) - $startMemUsage);
$code = 0;
$errCount = count($errors);
$output->writeln("\n\nTime: {$timeUsage}, Memory: {$memUsage}MB\n");
if ($errCount > 0) {
$output->writeln('<error>FAILURES!</error>');
$output->writeln("<error>Files: {$fileCount}, Failures: {$errCount}</error>");
$this->showErrors($errors);
$code = 1;
} else {
$output->writeln("<info>OK! (Files: {$fileCount}, Success: {$fileCount})</info>");
}
return $code;
}
示例7: formatStopwatchEvent
/**
* @param StopwatchEvent $event
*
* @return string
*/
private function formatStopwatchEvent(StopwatchEvent $event)
{
return sprintf('Time: %s, Memory: %s.', Helper::formatTime($event->getDuration() / 1000), Helper::formatMemory($event->getMemory()));
}