/** * @param ProgressAdapter|null $progressAdapter */ public function updateAddressFormats(ProgressAdapter $progressAdapter = null) { $localeDataUri = $this->options->getLocaleDataUri(); $dataPath = $this->options->getDataPath(); $locales = json_decode($this->httpClient->setUri($localeDataUri)->send()->getContent()); foreach (scandir($dataPath) as $file) { if (fnmatch('*.json', $file)) { unlink($dataPath . '/' . $file); } } $countryCodes = isset($locales->countries) ? explode('~', $locales->countries) : []; $countryCodes[] = 'ZZ'; if ($progressAdapter !== null) { $progressBar = new ProgressBar($progressAdapter, 0, count($countryCodes)); } foreach ($countryCodes as $countryCode) { file_put_contents($dataPath . '/' . $countryCode . '.json', $this->httpClient->setUri($localeDataUri . '/' . $countryCode)->send()->getContent()); if (isset($progressBar)) { $progressBar->next(); } } if (isset($progressBar)) { $progressBar->finish(); } // We clearly don't want the "ZZ" in the array! array_pop($countryCodes); $writer = new PhpArrayWriter(); $writer->setUseBracketArraySyntax(true); $writer->toFile($this->options->getCountryCodesPath(), $countryCodes, false); }
/** * Will create all images. * * <code> * $ php path/to/index.php image-generate --ignore * </code> * @throws \RuntimeException */ public function imageGenerateAction() { if (!$this->getRequest() instanceof ConsoleRequest) { throw new RuntimeException('You can only use this action from a console!'); } $rawFilePath = implode(DIRECTORY_SEPARATOR, [self::PATH_IMAGES, FileProperties::DIR_RAW]); //COUNT // count how many file there are. $counter = 0; foreach (new DirectoryIterator($rawFilePath) as $fileInfo) { if ($this->isImage($fileInfo)) { continue; } $counter++; } $adapter = new Console(); $progressBar = new ProgressBar($adapter, 0, $counter); $imageDirectory = new DirectoryIterator(self::PATH_IMAGES); //FOR EVERY // for every file in directory... foreach (new DirectoryIterator($rawFilePath) as $fileInfo) { if ($this->isImage($fileInfo)) { continue; } if ($this->getRequest()->getParam('ignore', false)) { $smallFilePath = implode(DIRECTORY_SEPARATOR, [self::PATH_IMAGES, FileProperties::DIR_SMALL, $fileInfo->getFilename()]); if (is_file($smallFilePath)) { $progressBar->next(); continue; } } try { (new ImageGenerator($fileInfo, $imageDirectory))->execute(); } catch (\Exception $e) { echo $e->getMessage() . PHP_EOL; } $progressBar->next(); } $progressBar->finish(); }
/** * Handles Event FormatEvents::onRowEnd * * @param GenerateEvent $event */ public function onRowEnd(GenerateEvent $event) { $this->bar->next(1, 'Table ' . $event->getNode()->getId()); }
<?php if ($argc != 2 || in_array($argv[1], ['--help', '-help', '-h', '-?'])) { ?> Generates orders and stores them in mongoDB. Usage: <?php echo $argv[0]; ?> total total number of orders to generate <?php exit(1); } require_once 'bootstrap.php'; use Zend\ProgressBar\ProgressBar; use Zend\ProgressBar\Adapter\Console; $orderGenerator = ServiceLocator::getInstance()->get('order_generator'); $orderRepository = ServiceLocator::getInstance()->get('order_repository'); $total = (int) $argv[1]; $progressBar = new ProgressBar(new Console(), 0, $total); while ($total) { $orderRepository->add($orderGenerator->generate()); $total--; $progressBar->next(); }