setEmptyBarCharacter() public method

Sets the empty bar character.
public setEmptyBarCharacter ( string $char )
$char string A character
 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;
     }
 }
Esempio n. 2
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;
 }
Esempio n. 3
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;
 }
Esempio n. 4
0
 /**
  * @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;
 }
Esempio n. 5
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();
     }
 }
Esempio n. 6
0
 /**
  * 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;
 }
Esempio n. 7
0
 /**
  * @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;
 }
Esempio n. 8
0
 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;
 }
Esempio n. 9
0
 /**
  * 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;
 }
Esempio n. 10
0
 /**
  * {@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();
     }
 }
 /**
  * @param array $data
  */
 protected function onStart(array $data)
 {
     $format = isset($this->options['format']) ? $this->options['format'] : 'normal';
     if (isset($data['total']) && $data['total'] > 0) {
         $maxSteps = (int) $data['total'];
         unset($data['total']);
     } else {
         $maxSteps = 1;
     }
     $progress = new ProgressBar($this->output, $maxSteps);
     $progress->setFormat($format);
     $progress->setEmptyBarCharacter(' ');
     $progress->setProgressCharacter(':');
     foreach ($data as $key => $value) {
         $progress->setMessage($value, $key);
     }
     $progress->start();
     $this->progress = $progress;
 }
 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('');
     }
 }
 /**
  * @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>');
     }
 }
Esempio n. 14
0
 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()));
 }
Esempio n. 15
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.
  *
  * @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;
 }
 /**
  * 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;
 }
Esempio n. 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.
  *
  * @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;
 }
Esempio n. 18
0
 /**
  * @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()]);
 }
Esempio n. 19
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;
 }