当前位置: 首页>>代码示例>>PHP>>正文


PHP Helper::formatMemory方法代码示例

本文整理汇总了PHP中Symfony\Component\Console\Helper\Helper::formatMemory方法的典型用法代码示例。如果您正苦于以下问题:PHP Helper::formatMemory方法的具体用法?PHP Helper::formatMemory怎么用?PHP Helper::formatMemory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Console\Helper\Helper的用法示例。


在下文中一共展示了Helper::formatMemory方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getProgressBar

 protected function getProgressBar($nbIteration, $message)
 {
     $bar = new ProgressBar($this->output, $nbIteration);
     ProgressBar::setPlaceholderFormatterDefinition('memory', function (ProgressBar $bar) {
         static $i = 0;
         $mem = memory_get_usage();
         $colors = $i++ ? '41;37' : '44;37';
         return "[" . $colors . 'm ' . Helper::formatMemory($mem) . " [0m";
     });
     $bar->setFormat(" [44;37m %title:-38s% [0m\n %current%/%max% %bar% %percent:3s%%\n :chequered_flag:  %remaining:-10s% %memory:37s%\n");
     $bar->setBarCharacter("[32m●[0m");
     $bar->setEmptyBarCharacter("[31m●[0m");
     $bar->setMessage($message, 'title');
     $bar->start();
     return $bar;
 }
开发者ID:petit2m,项目名称:seriesTracker,代码行数:16,代码来源:BaseCommand.php

示例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));
     });
 }
开发者ID:ayoah,项目名称:symfony,代码行数:12,代码来源:ProgressIndicator.php

示例3: 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));
     });
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:12,代码来源:ProgressIndicator.php

示例4: 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);
     });
 }
开发者ID:cilefen,项目名称:symfony,代码行数:42,代码来源:ProgressBar.php

示例5: testAnsiColorsAndEmojis

 public function testAnsiColorsAndEmojis()
 {
     $bar = new ProgressBar($output = $this->getOutputStream(), 15);
     ProgressBar::setPlaceholderFormatterDefinition('memory', function (ProgressBar $bar) {
         static $i = 0;
         $mem = 100000 * $i;
         $colors = $i++ ? '41;37' : '44;37';
         return "[" . $colors . 'm ' . Helper::formatMemory($mem) . " [0m";
     });
     $bar->setFormat(" [44;37m %title:-37s% [0m\n %current%/%max% %bar% %percent:3s%%\n :chequered_flag:  %remaining:-10s% %memory:37s%");
     $bar->setBarCharacter($done = "[32m●[0m");
     $bar->setEmptyBarCharacter($empty = "[31m●[0m");
     $bar->setProgressCharacter($progress = "[32m➤ [0m");
     $bar->setMessage('Starting the demo... fingers crossed', 'title');
     $bar->start();
     $bar->setMessage('Looks good to me...', 'title');
     $bar->advance(4);
     $bar->setMessage('Thanks, bye', 'title');
     $bar->finish();
     rewind($output->getStream());
     $this->assertEquals($this->generateOutput(" [44;37m Starting the demo... fingers crossed  [0m\n" . '  0/15 ' . $progress . str_repeat($empty, 26) . "   0%\n" . " :chequered_flag:  1 sec                          [44;37m 0 B [0m") . $this->generateOutput(" [44;37m Looks good to me...                   [0m\n" . '  4/15 ' . str_repeat($done, 7) . $progress . str_repeat($empty, 19) . "  26%\n" . " :chequered_flag:  1 sec                       [41;37m 97 KiB [0m") . $this->generateOutput(" [44;37m Thanks, bye                           [0m\n" . ' 15/15 ' . str_repeat($done, 28) . " 100%\n" . " :chequered_flag:  1 sec                      [41;37m 195 KiB [0m"), stream_get_contents($output->getStream()));
 }
开发者ID:saj696,项目名称:pipe,代码行数:22,代码来源:ProgressBarTest.php

示例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;
 }
开发者ID:overtrue,项目名称:phplint,代码行数:54,代码来源:LintCommand.php

示例7: displayAvancement

 protected function displayAvancement($options, $done, $size, $showProgress, $output, $progress)
 {
     //advance
     $done += $options['slice'];
     if ($done > $size) {
         $done = $size;
     }
     //showing where we're at.
     if ($showProgress) {
         if ($output->isDecorated()) {
             $progress->advance();
         } else {
             $output->writeln("did " . $done . " over (" . $size . ") memory: " . Helper::formatMemory(memory_get_usage(true)));
         }
     }
     return $done;
 }
开发者ID:conjecto,项目名称:nemrod,代码行数:17,代码来源:Populator.php

示例8: download

 /**
  * Chooses the best compressed file format to download (ZIP or TGZ) depending upon the
  * available operating system uncompressing commands and the enabled PHP extensions
  * and it downloads the file.
  *
  * @return $this
  *
  * @throws \RuntimeException If the Symfony archive could not be downloaded
  */
 protected function download()
 {
     $this->output->writeln(sprintf("\n Downloading %s...\n", $this->getDownloadedApplicationType()));
     // decide which is the best compressed version to download
     $distill = new Distill();
     $symfonyArchiveFile = $distill->getChooser()->setStrategy(new MinimumSize())->addFilesWithDifferentExtensions($this->getRemoteFileUrl(), ['tgz', 'zip'])->getPreferredFile();
     /** @var ProgressBar|null $progressBar */
     $progressBar = null;
     $downloadCallback = function (ProgressEvent $event) use(&$progressBar) {
         $downloadSize = $event->downloadSize;
         $downloaded = $event->downloaded;
         // progress bar is only displayed for files larger than 1MB
         if ($downloadSize < 1 * 1024 * 1024) {
             return;
         }
         if (null === $progressBar) {
             ProgressBar::setPlaceholderFormatterDefinition('max', function (ProgressBar $bar) {
                 return Helper::formatMemory($bar->getMaxSteps());
             });
             ProgressBar::setPlaceholderFormatterDefinition('current', function (ProgressBar $bar) {
                 return str_pad(Helper::formatMemory($bar->getProgress()), 11, ' ', STR_PAD_LEFT);
             });
             $progressBar = new ProgressBar($this->output, $downloadSize);
             $progressBar->setFormat('%current%/%max% %bar%  %percent:3s%%');
             $progressBar->setRedrawFrequency(max(1, floor($downloadSize / 1000)));
             $progressBar->setBarWidth(60);
             if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
                 $progressBar->setEmptyBarCharacter('░');
                 // light shade character \u2591
                 $progressBar->setProgressCharacter('');
                 $progressBar->setBarCharacter('▓');
                 // dark shade character \u2593
             }
             $progressBar->start();
         }
         $progressBar->setProgress($downloaded);
     };
     $client = $this->getGuzzleClient();
     // store the file in a temporary hidden directory with a random name
     $this->downloadedFilePath = rtrim(getcwd(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '.' . uniqid(time()) . DIRECTORY_SEPARATOR . 'symfony.' . pathinfo($symfonyArchiveFile, PATHINFO_EXTENSION);
     try {
         $request = $client->createRequest('GET', $symfonyArchiveFile);
         $request->getEmitter()->on('progress', $downloadCallback);
         $response = $client->send($request);
     } catch (ClientException $e) {
         if ('new' === $this->getName() && ($e->getCode() === 403 || $e->getCode() === 404)) {
             throw new \RuntimeException(sprintf("The selected version (%s) cannot be installed because it does not exist.\n" . "Execute the following command to install the latest stable Symfony release:\n" . '%s new %s', $this->version, $_SERVER['PHP_SELF'], str_replace(getcwd() . DIRECTORY_SEPARATOR, '', $this->projectDir)));
         } else {
             throw new \RuntimeException(sprintf("There was an error downloading %s from symfony.com server:\n%s", $this->getDownloadedApplicationType(), $e->getMessage()), null, $e);
         }
     }
     $this->fs->dumpFile($this->downloadedFilePath, $response->getBody());
     if (null !== $progressBar) {
         $progressBar->finish();
         $this->output->writeln("\n");
     }
     return $this;
 }
开发者ID:symfony,项目名称:symfony-installer,代码行数:67,代码来源:DownloadCommand.php

示例9: 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()));
 }
开发者ID:localheinz,项目名称:github-changelog,代码行数:9,代码来源:GenerateCommand.php


注:本文中的Symfony\Component\Console\Helper\Helper::formatMemory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。