/** * {@inheritdoc} */ public function dispatch(RequestInterface $request, ResponseInterface $response = null) { parent::dispatch($request, $response); /* @var $request \Zend\Console\Request */ /* @var $response \Zend\Console\Response */ $consumerName = $request->getParam('consumer-name'); $consumerManager = $this->getConsumerManager(); if (!$consumerManager->has($consumerName)) { $this->getConsole()->writeLine('ERROR: Consumer "' . $consumerName . '" not found', ColorInterface::RED); $response->setErrorLevel(1); return; } $confirm = new Prompt\Confirm('Are you sure you want to purge? [y/n]', 'y', 'n'); $confirm->setConsole($this->getConsole()); if ($request->getParam('no-confirmation', false) || $confirm->show()) { $consumer = $consumerManager->get($consumerName); $consumer->purge(); $this->getConsole()->writeLine('OK', ColorInterface::GREEN); } else { $this->getConsole()->writeLine('Purging cancelled!', ColorInterface::YELLOW); } }
/** * @param $question * @param ConsoleAdapter $console * * @return bool */ private function askBooleanQuestion($question, ConsoleAdapter $console) { $console->write($question . ' ', ColorInterface::CYAN); $console->writeLine('[y/n]', ColorInterface::GREEN); $prompt = new Confirm(''); $prompt->setConsole($console); return (bool) $prompt->show(); }
public function testCanPromptConfirmWithYesNoCharChangedWithSetter() { fwrite($this->adapter->stream, 'oaB'); $confirm = new Confirm("Is ZF2 the best framework ?", "1", "0"); $confirm->setYesChar("A"); $confirm->setNoChar("B"); $confirm->setEcho(false); $confirm->setConsole($this->adapter); ob_start(); $response = $confirm->show(); $text = ob_get_clean(); $this->assertEquals($text, "Is ZF2 the best framework ?\n"); $this->assertTrue($response); }
public function confirm($promptText, $echo = true) { $prompt = new ConfirmPrompt($promptText); $prompt->setEcho($echo); $prompt->setConsole($this->console); return $prompt->show(); }
/** * Write a customizable confirm prompt * * @param string $message * @param string $yes * @param string $no * * @return bool */ public function writeConfirmPrompt($message, $yes, $no) { $this->writeLine(); // write prompt badge $this->writeBadge('badge_pick', Color::RED); // output prompt $prompt = new Confirm($this->translator->translate($message), $this->translator->translate($yes), $this->translator->translate($no)); $answer = $prompt->show(); return $answer; }
$files = [__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../vendor/autoload.php', __DIR__ . '/../../../autoload.php', __DIR__ . '/../../../vendor/autoload.php']; foreach ($files as $file) { if (file_exists($file)) { $loader = (require $file); break; } } if (!isset($loader)) { throw new RuntimeException('vendor/autoload.php could not be found. Did you run `php composer.phar install`?'); } $filePersister = new File(getcwd()); $gistPersister = new Gist(new Client()); $console = Console::getInstance(); $logo = new Logo(); $help = new Help(); $goodbye = new Goodbye(); $logo->draw($console); $report = $help->help($console); $file = $filePersister->persist($report); $console->writeLine('The information has been saved to', ColorInterface::GREEN); $console->writeLine(realpath($file), ColorInterface::BLACK, ColorInterface::CYAN); $console->write('May I upload this information on https://gist.github.com/ ?', ColorInterface::CYAN); $console->writeLine('[y/n]', ColorInterface::GREEN); $prompt = new Confirm(''); $prompt->setConsole($console); if ($prompt->show()) { $gistUri = $gistPersister->persist($report); $console->writeLine('The information was uploaded to', ColorInterface::GREEN); $console->writeLine($gistUri, ColorInterface::BLACK, ColorInterface::CYAN); } $goodbye->draw($console);
/** * Import Search Results * * @throws \RuntimeException */ public function importAction() { if (!$this->getRequest() instanceof ConsoleRequest) { throw new \RuntimeException('You can only use this action from a console!'); } $filter = $this->inputFilterSearch; $filter->setData($this->params()->fromRoute()); if ($filter->isValid() && $filter->getValue('help') == null) { if ($filter->getValue('confirm') == 'yes') { $confirm = new Confirm('Are you sure you want to Import Search Results? [y/n]', 'y', 'n'); $result = $confirm->show(); } else { $result = true; } if ($result) { $this->serviceSearch->import(); } } else { if ($filter->getValue('help') != null) { $this->getEventManager()->trigger('Mp3Help', null, ['help' => 'import']); exit; } } }