setBarCharacter() public method

Sets the bar character.
public setBarCharacter ( string $char )
$char string A character
コード例 #1
0
 private function progressBarInit($count)
 {
     if ($this->progressBar === null) {
         return;
     }
     $this->progressBar->start($count);
     $this->progressBar->setBarCharacter(Constants::CHARACTER_PROGRESS_BAR);
     $this->progressBar->setProgressCharacter(Constants::CHARACTER_BEER);
 }
コード例 #2
0
 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;
     }
 }
コード例 #3
0
 /**
  * @param OutputInterface $output
  * @return ProgressBar
  */
 protected function createProgressBar(OutputInterface $output)
 {
     $progress = new ProgressBar($output);
     $progress->setBarCharacter('<comment>=</comment>');
     $progress->setProgressCharacter('|');
     $progress->setFormat(self::PROGRESS_BAR_MESSAGE_FORMAT);
     return $progress;
 }
コード例 #4
0
 /**
  * Progress bar define
  *
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @param int                                               $finish
  * @param string                                            $format
  * @return \Symfony\Component\Console\Helper\ProgressBar
  */
 public function getProgress(OutputInterface $output, $finish = 100, $format = 'normal')
 {
     $progress = new ProgressBar($output, $finish);
     $progress->setProgressCharacter('ϟ');
     $progress->setFormat($format);
     $progress->setBarCharacter('<comment>=</comment>');
     return $progress;
 }
コード例 #5
0
 /**
  * @param OutputInterface $output
  * @param int $length
  *
  * @return ProgressBar
  */
 protected function createProgressBar(OutputInterface $output, $length = 10)
 {
     $progress = new ProgressBar($output);
     $progress->setBarCharacter('<info>|</info>');
     $progress->setEmptyBarCharacter(' ');
     $progress->setProgressCharacter('|');
     $progress->start($length);
     return $progress;
 }
コード例 #6
0
ファイル: GenerateCommand.php プロジェクト: daylerees/rainbow
 /**
  * Setup the progress bar.
  *
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  */
 protected function setupProgressBar(OutputInterface $output)
 {
     $this->progress = new ProgressBar($output, count($this->themes) * count($this->patterns));
     $this->progress->setFormat("<info>%message%</info>\n<fg=red>[</>%bar%<fg=red>]</> <fg=yellow>(%current%/%max%) (%elapsed%)</>");
     $this->progress->setBarCharacter('<fg=blue>#</>');
     $this->progress->setProgressCharacter("<fg=magenta>#</>");
     $this->progress->setMessage('Test');
     $this->progress->start();
 }
コード例 #7
0
 public static function create(OutputInterface $output)
 {
     $bar = new ProgressBar($output);
     $bar->setBarCharacter('<fg=green>=</>');
     $bar->setEmptyBarCharacter('<fg=red>=</>');
     $bar->setProgressCharacter('>');
     $bar->setBarWidth(40);
     $bar->setFormat("%message%\n [%bar%] %percent:3s%%\n%elapsed:6s%/%estimated:-6s% %memory:6s%\n");
     return $bar;
 }
コード例 #8
0
ファイル: BuildCommand.php プロジェクト: lexcast/fminor-core
 /**
  * @param OutputInterface $output
  *
  * @return \Symfony\Component\Console\Helper\ProgressBar
  */
 private function getProgressBar(OutputInterface $output)
 {
     $bar = new ProgressBar($output);
     $bar->setFormat(' %current%/%max% [%bar%] %percent:3s%% %memory:6s%');
     $bar->setBarCharacter('<comment>=</comment>');
     $bar->setEmptyBarCharacter(' ');
     $bar->setProgressCharacter('|');
     $bar->setBarWidth(50);
     return $bar;
 }
コード例 #9
0
 /**
  * @param string $message
  */
 public function logTask($message)
 {
     $this->clearLine();
     $this->output->writeln('<fg=blue;options=bold>   > ' . $message . " </fg=blue;options=bold>");
     if ($this->output->getVerbosity() <= OutputInterface::VERBOSITY_NORMAL) {
         $this->progress = new ProgressBar($this->output);
         $this->progress->setEmptyBarCharacter(' ');
         $this->progress->setBarCharacter('-');
         $this->progress->start();
     }
 }
コード例 #10
0
ファイル: PackerHelper.php プロジェクト: laravolt/packer
 /**
  * Setting custom formatting for the progress bar
  * @param  object $bar Symfony ProgressBar instance
  * @return object $bar Symfony ProgressBar instance
  */
 public function barSetup(ProgressBar $bar)
 {
     // the finished part of the bar
     $bar->setBarCharacter('<comment>=</comment>');
     // the unfinished part of the bar
     $bar->setEmptyBarCharacter('-');
     // the progress character
     $bar->setProgressCharacter('>');
     // the 'layout' of the bar
     $bar->setFormat(' %current%/%max% [%bar%] %percent:3s%% ');
     return $bar;
 }
コード例 #11
0
ファイル: ProgressBarBuilder.php プロジェクト: spryker/Gui
 /**
  * @return \Symfony\Component\Console\Helper\ProgressBar
  */
 public function build()
 {
     $this->setupFormat();
     $progressBar = new ProgressBar($this->output, $this->count);
     $progressBar->setMessage($this->barTitle, 'barTitle');
     $progressBar->setBarWidth(20);
     if ($this->output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) {
         $progressBar->setBarCharacter("◼");
         $progressBar->setEmptyBarCharacter("◼");
         $progressBar->setProgressCharacter("▶");
         $progressBar->setBarWidth(50);
     }
     return $progressBar;
 }
コード例 #12
0
ファイル: BaseCommand.php プロジェクト: petit2m/seriesTracker
 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) . " ";
     });
     $bar->setFormat("  %title:-38s% \n %current%/%max% %bar% %percent:3s%%\n 🏁  %remaining:-10s% %memory:37s%\n");
     $bar->setBarCharacter("●");
     $bar->setEmptyBarCharacter("●");
     $bar->setMessage($message, 'title');
     $bar->start();
     return $bar;
 }
コード例 #13
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $rows = 100;
     $progressBar = new ProgressBar($output, $rows);
     $progressBar->setBarCharacter('<comment>=</comment>');
     $progressBar->setProgressCharacter('>');
     $progressBar->setBarWidth(77);
     $table = new Table($output);
     for ($i = 0; $i < $rows; $i++) {
         $table->addRow([sprintf('Row <info># %s</info>', $i), rand(0, 1000)]);
         usleep(50000);
         $progressBar->advance();
     }
     $progressBar->finish();
     $output->writeln('');
     $table->render();
 }
コード例 #14
0
ファイル: cli_iohandler.php プロジェクト: MrAdder/phpbb
 /**
  * {@inheritdoc}
  */
 public function set_task_count($task_count, $restart = false)
 {
     parent::set_task_count($task_count, $restart);
     if ($this->output->getVerbosity() === OutputInterface::VERBOSITY_NORMAL) {
         $this->progress_bar = $this->io->createProgressBar($task_count);
         $this->progress_bar->setFormat("    %current:3s%/%max:-3s% %bar%  %percent:3s%%\n" . "             %message%\n");
         $this->progress_bar->setBarWidth(60);
         if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
             $this->progress_bar->setEmptyBarCharacter('░');
             // light shade character \u2591
             $this->progress_bar->setProgressCharacter('');
             $this->progress_bar->setBarCharacter('▓');
             // dark shade character \u2593
         }
         $this->progress_bar->setMessage('');
         $this->io->newLine(2);
         $this->progress_bar->start();
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var FormatterHelper $formatter */
     $formatter = $this->getHelper('formatter');
     $message = $formatter->formatSection('Section', 'Hello!', 'comment');
     $output->writeln($message);
     $blockMessage = $formatter->formatBlock(['Good luck!'], 'bg=black;fg=white', true);
     $output->writeln($blockMessage);
     /** @var ProcessHelper $processHelper */
     $processHelper = $this->getHelper('process');
     $process = ProcessBuilder::create(['figlet', 'Started!'])->getProcess();
     $processHelper->run($output, $process, 'Something went wrong');
     $finder = new Finder();
     $files = $finder->in(CACHE_PATH)->name('makes*json')->files();
     $progressHelper = new ProgressBar($output);
     $progressHelper->setEmptyBarCharacter('.');
     $progressHelper->setBarCharacter('<comment>+</comment>');
     if ($input->getOption('progress')) {
         $progressHelper->start($files->count());
     }
     $table = new Table($output);
     $table->setStyle('default');
     $style = new TableStyle();
     $style->setBorderFormat('<comment>%s</comment>');
     $table->setStyle($style);
     foreach ($files as $file) {
         /** @var SplFileInfo $file */
         $makes = json_decode($file->getContents(), true);
         $table->setHeaders(['Make Name', 'Models Count']);
         foreach ($makes['makes'] as $make) {
             $table->addRow([$make['name'], count($make['models'])]);
         }
         //            $table->render($output);
         if ($input->getOption('progress')) {
             $progressHelper->advance();
         }
     }
     if ($input->getOption('progress')) {
         $progressHelper->finish();
         $output->writeln('');
     }
 }
コード例 #16
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         $verbosityLevelMap = array(LogLevel::NOTICE => OutputInterface::VERBOSITY_NORMAL, LogLevel::INFO => OutputInterface::VERBOSITY_NORMAL);
         $logger = new ConsoleLogger($output, $verbosityLevelMap);
         $progressBar = new ProgressBar($output);
         $progressBar->setFormat("<info>[info] %message% : %current%/%max% [</info>%bar%<info>] %percent:3s%% %elapsed:6s%/%estimated:-6s%</info>");
         $progressBar->setEmptyBarCharacter('<fg=red>-</>');
         $progressBar->setBarCharacter('<info>=</info>');
         $progressBar->setProgressCharacter('<info>></info>');
         $output->writeln("\n\r<question>Execution de la passerelle JLP-IMMO</question>");
         // Appel du service correpondant au CRON
         $services = $this->getContainer()->get('jlp_core.passerelle');
         $responseServices = $services->execute($logger, $progressBar);
         $output->writeln("<info>Passerelle resultat : " . print_r($responseServices, true) . "</info>");
         $output->writeln("\n\r");
     } catch (\Exception $e) {
         $output->writeln("\t<error>Passerelle Exception : " . $e . '</error>');
     }
 }
コード例 #17
0
 /**
  * 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 $this->formatSize($bar->getMaxSteps());
             });
             ProgressBar::setPlaceholderFormatterDefinition('current', function (ProgressBar $bar) {
                 return str_pad($this->formatSize($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;
 }
コード例 #18
0
ファイル: CreateCommand.php プロジェクト: poetic/clutch
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $bundlezip = $input->getOption('zip-file');
     if (!$bundlezip) {
         $helper = $this->getHelper('question');
         $question = new Question('<info>Please enter the name of the zip file:</info> <comment>[webflow]</comment> ', 'webflow');
         $bundlezip = $helper->ask($input, $output, $question);
     }
     $withZip = $bundlezip . ".zip";
     // Theme Name
     $theme = $input->getOption('theme-name');
     if (!$theme) {
         $helper = $this->getHelper('question');
         $question = new Question('<info>Please enter theme name:</info> <comment>[webflow]</comment> ', 'webflow');
         $theme = $helper->ask($input, $output, $question);
     }
     // Theme Description
     // $themeDesc = $input->getOption('theme-description');
     // if(!$themeDesc){
     //   $helper = $this->getHelper('question');
     //   $question = new Question('<info>Please enter theme description:</info> <comment>[These is a webflow theme]</comment> ', 'These is a webflow theme');
     //   $themeDesc = $helper->ask($input, $output, $question);
     // }
     $themeDesc = 'These is a webflow theme';
     $path = getcwd() . '/temp';
     $zip = new ZipArchive();
     if ($zip->open($withZip) === TRUE) {
         $zip->extractTo($path);
         $zip->close();
         $output->writeln('<info>Starting Theme creation process</info>');
     } else {
         $output->writeln('<comment>Failed to open the archive!</comment>');
         return false;
     }
     $directory = "{$path}/{$bundlezip}/";
     $htmlfiles = glob($directory . "*.html");
     $themeMachine = strtolower(str_replace(" ", "_", $theme));
     $Root = getcwd() . '/themes';
     $themeDir = "{$Root}/{$theme}";
     $create = new ClutchCli();
     $output = new ConsoleOutput();
     $output->setFormatter(new OutputFormatter(true));
     $rows = 8;
     $progressBar = new ProgressBar($output, $rows);
     $progressBar->setFormat(' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%');
     $progressBar->setBarCharacter('<fg=magenta>=</>');
     $progressBar->setProgressCharacter("🏃");
     $progressBar->setOverwrite(true);
     for ($i = 0; $i < $rows; $i++) {
         $create->Components($themeDir, $theme, $htmlfiles, 'data-component', 'components');
         $create->Components($themeDir, $theme, $htmlfiles, 'data-node', 'nodes');
         $create->Components($themeDir, $theme, $htmlfiles, 'data-menu', 'menus');
         $progressBar->advance(2);
         $create->Directory($path, $Root, $themeDir, $theme, $bundlezip);
         $progressBar->advance();
         $vars = array('{{themeName}}' => $theme, '{{themeMachine}}' => $themeMachine, '{{themeDescription}}' => $themeDesc);
         $progressBar->advance();
         $create->ThemeTemplates($themeDir, $theme, $vars);
         $progressBar->advance();
         $create->deleteDirectory($path);
         $progressBar->advance();
         \Drupal::service('theme_handler')->rebuildThemeData();
         $progressBar->advance();
         \Drupal::service('theme_handler')->reset();
         \Drupal::service('theme_handler')->refreshInfo();
         \Drupal::service('theme_handler')->listInfo();
         // $this->getChain()->addCommand('cache:rebuild', ['cache' => 'all']);
         // $this->getChain()->addCommand('clutch:sync', ['theme' => $theme]);
         $progressBar->advance();
         $output->writeln('<comment>' . "\r\n" . 'Your theme ' . $theme . ' is now created.</comment>');
         return true;
     }
     $progressBar->finish();
 }
コード例 #19
0
ファイル: Building.php プロジェクト: mostofreddy/phox
 /**
  * Executes the current command.
  *
  * @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
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('');
     $output->writeln('<comment>Creating package</comment>');
     $this->validate($input, $output);
     try {
         //get all params
         $rutaPhar = $input->getOption('output');
         $alias = $input->getOption('alias') . '.phar';
         $rutaPhar = rtrim($rutaPhar, '/') . '/' . $alias;
         $src = $input->getOption('src');
         $stub = $input->getOption('stub');
         $stubweb = $input->getOption('stubweb');
         $replace = $input->getOption('replace');
         $exclude = $input->getOption('exclude');
         if (true === $replace && is_file($rutaPhar)) {
             \Phar::unlinkArchive($rutaPhar);
         }
         //create and setup Stup object
         $oStub = new Stub();
         if (null !== $stub) {
             $oStub->setStubCli($stub);
         }
         if (null !== $stubweb) {
             $oStub->setStubWeb($stubweb);
         }
         $oStub->setDirTmp($src);
         $oStub->createDefaultStub();
         //create Finder object
         $finder = new Finder();
         $finder->files()->in($src);
         foreach ($exclude as $dirToExclude) {
             $finder->exclude($dirToExclude);
         }
         //inicialize progressbar
         $progress = new ProgressBar($output, count($finder));
         //create phar object
         $phar = new \Phar($rutaPhar, 0, $alias);
         $phar->startBuffering();
         //create default stubs
         $phar->setStub($phar->createDefaultStub($oStub->getStubCli(), $oStub->getStubWeb()));
         $progress->setBarCharacter('<comment>=</comment>');
         $progress->setProgressCharacter('<comment>></comment>');
         //add all files in the phar object
         $progress->start();
         foreach ($finder as $file) {
             $alias = ltrim(str_replace($src, '', $file->getPathname()), '/');
             $phar->addFile($file, $alias);
             $progress->advance();
         }
         $progress->finish();
         $phar->stopBuffering();
         $oStub->deleteTmpStubs();
         $output->writeln('');
         $output->writeln('');
         $output->writeln("<info>Phar created in: </info>" . $rutaPhar);
     } catch (\Exception $e) {
         $output->writeln('<error>' . $e->getMessage() . "</error>");
         exit(1);
     }
 }
コード例 #20
0
ファイル: GuzzleHelper.php プロジェクト: mkitsos/omnislash
 public function getProgressBar(OutputInterface $output, $max)
 {
     if ($this->progressBar instanceof ProgressBar) {
         return $this->progressBar;
     }
     ProgressBar::setPlaceholderFormatterDefinition('rejected', function (ProgressBar $bar) {
         return \Omnislash\Helper\GuzzleHelper::$rejected;
     });
     ProgressBar::setPlaceholderFormatterDefinition('fulfilled', function (ProgressBar $bar) {
         return \Omnislash\Helper\GuzzleHelper::$fulfilled;
     });
     $progress = new ProgressBar($output, $max);
     $format = ' %current%/%max% [%bar%] %percent:3s%%';
     $format .= ' Fulfilled: %fulfilled% / Rejected: %rejected%';
     $format .= ' %elapsed:6s%/%estimated:-6s% %memory:6s%';
     $progress->setFormat($format);
     $progress->setBarCharacter('<comment>=</comment>');
     return $this->progressBar = $progress;
 }
コード例 #21
0
ファイル: PwModuleTools.php プロジェクト: wireshell/wireshell
 /**
  * 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.
  *
  * @param string $url
  * @param string $module
  * @param OutputInterface $output
  * @return NewCommand
  *
  * @throws \RuntimeException if the ProcessWire archive could not be downloaded
  */
 public function downloadModule($url, $module, $output)
 {
     $output->writeln(" Downloading module {$module}...");
     $distill = new Distill();
     $pwArchiveFile = $distill->getChooser()->setStrategy(new MinimumSize())->addFile($url)->getPreferredFile();
     /** @var ProgressBar|null $progressBar */
     $progressBar = null;
     $downloadCallback = function ($size, $downloaded, $client, $request, Response $response) use(&$progressBar, &$output) {
         // Don't initialize the progress bar for redirects as the size is much smaller
         if ($response->getStatusCode() >= 300) {
             return;
         }
         if (null === $progressBar) {
             ProgressBar::setPlaceholderFormatterDefinition('max', function (ProgressBar $bar) {
                 return $this->formatSize($bar->getMaxSteps());
             });
             ProgressBar::setPlaceholderFormatterDefinition('current', function (ProgressBar $bar) {
                 return str_pad($this->formatSize($bar->getStep()), 11, ' ', STR_PAD_LEFT);
             });
             $progressBar = new ProgressBar($output, $size);
             $progressBar->setFormat('%current%/%max% %bar%  %percent:3s%%');
             $progressBar->setRedrawFrequency(max(1, floor($size / 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 = new Client();
     $client->getEmitter()->attach(new Progress(null, $downloadCallback));
     // store the file in a temporary hidden directory with a random name
     $this->compressedFilePath = \ProcessWire\wire('config')->paths->siteModules . '.' . uniqid(time()) . DIRECTORY_SEPARATOR . $module . '.' . pathinfo($pwArchiveFile, PATHINFO_EXTENSION);
     try {
         $response = $client->get($pwArchiveFile);
     } catch (ClientException $e) {
         if ($e->getCode() === 403 || $e->getCode() === 404) {
             throw new \RuntimeException("The selected module {$module} cannot be downloaded because it does not exist.\n");
         } else {
             throw new \RuntimeException(sprintf("The selected module (%s) couldn't be downloaded because of the following error:\n%s", $module, $e->getMessage()));
         }
     }
     $fs = new Filesystem();
     $fs->dumpFile($this->compressedFilePath, $response->getBody());
     if (null !== $progressBar) {
         $progressBar->finish();
         $output->writeln("\n");
     }
     return $this;
 }
コード例 #22
0
ファイル: GrumpPhpCommand.php プロジェクト: octava/geggs
 /**
  * @param InputInterface         $input
  * @param OutputInterface|Output $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->getLogger()->debug('Start', ['command_name' => $this->getName(), 'args' => $input->getArguments(), 'opts' => $input->getOptions()]);
     $action = $input->getArgument('action');
     if (!in_array($action, [self::ACTION_INIT, self::ACTION_DROP])) {
         throw new \RuntimeException(sprintf('Invalid argument action, must be "%s" or "%s"', self::ACTION_INIT, self::ACTION_DROP));
     }
     $optionDryRun = $input->getOption('dry-run');
     $prettyOutput = !$output->isQuiet() && !$output->isDebug();
     if ($prettyOutput) {
         $this->getSymfonyStyle()->title(sprintf('grumphp action "%s"', $input->getArgument('action')));
         $this->getSymfonyStyle()->writeln('');
     }
     $repositories = $this->getRepositoryModelList();
     $composerFilename = $repositories->getProjectModel()->getAbsolutePath() . DIRECTORY_SEPARATOR . 'composer.json';
     $composerData = json_decode(file_get_contents($composerFilename), true);
     if (!$composerData) {
         throw new \RuntimeException('Json decode error: ' . json_last_error_msg());
     }
     $configFilename = $repositories->getProjectModel()->getAbsolutePath() . DIRECTORY_SEPARATOR . 'grumphp.yml';
     if (!empty($composerData['config']['extra']['grumphp']['config-default-path'])) {
         $configFilename = $composerData['config']['extra']['grumphp']['config-default-path'];
     }
     if (!file_exists($configFilename)) {
         $this->getSymfonyStyle()->error(sprintf('File "%s" not found', $configFilename));
         return;
     }
     if ($prettyOutput) {
         $this->getSymfonyStyle()->write(sprintf('Work with GrumPhp file "%s"', $configFilename));
     }
     $grumpConfigData = Yaml::parse(file_get_contents($configFilename));
     $fileSystem = new Filesystem();
     $vendorModels = $repositories->getVendorModels();
     $vendorModelsCnt = count($vendorModels);
     $progress = null;
     if ($prettyOutput) {
         $progress = new ProgressBar($output, $vendorModelsCnt);
         $progress->setFormat("%filename% \n %current%/%max% [%bar%]\n");
         $progress->setBarCharacter('<comment>#</comment>');
         $progress->setEmptyBarCharacter(' ');
         $progress->setProgressCharacter('');
         $progress->setBarWidth(50);
     }
     foreach ($vendorModels as $model) {
         if ($prettyOutput) {
             $progress->setMessage('Working on ' . $model->getPath(), 'filename');
             $progress->advance();
         }
         $vendorPath = $model->getAbsolutePath();
         $gitPreCommitFilename = implode(DIRECTORY_SEPARATOR, [$vendorPath, '.git', 'hooks', 'pre-commit']);
         $gitCommitMsgFilename = implode(DIRECTORY_SEPARATOR, [$vendorPath, '.git', 'hooks', 'commit-msg']);
         $vendorConfigFilename = implode(DIRECTORY_SEPARATOR, [$vendorPath, '.git', 'grumphp.yml']);
         if (self::ACTION_INIT == $action) {
             $grumpConfigData['parameters']['bin_dir'] = '../../../bin';
             if (!empty($grumpConfigData['parameters']['tasks']['phpcs']['standard'])) {
                 $standard = $grumpConfigData['parameters']['tasks']['phpcs']['standard'];
                 if (0 === strpos($standard, 'vendor/') || 0 === strpos($standard, './vendor/')) {
                     $grumpConfigData['parameters']['tasks']['phpcs']['standard'] = implode(DIRECTORY_SEPARATOR, [$repositories->getProjectModel()->getAbsolutePath(), $grumpConfigData['parameters']['tasks']['phpcs']['standard']]);
                 }
             }
             if (!$optionDryRun) {
                 $grumpConfigYml = Yaml::dump($grumpConfigData);
                 $fileSystem->dumpFile($vendorConfigFilename, $grumpConfigYml);
                 $fileSystem->dumpFile($gitPreCommitFilename, $this->generatePreCommit($vendorConfigFilename));
                 $fileSystem->chmod($gitPreCommitFilename, 0755);
                 $fileSystem->dumpFile($gitCommitMsgFilename, $this->generateCommitMsg($vendorConfigFilename));
                 $fileSystem->chmod($gitCommitMsgFilename, 0755);
             }
             $this->getLogger()->debug('Config created', ['file' => $vendorConfigFilename]);
             $this->getLogger()->debug('Pre commit hook created', ['file' => $gitPreCommitFilename]);
             $this->getLogger()->debug('Commit msg hook created', ['file' => $gitCommitMsgFilename]);
         } elseif (self::ACTION_DROP == $action) {
             if (!$optionDryRun) {
                 $fileSystem->remove([$gitCommitMsgFilename, $gitPreCommitFilename, $vendorConfigFilename]);
             }
             $this->getLogger()->debug('Config removed', ['file' => $vendorConfigFilename]);
             $this->getLogger()->debug('Pre commit hook removed', ['file' => $gitPreCommitFilename]);
             $this->getLogger()->debug('Commit msg hook removed', ['file' => $gitCommitMsgFilename]);
         }
     }
     if ($prettyOutput) {
         $progress->setMessage('Done', 'filename');
         $progress->finish();
         if (self::ACTION_INIT == $action) {
             $this->getSymfonyStyle()->success('GrumPHP is sniffing your vendors code!');
         } elseif (self::ACTION_DROP == $action) {
             $this->getSymfonyStyle()->note('GrumPHP stopped sniffing your vendors commits! Too bad ...');
         }
     }
     $this->getLogger()->debug('Finish', ['command_name' => $this->getName()]);
 }
コード例 #23
0
ファイル: DownloadHelper.php プロジェクト: mistymagich/gush
 /**
  * Download a file from the URL to the destination.
  *
  * @param string $url      Fully qualified URL to the file.
  * @param bool   $progress Show the progressbar when downloading.
  */
 public function downloadFile($url, $progress = true)
 {
     /** @var ProgressBar|null $progressBar */
     $progressBar = null;
     $downloadCallback = function ($size, $downloaded, $client, $request, Response $response) use(&$progressBar) {
         // Don't initialize the progress bar for redirects as the size is much smaller.
         if ($response->getStatusCode() >= 300) {
             return;
         }
         if (null === $progressBar) {
             ProgressBar::setPlaceholderFormatterDefinition('max', function (ProgressBar $bar) {
                 return $this->formatSize($bar->getMaxSteps());
             });
             ProgressBar::setPlaceholderFormatterDefinition('current', function (ProgressBar $bar) {
                 return str_pad($this->formatSize($bar->getProgress()), 11, ' ', STR_PAD_LEFT);
             });
             $progressBar = new ProgressBar($this->output, $size);
             $progressBar->setFormat('%current%/%max% %bar%  %percent:3s%%');
             $progressBar->setRedrawFrequency(max(1, floor($size / 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();
     if ($progress) {
         $this->output->writeln(sprintf("\n Downloading %s...\n", $url));
         $client->getEmitter()->attach(new Progress(null, $downloadCallback));
     }
     $response = $client->get($url);
     $tmpFile = $this->filesystemHelper->newTempFilename();
     $this->fs->dumpFile($tmpFile, $response->getBody());
     if (null !== $progressBar) {
         $progressBar->finish();
         $this->output->writeln("\n");
     }
     return $tmpFile;
 }
コード例 #24
0
ファイル: UpgradeCommand.php プロジェクト: samuell/wireshell
 /**
  * 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.
  *
  * @throws \RuntimeException if the ProcessWire archive could not be downloaded
  */
 private function download()
 {
     $this->output->writeln("\n  Downloading ProcessWire Version " . $this->branch['version'] . "...");
     $distill = new Distill();
     $pwArchiveFile = $distill->getChooser()->setStrategy(new MinimumSize())->addFile($this->branch['zipURL'])->getPreferredFile();
     /** @var ProgressBar|null $progressBar */
     $progressBar = null;
     $downloadCallback = function ($size, $downloaded, $client, $request, Response $response) use(&$progressBar) {
         // Don't initialize the progress bar for redirects as the size is much smaller
         if ($response->getStatusCode() >= 300) {
             return;
         }
         if (null === $progressBar) {
             ProgressBar::setPlaceholderFormatterDefinition('max', function (ProgressBar $bar) {
                 return $this->formatSize($bar->getMaxSteps());
             });
             ProgressBar::setPlaceholderFormatterDefinition('current', function (ProgressBar $bar) {
                 return str_pad($this->formatSize($bar->getStep()), 11, ' ', STR_PAD_LEFT);
             });
             $progressBar = new ProgressBar($this->output, $size);
             $progressBar->setFormat('%current%/%max% %bar%  %percent:3s%%');
             $progressBar->setRedrawFrequency(max(1, floor($size / 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 = new Client();
     $client->getEmitter()->attach(new Progress(null, $downloadCallback));
     // store the file in a temporary hidden directory with a random name
     $this->compressedFilePath = getcwd() . DIRECTORY_SEPARATOR . '.' . uniqid(time()) . DIRECTORY_SEPARATOR . 'pw.' . pathinfo($pwArchiveFile, PATHINFO_EXTENSION);
     try {
         $response = $client->get($pwArchiveFile);
     } catch (ClientException $e) {
         if ($e->getCode() === 403 || $e->getCode() === 404) {
             throw new \RuntimeException(sprintf("The selected version (%s) cannot be installed because it does not exist.\n" . "Try the special \"latest\" version to install the latest stable ProcessWire release:\n" . '%s %s %s latest', $this->version, $_SERVER['PHP_SELF'], $this->getName(), $this->projectDir));
         } else {
             throw new \RuntimeException(sprintf("The selected version (%s) couldn't be downloaded because of the following error:\n%s", $this->version, $e->getMessage()));
         }
     }
     $this->fs->dumpFile($this->compressedFilePath, $response->getBody());
     if (null !== $progressBar) {
         $progressBar->finish();
         $this->output->writeln("\n");
     }
     return $this;
 }
コード例 #25
0
 private function createProgressBar($max = 100)
 {
     $bar = new ProgressBar($this->output, $max);
     $bar->setBarCharacter('<info>#</info>');
     $bar->setProgressCharacter('<info>#</info>');
     $bar->setFormat("%message%\n" . '%percent:3s%% [%bar%] %elapsed:6s%/%estimated:-6s%   ');
     return $bar;
 }
コード例 #26
0
ファイル: ProgressBarTest.php プロジェクト: saj696/pipe
 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) . " ";
     });
     $bar->setFormat("  %title:-37s% \n %current%/%max% %bar% %percent:3s%%\n 🏁  %remaining:-10s% %memory:37s%");
     $bar->setBarCharacter($done = "●");
     $bar->setEmptyBarCharacter($empty = "●");
     $bar->setProgressCharacter($progress = "➤ ");
     $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("  Starting the demo... fingers crossed  \n" . '  0/15 ' . $progress . str_repeat($empty, 26) . "   0%\n" . " 🏁  1 sec                           0 B ") . $this->generateOutput("  Looks good to me...                   \n" . '  4/15 ' . str_repeat($done, 7) . $progress . str_repeat($empty, 19) . "  26%\n" . " 🏁  1 sec                        97 KiB ") . $this->generateOutput("  Thanks, bye                           \n" . ' 15/15 ' . str_repeat($done, 28) . " 100%\n" . " 🏁  1 sec                       195 KiB "), stream_get_contents($output->getStream()));
 }
コード例 #27
0
 /**
  * Downloads the oxid archive
  *
  * @param OutputInterface $output
  * @param $url
  * @return string
  */
 protected function downloadOxid(OutputInterface $output, $version)
 {
     $file = sys_get_temp_dir() . '/oxrun-' . time() . '.zip';
     $progressBar = null;
     $client = new Client();
     try {
         $githubToken = getenv('GITHUB_TOKEN');
         if ($githubToken) {
             $request = $client->createRequest('GET', $version['zip'] . '?access_token=' . $githubToken, array('save_to' => $file));
         } else {
             $request = $client->createRequest('GET', $version['zip'], array('save_to' => $file));
         }
         $request->getEmitter()->on('progress', function (ProgressEvent $e) use(&$progressBar, $output) {
             if (null === $progressBar && $e->downloadSize !== 0) {
                 ProgressBar::setPlaceholderFormatterDefinition('max', function (ProgressBar $bar) {
                     return $this->formatSize($bar->getMaxSteps());
                 });
                 ProgressBar::setPlaceholderFormatterDefinition('current', function (ProgressBar $bar) {
                     return str_pad($this->formatSize($bar->getStep()), 11, ' ', STR_PAD_LEFT);
                 });
                 $progressBar = new ProgressBar($output, $e->downloadSize);
                 $progressBar->setFormat('%current%/%max% %bar%  %percent:3s%%');
                 $progressBar->setRedrawFrequency(max(1, floor($e->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();
             }
             if ($progressBar) {
                 $progressBar->setProgress($e->downloaded);
             }
         });
         $client->send($request);
     } catch (ClientException $e) {
         throw new \RuntimeException(sprintf("There was an error downloading:\n%s", $e->getMessage()), null, $e);
     }
     if (null !== $progressBar) {
         $progressBar->finish();
         $output->writeln("\n");
     }
     return $file;
 }